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_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..2873196d --- /dev/null +++ b/Backend/tests/test_post_account_statement.py @@ -0,0 +1,34 @@ +#!/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(): + + + + url = 'http://127.0.0.1:8000/upload_statement' + file = open(get_rel_path(), 'rb') + response = client.post(url=url, files=file) + + + + + + +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