Last active
May 10, 2017 15:11
-
-
Save OtavioBraga/e1dba8eaa20f0412f9e9b2ce4cdab2b3 to your computer and use it in GitHub Desktop.
basic test for a flask application using pytest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importamos nosso app | |
from app import meu_web_app | |
# Importamos a biblioteca de testes | |
import unittest | |
class TestHomeView(unittest.TestCase): | |
''' | |
Como todos os 3 casos de teste fazem um get na home "/" | |
da nossa aplicacao, definimos a funcao setUp. Ela e executada | |
automaticamente sempre que o Pytest instancia a classe TestHomeView. | |
A funcao setUp e semelhante a um metodo construtor. | |
''' | |
def setUp(self): | |
app = meu_web_app.test_client() | |
self.response = app.get('/') | |
# Testamos se a resposta e 200 ("ok") | |
def test_get(self): | |
self.assertEqual(200, self.response.status_code) | |
# Testamos se a nossa home retorna a string "ok" | |
def test_html_string_response(self): | |
self.assertEqual("ok", self.response.data.decode('utf-8')) | |
# Testamos se o content_type da resposta da home esta correto | |
def test_content_type(self): | |
self.assertIn('text/html', self.response.content_type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment