def setUp(self): self.test_client = create_app().test_client() TestUtils.insert_dummy() TestUtils.login_dummy() self.test_body = { 'alias': 'dummy test account', 'type': 'saving', 'deposit': 0.0 }
def login_dummy(cls): response = create_app().test_client().post(cls.login_route, json={ 'username': cls.username, 'password': cls.password }) token = response.get_json()['access_token'] cls.login_header = {'Authorization': 'Bearer ' + token}
def main(): parser = argparse.ArgumentParser(description='Flask Bank Project', epilog='Default: run on local machine, ' 'debug on') group = parser.add_mutually_exclusive_group() group.add_argument('-p', '--production', action='store_true', help='Production mode, debug off') args = parser.parse_args() production = args.production if production: print('Using Production Configuration') create_app(ProductionConfig).run(threaded=True, host="0.0.0.0") else: print('Using Development Configuration') create_app().run(threaded=True, host="0.0.0.0")
def setUp(self): TestUtils.insert_dummy() self.test_client = create_app().test_client() self.password = TestUtils.password self.http_body = { 'username': TestUtils.username, 'password': self.password } self.login_route = 'http://127.0.0.1:5000/api/login' self.login = lambda: self.test_client.post(self.login_route, json=self.http_body)
def setUp(self): self.test_client = create_app().test_client() TestUtils.insert_dummy() self.auth_token = self.test_client.post( 'http://127.0.0.1:5000/api/login', json={ 'username': TestUtils.username, 'password': TestUtils.password }).get_json().get('access_token', 'bad') self.info_route = 'http://127.0.0.1:5000/api/client/info' self.get_client = lambda: self.test_client.get( self.info_route, headers={'Authorization': 'Bearer ' + self.auth_token})
def setUp(self): self.test_client = create_app().test_client() self.username = '******' self.reg_route = 'http://127.0.0.1:5000/api/register' self.del_route = f'http://127.0.0.1:5000/api/utils' \ f'/!CLEAR_ONE_CLIENTS/{self.username}' self.http_body = { 'first_name': 'first', 'last_name': 'last', 'email': '*****@*****.**', 'username': self.username, 'password': '******' } self.test_client.delete(self.del_route)
def test_signup_and_delete(self): app = create_app().test_client() # ------------------------------------------------------------------------------ # Check normal registration response = app.post('http://127.0.0.1:5000/api/register', json={ 'first_name': 'some random', 'last_name': 'some random', 'email': 'some random', 'username': '******', 'password': '******' }) json_data = response.get_json() self.assertEqual(response.status_code, 201) # ------------------------------------------------------------------------------ # Check normal deletion response = app.delete( 'http://127.0.0.1:5000/api/utils/!CLEAR_ONE_CLIENTS/some random') self.assertEqual(response.status_code, 200)
def test_login(self): app = create_app().test_client() # ------------------------------------------------------------------------------ # Check if the username and password matches response = app.post('http://127.0.0.1:5000/api/login', json={ 'username': '******', 'password': '******' }) json_data = response.get_json() self.assertEqual(response.status_code, 201) # ------------------------------------------------------------------------------ # Check non-exist user response = app.post('http://127.0.0.1:5000/api/login', json={ 'username': '******', 'password': '******' }) json_data = response.get_json() self.assertEqual(response.status_code, 409) # ------------------------------------------------------------------------------ # Bad Request, missing key response = app.post('http://127.0.0.1:5000/api/login', json={'username': '******'}) json_data = response.get_json() self.assertEqual(response.status_code, 400) # ------------------------------------------------------------------------------ # Bad Request, misspelled key response = app.post('http://127.0.0.1:5000/api/login', json={ 'user_name': 'some random', 'pass_word': 'some random' }) json_data = response.get_json() self.assertEqual(response.status_code, 400)
from flaskbank.backend import create_app from flaskbank.backend.config import ProductionConfig app = create_app(ProductionConfig)
def insert_dummy(cls): create_app().test_client().post(cls.reg_route, json=cls.dummy)
def delete_dummy(cls): create_app().test_client().delete(cls.del_route)