def rig_test_client(data): with testing.postgresql.Postgresql() as postgresql: dburl = postgresql.url() engine = create_engine(dburl) setup_data(engine, data) app.config['SQLALCHEMY_DATABASE_URI'] = dburl yield app.test_client()
def test_handler_add_station_responses_404(): test_data = {'station_id': 182, 'weekday': 7} headers = {'Content-Type': 'application/json'} with app.test_client() as client: response = client.post('/v1/users/-jbjbjnbk/stations/', headers=headers, data=json.dumps(test_data)) assert response.status == '404 NOT FOUND'
def authorized_client( users_service: UsersService, ) -> Generator[Client, None, None]: token = users_service.get_user_token() app.test_client_class = AuthorizedClient with app.test_client(token=token) as client: app.before_first_request_funcs = [] yield client
def test_handler_users_stations_returns_correct_structure(): with app.test_client() as client: response = client.get('/v1/stations/users/?from=35&to=66') json_data = response.get_json() user = json_data[0] assert 'email' in user assert 'id' in user assert 'name' in user
def test_post(self): with app.test_client() as c: rv = c.post('/api/auth', json={ 'username': '******', 'password': '******' }) json_data = rv.get_json() assert (json_data)
def setUp(self): self.app = app.test_client() token = jwt.encode( { 'id_geral': 1, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=40) }, app.config['SECRET_KEY']) self.headers = {'token': token}
def test_handler_station_returns_correct_structure(): with app.test_client() as client: response = client.get('/v1/stations/') json_data = response.get_json() station = json_data[0] assert 'active' in station assert 'id' in station assert 'line_id' in station assert 'name' in station assert 'order_on_line' in station
def client(): app.config["TESTING"] = True # mocker.patch.object(liquidity.LpClient, "get_quote", return_value=MOCK_QUOTE) # mocker.patch.object( # liquidity.LpClient, "trade_and_execute", return_value=MOCK_TRADE # ) # mocker.patch.object(liquidity.LpClient, "lp_details", return_value=MOCK_LP_DETAILS) with app.test_client() as client: yield client
def test_handler_delete_station_responses_200(): headers = {'Content-Type': 'application/json'} with app.test_client() as client: response = client.delete('/v1/users/4/stations/190/', headers=headers) assert response.status == '200 OK' records = db.session.query(UserStation).filter( UserStation.user_id == 4, UserStation.station_id == 190).all() assert len(records) == 0
def setUp(self): self.app = app.test_client() self.app_context = app.app_context() self.app_context.__enter__() db.drop_all() db.create_all() self.user1 = User('user1', '123456') self.user2 = User('user2', '123456') db.session.add(self.user1) db.session.add(self.user2) db.session.commit()
def rig_test_client(): with testing.postgresql.Postgresql() as postgresql: with app.app_context(): dburl = postgresql.url() engine = create_engine(dburl) Base.metadata.create_all(engine) db_session.bind = engine user_datastore = SQLAlchemySessionUserDatastore( db_session, User, Role) app.config['SQLALCHEMY_DATABASE_URI'] = dburl app.config['WTF_CSRF_ENABLED'] = False init_app_with_options(user_datastore) yield app.test_client(), engine
def test_handler_add_station_responses_200(): test_data = {'station_id': 190, 'weekday': 7} headers = {'Content-Type': 'application/json'} with app.test_client() as client: response = client.post('/v1/users/4/stations/', headers=headers, data=json.dumps(test_data)) assert response.status == '200 OK' records = db.session.query(UserStation).filter( UserStation.user_id == 4, UserStation.station_id == 190).all() assert len(records) == 1
def client(): import tempfile import shutil models_dir, results_dir = None, None try: models_dir = tempfile.mkdtemp(prefix='models_tmp') results_dir = tempfile.mkdtemp(prefix='results_tmp') app.config['MODELS_PATH'] = models_dir app.config['RESULTS_PATH'] = results_dir yield app.test_client() finally: # cleanup temp dirs, log errors instead of crashing shutil.rmtree(results_dir, onerror=cleanup_error) shutil.rmtree(models_dir, onerror=cleanup_error)
def setUp(self): db_user = app.config['DB_USERNAME'] db_pass = app.config['DB_PASSWORD'] db_host = app.config['DB_HOST'] db_name = 'test_blog' self.db_uri = "mysql+pymysql://%s:%s@%s/" % (db_user, db_pass, db_host) app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['BLOG_DATABASE_NAME'] = db_name app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uri + db_name engine = sqlalchemy.create_engine(self.db_uri) conn = engine.connect() conn.execute("commit") conn.execute("CREATE DATABASE %s" % db_name) db.create_all() conn.close() self.app = app.test_client()
def test_ok(self): with app.test_client() as client: resp = client.get("/") self.assertEqual(resp.status_code, 200)
def test_handler_station_responses_200(): with app.test_client() as client: response = client.get('/v1/stations/') assert response.status == '200 OK' json_data = response.get_json() assert len(json_data) > 0
def before_all(context): context.app = app.test_client()
def test_stuff(self): self.login('root', 'public') rv = self.app.get('/') rv.data with app.test_client(): print User.query.all() # !!!!! ***** See ***** !!!!!
def app(db): """Set up the Flask test client""" return flask_app.test_client()
def setUp(self): self.app = app.test_client() db.create_all()
def test_testing_endpoint(): response = app.test_client().get("/testing") assert response.status_code == 200
def test_it_can_serve_HTTP(): browser = app.test_client() response = browser.get('/') assert response.status_code == 200
def test_db_list(): response = app.test_client().get("/db_list") assert response.status_code == 200
def test_handler_users_stations_responses_404(): with app.test_client() as client: response = client.get('/v1/stations/users/?from=-58&to=abcd') assert response.status == '404 NOT FOUND'
def test_db_choose(): response = app.test_client().get("/db_choose/cmpd") assert response.status_code == 200 response_data = json.loads(response.get_data().decode('utf-8')) assert response_data['result'] == app.config['DB_NAME']
def test_handler_users_stations_responses_200(): with app.test_client() as client: response = client.get('/v1/stations/users/?from=35&to=66') assert response.status == '200 OK' json_data = response.get_json() assert len(json_data) > 0
def setUp(self): app.config.from_object('webapp.config.Testing') db.init_app(app) self.app = app.test_client()
def create_app(self): self.app = app.test_client() return app
def test_inner(self): raise Exception("test error") with app.test_client() as client: resp = client.get("/") self.assertIn(b"masha", resp.data)
def setUp(self): self.debug = False self.client = app.test_client()
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys sys.path.append("..") from flask import * from webapp import app, db from webapp.apps.spamsub.models import * app.testing = True client = app.test_client() ctx = app.test_request_context() ctx.push() print "app and db have been imported.\nYou have a test client: client,\nand a test request context: ctx"
def test_response_data(self): tester = app.test_client(self) response = tester.get('/foundme') self.assertEqual(response.data, b'You found me!')
def setUp(self): self.client = app.test_client()
def test_response(self): tester = app.test_client(self) response = tester.get('/foundme') self.assertEqual(response.status_code, 200)
def api(): app.debug = True app.testing = True yield app.test_client()
def test_web_view(self): with app.test_client() as c: resp = c.get('/tasks') data = flask.json.loads(resp.data) assertEquals(data['contains'], "Ahmed")
def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True self.app = app.test_client()