def client(): ''' Flask app fixture ''' app.testing = True client = app.test_client() yield client
def test_user_can_install(self): with app.test_client() as c: response = c.get('/install') expect(response.status_code).to(equal(200)) html_string = response.data.decode("utf-8") expect(html_string).to(contain("Install")) expect(html_string).to(contain("button"))
def test_get_descriptions_from_wikipedia_not_found(self): with app.test_client() as client: recoart_code = get_recoart_fake_code() language_params = '?' + LANGUAGE_PARAM + '=' + API_ES + ',' + API_EN + ',' + API_FR + ',' + API_IT get_descriptions_from_wikipedia_url = BASE_URI_V1 + URI_WIKIPEDIA_DESCRIPTIONS + '/' + recoart_code + language_params response = client.get(get_descriptions_from_wikipedia_url) self.assertEqual(NOT_FOUND, response.status_code)
def client(): # db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() app.config["TESTING"] = True client = app.test_client() # with flaskr.app.app_context(): # flaskr.init_db() yield client
def client(request): test_client = app.test_client() def teardown(): pass request.addfinalizer(teardown) return test_client
def test_client(): test_client = app.test_client() ctx = app.app_context() ctx.push() yield test_client ctx.pop()
def test_get_non_existent_quiz(setup): """ Getting a non-existent quiz should return 400 and QuizNotFoundException """ with app.test_client() as c: response = c.get('/quiz?_id=2') response_json = response.get_json() assert response.status_code == 400 assert response_json == BaseExceptionSchema().dump(QuizNotFoundException())
def client(): """Create and return client to make requests""" # app.config["TESTING"] = True app.config.from_object(config['testing']) client = app.test_client() Base.metadata.create_all(engine) yield client
def test_user_can_be_thanked(self, mocker): with app.test_client() as c: mocker.patch.object(pyBot, 'auth') pyBot.auth.return_value = True response = c.get('/thanks') expect(response.status_code).to(equal(200)) html_string = response.data.decode('utf-8') expect(html_string).to(contain('Thanks for installing!'))
def setup_class(cls): cls.client = app.test_client() cls.default_headers = {'Content-Type': 'application/json'} cls.data = { "titulo": "teste", "texto": "teste teste", "autor": { "nome": "teste" } } cls.created_data = []
def setup_class(cls): cls.client = app.test_client() cls.default_headers = {'Content-Type': 'application/json'} autor = AutorModel(nome='teste') autor.save() noticia = NoticiaModel(titulo='teste 1', texto='teste teste 1', autor=autor) noticia.save() cls.noticia_id = str(noticia.id)
def setUp(self): app.config['TESTING'] = True app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///{}".format( os.path.join(project_dir, TEST_DB)) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['PAGE_SIZE'] = 10 db.init_app(app) self.app = app.test_client() self.assertEqual(app.debug, False)
def test_submit_non_existent_quiz(setup): """ Submitting responses for a non-existent quiz should return 400 and QuizNotFoundException """ with app.test_client() as c: response = c.post('/quiz', json={ '_id': '2', 'responses': ['B', 'A', 'B', 'A'] }) response_json = response.get_json() assert response.status_code == 400 assert response_json == BaseExceptionSchema().dump(QuizNotFoundException())
def test_submit_too_many_response(setup): """ Submitting more responses than questions should return 400 and InvalidResponsesException """ with app.test_client() as c: response = c.post('/quiz', json={ '_id': '1', 'responses': ['B', 'A', 'B', 'A', 'D'] }) response_json = response.get_json() assert response.status_code == 400 assert response_json == BaseExceptionSchema().dump(InvalidResponsesException())
def test_app_can_respond_to_challenges(self, mocker): with app.app_context(): with app.test_client() as c: data = { "token": os.environ.get("VERIFICATION_TOKEN"), "challenge": 'my challenge' } response = c.post('/listening', data=json.dumps(data), content_type='application/json') expect(response.status_code).to(equal(200))
def test_get_quiz(setup): """ Getting a quiz should return a quiz with the answers hidden """ with app.test_client() as c: response = c.get('/quiz?_id=1') response_json = response.get_json() assert response_json['_id'] == '1' assert response_json['title'] == 'Quiz 1' assert response_json['questions'][0] == {'question': 'How are you doing?', 'options': {'A': 'Good', 'B': 'Ok', 'C': 'Bad'}, 'points': 10}
def setUp(self): utils.init_test_database() self.app = app.test_client() self.app.testing = True self.new_user = User(username=TEST_USER['username'], password=User.generate_hash( TEST_USER['password']), name=TEST_USER['name'], surname=TEST_USER['surname'], email=TEST_USER['email']) self.new_user.save_to_db()
def test_submit_quiz(setup): """ Submitting a valid quiz should return 200 and the result of the quiz """ with app.test_client() as c: response = c.post('/quiz', json={ '_id': '1', 'responses': ['B', 'D', 'B', 'A'] }) response_json = response.get_json() assert response.status_code == 200 assert response_json == 85
def client(): db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True with app.test_client() as client: with app.app_context(): init_db() yield client os.close(db_fd) os.unlink(app.config['DATABASE'])
def client(): with mock.patch('flask.Flask', lambda x: Flask(x)): from src.app import app db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True with app.test_client() as client: # with app.app_context(): # app.init_db() yield client os.close(db_fd) os.unlink(app.config['DATABASE'])
def test_app(): m = mock.Mock() n = mock.Mock() m.return_value = {"secret_key": "Test"} with mock.patch("json.load", m): with mock.patch("builtins.open", n): from src.app import app assert type(app) is flask.app.Flask with app.test_client() as client: r = client.get("/") assert r.status_code == 200 assert r.data is not None
def test_get_descriptions_from_wikipedia(self): with app.test_client() as client: recoart_code = get_random_wikipedia_paint_catalog( ).RecoArtPaintCode language_params = '?' + LANGUAGE_PARAM + '=' + API_ES + ',' + API_EN + ',' + API_FR + ',' + API_IT get_descriptions_from_wikipedia_url = BASE_URI_V1 + URI_WIKIPEDIA_DESCRIPTIONS + '/' + recoart_code + language_params response = client.get(get_descriptions_from_wikipedia_url) wikipedia_descriptions_json = response.get_json() wikipedia_descriptions = DescriptionsDTO( **wikipedia_descriptions_json) self.assertEqual(OK, response.status_code) self.assertEqual(4, len(wikipedia_descriptions.Descriptions))
def test_get_schedule(requests, snapshot): requests.post().json.return_value = RESPONSE_SCHEDULE data = '{"idCuadro": "5", "fecha": "16/09/2021"}' url = "http://www.clubconecta.cl/booking/srvc.aspx/ObtenerCuadro" with app.test_client() as test_app: result = test_app.get("/get_schedule/conecta/2021-09-16") assert requests.post.call_args[0] == (url, ) assert requests.post.call_args[1].get("headers") is not None assert requests.post.call_args[1].get("cookies") is not None assert requests.post.call_args[1].get("data") == data assert result.status_code == 200 snapshot.assert_match(result.json)
def test_forecast_prophet_conf_int_lower(): warnings.filterwarnings("ignore") """Teste a função Prophet""" data = { "data": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "model": "prophet_python", "params": { "alpha": 0.8, "n_periods": 5, "seasonal": True } } rv = app.test_client().post('/forecast', json=data) ret = json.loads(rv.data) assert [round(v[1]) for v in ret['conf_int']] == [11, 12, 13, 14, 15]
def test_get_availability(requests, snapshot): # pylint: disable=line-too-long requests.post().json.return_value = RESPONSE_AVAILABILITY data = '{"idCuadro": "5", "idRecurso": "19", "idmodalidad": 5, "fecha": "16/09/2021", "hora": "1174"}' url = "http://www.clubconecta.cl/booking/srvc.aspx/ObtenerInformacionHuecoLibre" with app.test_client() as test_app: result = test_app.get("/get_availability/conecta/19/2021-09-16/1174") origin = "http://www.clubconecta.cl" assert requests.post.call_args[0] == (url, ) assert requests.post.call_args[1]["headers"]["Origin"] == origin assert requests.post.call_args[1]["cookies"]["i18next"] == "es-CL" assert requests.post.call_args[1].get("data") == data assert result.status_code == 200 snapshot.assert_match(result.json)
def test_user_can_log_in_to_session(self): email = "*****@*****.**" password = "******" username = "******" user = User(email, password, username) user.register() with app.test_client() as c: c.get("/") user.login() assert session["email"] == "*****@*****.**" db.session.delete(user) db.session.commit()
def test_get_fixed_times(requests, snapshot): # pylint: disable=line-too-long requests.post().json.return_value = RESPONSE_FIXED_TIME data = '{"id": "15", "idmodalidad": 3, "fecha": "16/09/2021", "idHorario": "1174"}' url = "http://www.clubconecta.cl/booking/srvc.aspx/ObtenerInformacionHorarioPrefijadoLibre" with app.test_client() as test_app: result = test_app.get( "/get_fixed_time_info/conecta/15/2021-09-16/1174") origin = "http://www.clubconecta.cl" assert requests.post.call_args[0] == (url, ) assert requests.post.call_args[1]["headers"]["Origin"] == origin assert requests.post.call_args[1]["cookies"]["i18next"] == "es-CL" assert requests.post.call_args[1].get("data") == data assert result.status_code == 200 snapshot.assert_match(result.json)
class StatusServiceTests(unittest.TestCase): app = app.test_client() def test_status(self): Customer().set_customer(TESTING_DATABASE) User().insert({ 'type': 'admin', 'first_name': 'status', 'last_name': 'status', 'username': '******', 'email': 'status', 'password': '******' }) logged_user = Login().login(Auth('status', 'status')) self.headers = { 'Content-Type': 'application/json', 'x-access-token': logged_user.data['token'] } response = self.app.get('/status', headers=self.headers) self.assertEqual(response.status_code, 200, 'Status not found') data = json.loads(response.data) keys = ['is_up', 'data_usage', 'info'] self.assertEqual('docker' in data, True, 'Missing docker status') self.assertEqual('mongo' in data, True, 'Missing mongo status') for key in keys: self.assertEqual(key in data['docker'], True, key + ' missing in docker status') self.assertEqual(key in data['mongo'], True, key + ' missing in mongo status') def test_healthcheck(self): Customer().set_customer(TESTING_DATABASE) response = self.app.get('/api/healthcheck') self.assertEqual(response.status_code, 200, 'Healthcheck not found') data = json.loads(response.data) self.assertEqual('ok' in data, True, 'Missing healthcheck')
def setup_class(cls): cls.client = app.test_client() cls.default_headers = {'Content-Type': 'application/json'} autor = AutorModel(nome='teste') autor.save() noticia = NoticiaModel(titulo='teste 1', texto='teste teste 1', autor=autor) noticia.save() cls.new_data = { 'titulo': 'teste', 'texto': 'teste update', 'autor': { 'nome': 'autor update' } } cls.created_data = [] cls.noticia_id = str(noticia.id)
def setup_class(cls): cls.client = app.test_client() cls.default_headers = {'Content-Type': 'application/json'} cls.data = { 'titulo': 'teste 1', 'texto': 'teste search', 'autor': { 'nome': 'autor search' } } cls.data2 = { 'titulo': 'abc', 'texto': 'abc', 'autor': { 'nome': 'abc' } } cls.data['oid'] = cls._save_data(cls.data) cls.data2['oid'] = cls._save_data(cls.data2)
def test_file_upload(self): app.config['UPLOADED_PHOTOS_DEST'] = '../static' client = app.test_client( ) # you will need your flask app to create the test_client # note in that in the previous line you can use 'file' or whatever you want. # flask client checks for the tuple (<FileObject>, <String>) data = { 'images': (BytesIO(b'image byte info goes there'), 'sample_img.jpeg') } response = client.post('upload', buffered=True, content_type='multipart/form-data', data=data) self.assertEqual(response.status_code, 200) image_names = os.listdir('static/') self.assertEqual( any(name == 'sample_img.jpeg' for name in image_names), True)
def setUp(self): self.app = app.test_client()
def setUp(self): # Fix to make 'make_response' work. os.chdir('../src/') app.config['TESTING'] = True self.app = app.test_client()
def test_response_obj(): resp = app.test_client().get('/') assert(resp.status_code == 200)