def test_login_user(test_context): test_client, dummy_user, token = test_context path = '/api/v1/users/login' data = {'email': dummy_user.email, 'password': '******'} res = make_post_request(path, test_client, data, token) assert res.status_code == 200
def test_create_user(test_context): test_client, dummy_user, token = test_context new_user = { 'email': '*****@*****.**', 'username': '******', 'password': '******' } res = make_post_request('/api/v1/users/', test_client, new_user, token) created_user = UserModel.get_user_by_email('*****@*****.**') assert created_user is not None assert res.status_code == 201
def test_create_account_success(test_context): test_client, dummy_user, token = test_context new_account = { 'user_id': dummy_user.id, 'balance': 5, 'account_number': 'test_create_account_success' } res = make_post_request('/api/v1/accounts/', test_client, new_account, token) created_account = AccountModel.query.filter( AccountModel.account_number == 'test_account_number') assert created_account is not None assert res.status_code == 201
def test_create_account_failure(test_context): test_client, dummy_user, token = test_context account_details = { 'user_id': dummy_user.id, 'balance': 5, 'account_number': 'test_create_account_failure' } account = AccountModel(account_details) account.save() res = make_post_request('/api/v1/accounts/', test_client, account_details, token) assert res.status_code == 403 assert res.get_json() == { 'error': 'Account with account_number {} already exist for user_id {}, please supply another account number' .format(account.account_number, str(dummy_user.id)) }
def test_create_transaction_success(test_context): test_client, dummy_user, token = test_context from_account = AccountModel({ "user_id": dummy_user.id, "balance": 20, "account_number": "to_account", }) from_account.save() to_user = UserModel({ "username": "******", "email": "*****@*****.**", "password": "******" }) to_user.save() to_account = AccountModel({ "user_id": to_user.id, "balance": 0, "account_number": "from_account" }) to_account.save() transaction_details = { "to_account_id": to_account.id, "from_account_id": from_account.id, "amount": 20, } res = make_post_request('/api/v1/transactions/', test_client, transaction_details, token) assert res.status_code == 201 updated_from_account = AccountModel.get_one_account(from_account.id) updated_to_account = AccountModel.get_one_account(to_account.id) assert updated_from_account.balance == 0 assert updated_to_account.balance == 20
def test_create_transaction_permission_error(test_context): test_client, dummy_user, token = test_context user_with_permissions = UserModel({ "email": "user@with_permissions.com", "password": "******", "username": "******" }) user_with_permissions.save() from_account = AccountModel({ "user_id": user_with_permissions.id, "balance": 20, "account_number": "to_account", }) from_account.save() to_account = AccountModel({ "user_id": dummy_user.id, "balance": 0, "account_number": "from_account" }) to_account.save() transaction_details = { "to_account_id": dummy_user.id, "from_account_id": from_account.id, "amount": 20, } res = make_post_request('/api/v1/transactions/', test_client, transaction_details, token) assert res.status_code == 403 updated_from_account = AccountModel.get_one_account(from_account.id) updated_to_account = AccountModel.get_one_account(to_account.id) assert updated_from_account.balance == 20 assert updated_to_account.balance == 0