From c36c27521dd4d2b41461a8f9b0d925685ce5c911 Mon Sep 17 00:00:00 2001 From: Oluwabunmi Fife Date: Thu, 8 Dec 2022 14:25:35 +0100 Subject: [PATCH 1/2] feat(BAE-22): Restarted this branch and resolved related issues --- Backend/tests/test_api_status.py | 13 ++++++ Backend/tests/test_delete_statement.py | 26 +++++++++++ Backend/tests/test_post_account_statement.py | 48 ++++++++++++++++++++ config/definitions.py | 2 + 4 files changed, 89 insertions(+) create mode 100644 Backend/tests/test_api_status.py create mode 100644 Backend/tests/test_delete_statement.py create mode 100644 Backend/tests/test_post_account_statement.py create mode 100644 config/definitions.py diff --git a/Backend/tests/test_api_status.py b/Backend/tests/test_api_status.py new file mode 100644 index 00000000..93c05a82 --- /dev/null +++ b/Backend/tests/test_api_status.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +""" TEST FOR API STATUS """ +from fastapi.testclient import TestClient +from ..routes.api_status import router + +client = TestClient(router) + + +def test_api_status(): + """ Tests the API status """ + response = client.get("/") + assert response.status_code == 200 + assert response.json() == {"message": "Connection Successful"} diff --git a/Backend/tests/test_delete_statement.py b/Backend/tests/test_delete_statement.py new file mode 100644 index 00000000..eee53990 --- /dev/null +++ b/Backend/tests/test_delete_statement.py @@ -0,0 +1,26 @@ +from fastapi.testclient import TestClient +from ..routes.delete_documents import router + +client = TestClient(router) + +def test_delete_statement_success(): + """ Tests a successful delete """ + url = 'http://127.0.0.1:8000/delete_statement/{filename}' + # file = open(__file__, 'r+') + response = client.delete(url=url) + if response.status_code == 204: + assert {"message": "Successful deletion"} + else: + assert{"message": "Something went wrong"} + +def test_delete_statement_record(): + """ Tests a successful delete """ + url = 'http://127.0.0.1:8000/delete_record/{filename}' + # file = open(__file__, 'r+') + response = client.delete(url=url) + if response.status_code == 204: + assert {"message": "Successful deletion"} + else: + assert {"message": "Something went wrong"} + + diff --git a/Backend/tests/test_post_account_statement.py b/Backend/tests/test_post_account_statement.py new file mode 100644 index 00000000..8f0a0bd3 --- /dev/null +++ b/Backend/tests/test_post_account_statement.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 +""" TEST FOR POST METHOD FOR DOCUMENTS """ +import os + +from fastapi import UploadFile, File +from fastapi.testclient import TestClient +from ..routes.post_documents import router +from ...config.definitions import ROOT_DIR + +client = TestClient(router) + +# Returns the relative path for test.csv -> str +def get_rel_path(): + return (os.path.join(ROOT_DIR, 'tests', 'test.csv')) + +def test_upload_statement_success(): + + # _test_upload_file = path('Backend\dummy_account_statement.csv') + + url = 'http://127.0.0.1:8000/upload_statement' + + #RETURNING ASSERTION ERROR + #file = {'file': (open(get_rel_path(), 'rb'))} + + + #RETURNING ValueError: too many values to unpack (expected 2) + # with open(get_rel_path(), 'rb') as f: + # lines = f.readlines() + + #RETURNING ValueError: too many values to unpack (expected 2) + file = open(get_rel_path(), 'rb') + response = client.post(url=url, files=file) + #files.close() + assert response.status_code == 200 + + #assert type(response.json()) == str + + + + + +def test_upload_record_success(): + url = 'http://127.0.0.1:8000/upload_record' + file = open(r'test.csv') + +# response = client.post(url=url, files=file) +# assert response.status_code == 200 + diff --git a/config/definitions.py b/config/definitions.py new file mode 100644 index 00000000..d5c9a0e8 --- /dev/null +++ b/config/definitions.py @@ -0,0 +1,2 @@ +import os +ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..')) \ No newline at end of file From 8413518d03e703bdafdf0becc4c0aa69ef69a667 Mon Sep 17 00:00:00 2001 From: Oluwabunmi Fife Date: Thu, 8 Dec 2022 14:59:24 +0100 Subject: [PATCH 2/2] chore(BAE-22): Cleaned up tests --- Backend/tests/__init__.py | 0 Backend/tests/test_post_account_statement.py | 22 ++++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) create mode 100644 Backend/tests/__init__.py diff --git a/Backend/tests/__init__.py b/Backend/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Backend/tests/test_post_account_statement.py b/Backend/tests/test_post_account_statement.py index 8f0a0bd3..2873196d 100644 --- a/Backend/tests/test_post_account_statement.py +++ b/Backend/tests/test_post_account_statement.py @@ -15,25 +15,12 @@ def get_rel_path(): def test_upload_statement_success(): - # _test_upload_file = path('Backend\dummy_account_statement.csv') - url = 'http://127.0.0.1:8000/upload_statement' - - #RETURNING ASSERTION ERROR - #file = {'file': (open(get_rel_path(), 'rb'))} - - #RETURNING ValueError: too many values to unpack (expected 2) - # with open(get_rel_path(), 'rb') as f: - # lines = f.readlines() - - #RETURNING ValueError: too many values to unpack (expected 2) + url = 'http://127.0.0.1:8000/upload_statement' file = open(get_rel_path(), 'rb') response = client.post(url=url, files=file) - #files.close() - assert response.status_code == 200 - #assert type(response.json()) == str @@ -41,8 +28,7 @@ def test_upload_statement_success(): def test_upload_record_success(): url = 'http://127.0.0.1:8000/upload_record' - file = open(r'test.csv') - -# response = client.post(url=url, files=file) -# assert response.status_code == 200 + file = open(r'test.csv') + response = client.post(url=url, files=file) + assert response.status_code == 200