def client(): """ Starts Flask test client """ application.config.update(TESTING=True, WTF_CSRF_ENABLED=False) test_client = application.test_client() yield test_client
def test_retrieve_summary(self): tester = application.test_client(self) response = tester.post('/summary', data=json.dumps(dict(text=text)), content_type='application/json') self.assertEqual(response.status_code, 200) self.assertTrue(b'result' in response.data)
def test_genre(): response = application.test_client().get('/genre/scifi') bookstr = str(response.data, 'utf-8') li = list(bookstr.split("{}")) print(li) assert response.status_code == 200 assert len(li) == 1
def setUp(self): """Set up a blank temp database before each test""" basedir = os.path.abspath(os.path.dirname(__file__)) app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all()
def test_saved_login(self): # Tests whether the login persists accross requests client = pli.test_client() r = post_login(client, user1["email_address"], user1["real_pass"]) self.assertEqual(200, r.status_code) # route registered during test setup r = client.get("/test-login") self.assertTrue(r.data == "True")
def cli_client(user_api_key, user_id): # we need to use `user_id` fixture here to create a user in the db """ CLI client fixture. This fixture should be used when we are testing API used by the CLI and using API key auth """ application.config['TESTING'] = True # This is a custom testing client class, it is set for the scope of the test session, unless we set it back application.test_client_class = CLIClient with application.test_client(api_key=user_api_key) as client: yield client
def setUp(self): """ start application test client, This function runs once before each member function unit test. """ application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False self.app = application.test_client() self.app_context = application.app_context() self.app_context.push()
def test_rest_create_feature(self): tester = application.test_client(self) response = tester.post('/features', data=dict(id="", title="Test Feature", description="Test Description", client="1", priority="1", target="2019-08-30", area="Billings"), follow_redirects=True) self.assertIn(b'All good', response.data)
def client(): db_fd, application.config['DATABASE'] = tempfile.mkstemp() application.config['TESTING'] = True application.config['DEBUG'] = False with application.test_client() as client: with application.app_context(): database.init_app(application) yield client os.close(db_fd) os.unlink(application.config['DATABASE'])
def web_client(postgres, user_id, user_email): """ Web client fixture. This fixture should be used when we are testing API used by the frontend and complying with auth0 authentication """ application.config['TESTING'] = True # This is a default class, but we need to explicitly set it because cli_client overwrites it application.test_client_class = FlaskClient with application.test_client() as client: with client.session_transaction() as session: session['jwt_payload'] = session['profile'] = { 'user_id': user_id, # no matter what is in here 'email': user_email, 'internal_user_id': user_id } yield client
def automation_client(user_id): # we need to use `user_id` fixture here to create a user in the db """ Automation client fixture. This fixutre should be used when we are testing endpoints called by our automation and using BasicAuth """ application.config['TESTING'] = True # This is a default class, but we need to explicitly set it because cli_client overwrites it application.test_client_class = FlaskClient env_back = copy.deepcopy(os.environ) os.environ['GITHUB_ACTIONS_PASSWORD'] = '******' os.environ['LAMBDA_PROXY_PASSWORD'] = '******' with application.test_client() as client: yield client os.environ = env_back
def actual_function(s): with pli.test_client() as client: n = ("?next=" + to) if to is not None else "" if passwd is not None or username is None: r = post_login(client, username, passwd, url='/login' + n) else: r = post_login(client, username["email_address"], username["real_pass"], url='/login' + n) p_len = len(inspect.getargspec(f).args) if p_len == 1: f(s) elif p_len == 2: f(s, client) elif p_len == 3: f(s, client, r) else: # TODO pass
def setUp(self): food_diary_manager.truncate() self.app = application.test_client()
def test_upload(self): tester = application.test_client(self) response = tester.get('/', content_type='html/text') assert response.status_code == 200
def setUp(self): self.client = app.test_client( ) # get the client instance to use to test the endpoints
def test_userdelete(self): tester = application.test_client(self) response = tester.delete('/users/delete?userId=1', content_type='html/text') assert response.status_code == 200
def test_index(): response = application.test_client().get('/') assert response.status_code == 200 assert response.data == b"Congratulations!! TO FLASK-AWS APP"
def setUp(self): self.s3 = test_s3.S3() s3.gw = self.s3 app.debug = True self.c = app.test_client()
def test_popular(): response = application.test_client().get('/popular') assert response.status_code == 200
def test_rating(): with application.test_client() as c: response = c.post('/rating', json={'isbn': '765326361', 'rating': '4'}) assert response.status_code == 200
def test_signup_incompletepost_5(self): tester = application.test_client(self) response = tester.post('/users/signup',data=dict(email="*****@*****.**", name="Joyce"), follow_redirects=True) assert response.status_code == 400
def test_signup_incompletepost_4(self): tester = application.test_client(self) data = {'email':'*****@*****.**', 'name':''} response = tester.post('/users/signup', data=json.dumps(data), content_type='application/json', follow_redirects=True) assert response.status_code == 400
def setUp(self): application.config['TESTING'] = True application.config['WTF_CSRF_ENABLED'] = False application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db') self.app = application.test_client() db.create_all()
from application import application with application.test_client() as c: response = c.get('/') assert response.data == b'Hello Test Application!' assert response.status_code == 200
def setUp(self): self.client = application.test_client()
def setUp(self): application.config['TESTING'] = True client = application.test_client() self.client = client
def test_signup_success(self): tester = application.test_client(self) data = {'email':'*****@*****.**', 'name':'Edgar'} response = tester.post('/users/signup', data=json.dumps(data), content_type='application/json', follow_redirects=True) assert response.status_code == 201
def client(): application.config['TESTING'] = True client = application.test_client() yield client
def test_signin_noemail(self): tester = application.test_client(self) data = {'email':'*****@*****.**'} response = tester.post('/users/login', data=json.dumps(data), content_type='application/json', follow_redirects=True) assert response.status_code == 404
def setUp(self): self.client = app.test_client( ) # get the client instance to use to test the endpoints self.email = os.getenv('EMAIL_TEST')
def test_signin_success(self): tester = application.test_client(self) data = {'email':'*****@*****.**'} response = tester.post('/users/login', data=json.dumps(data), content_type='application/json', follow_redirects=True) assert response.status_code == 200
def client(): """Generic Flask application fixture""" application.testing = True return application.test_client()
def test_adminsearch_notadmin(self): tester = application.test_client(self) response = tester.get('/admin/users/name?userId=1&searchUserId=1', content_type='html/text') assert response.status_code == 401