From 994df3a7df9f32f26492bb1a49ac0e40ac1c70da Mon Sep 17 00:00:00 2001 From: Alvaro Guadamillas Date: Sun, 8 Oct 2023 21:50:55 +0200 Subject: [PATCH] fix: unit testing --- tests/conftest.py | 2 +- tests/functional/test_routes.py | 8 +++++--- tests/unit/test_model.py | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e173e54..2809798 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ def testing_client(scope='module'): with app.app_context(): db.create_all() - account = Account('Test Account', '€') + account = Account('Test Account', '€', 'Spain') db.session.add(account) db.session.commit() diff --git a/tests/functional/test_routes.py b/tests/functional/test_routes.py index 4d54e86..7704f28 100644 --- a/tests/functional/test_routes.py +++ b/tests/functional/test_routes.py @@ -1,6 +1,7 @@ from iebank_api import app import pytest + def test_get_accounts(testing_client): """ GIVEN a Flask application @@ -10,6 +11,7 @@ def test_get_accounts(testing_client): response = testing_client.get('/accounts') assert response.status_code == 200 + def test_dummy_wrong_path(): """ GIVEN a Flask application @@ -20,13 +22,13 @@ def test_dummy_wrong_path(): response = client.get('/wrong_path') assert response.status_code == 404 + def test_create_account(testing_client): """ GIVEN a Flask application WHEN the '/accounts' page is posted to (POST) THEN check the response is valid """ - response = testing_client.post('/accounts', json={'name': 'John Doe', 'currency': '€'}) + response = testing_client.post( + '/accounts', json={'name': 'John Doe', 'currency': '€', 'country': 'Spain'}) assert response.status_code == 200 - - diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py index 42eabd4..6a7ce27 100644 --- a/tests/unit/test_model.py +++ b/tests/unit/test_model.py @@ -5,11 +5,12 @@ def test_create_account(): """ GIVEN a Account model WHEN a new Account is created - THEN check the name, account_number, balance, currency, status and created_at fields are defined correctly + THEN check the name, account_number, balance, currency, country, status and created_at fields are defined correctly """ - account = Account('John Doe', '€') + account = Account('John Doe', '€', 'Spain') assert account.name == 'John Doe' assert account.currency == '€' assert account.account_number != None assert account.balance == 0.0 - assert account.status == 'Active' \ No newline at end of file + assert account.status == 'Active' + assert account.country == 'Spain' \ No newline at end of file