From 45714b90d6c485e276f78efa27ddcd4940ed73d5 Mon Sep 17 00:00:00 2001 From: Benjamin Dornel Date: Sat, 7 Oct 2023 00:37:07 +0800 Subject: [PATCH] refactor(tests): separate tests into unit and integration --- .gitattributes | 2 +- .gitignore | 4 ++-- tests/conftest.py | 6 +++--- .../banks}/citibank/test_citibank_extract.py | 2 +- .../banks}/citibank/test_citibank_transform.py | 0 .../banks}/hsbc/test_hsbc_extract.py | 2 +- .../banks}/hsbc/test_hsbc_transform.py | 0 .../banks}/ocbc/test_ocbc_extract.py | 2 +- .../{ => integration/banks}/ocbc/test_ocbc_load.py | 0 .../banks}/ocbc/test_ocbc_transform.py | 0 tests/{ => integration}/fixtures/4_pages_blank.pdf | Bin .../fixtures/citibank/expected.csv | 0 tests/{ => integration}/fixtures/citibank/input.pdf | Bin tests/{ => integration}/fixtures/hsbc/expected.csv | 0 tests/{ => integration}/fixtures/hsbc/input.pdf | Bin tests/{ => integration}/fixtures/ocbc/expected.csv | 0 tests/{ => integration}/fixtures/ocbc/input.pdf | Bin tests/{ => integration}/fixtures/protected.pdf | Bin .../{gmail => integration}/test_main_entrypoint.py | 1 + tests/{ => integration}/test_parser.py | 10 +++++----- tests/{ => integration}/test_statement_date.py | 0 tests/{gmail => unit}/test_check_trusted_user.py | 0 tests/{ => unit}/test_generate_name.py | 0 tests/{gmail => unit}/test_get_attachment.py | 0 tests/{gmail => unit}/test_persist_attachment.py | 0 25 files changed, 15 insertions(+), 14 deletions(-) rename tests/{ => integration/banks}/citibank/test_citibank_extract.py (83%) rename tests/{ => integration/banks}/citibank/test_citibank_transform.py (100%) rename tests/{ => integration/banks}/hsbc/test_hsbc_extract.py (81%) rename tests/{ => integration/banks}/hsbc/test_hsbc_transform.py (100%) rename tests/{ => integration/banks}/ocbc/test_ocbc_extract.py (83%) rename tests/{ => integration/banks}/ocbc/test_ocbc_load.py (100%) rename tests/{ => integration/banks}/ocbc/test_ocbc_transform.py (100%) rename tests/{ => integration}/fixtures/4_pages_blank.pdf (100%) rename tests/{ => integration}/fixtures/citibank/expected.csv (100%) rename tests/{ => integration}/fixtures/citibank/input.pdf (100%) rename tests/{ => integration}/fixtures/hsbc/expected.csv (100%) rename tests/{ => integration}/fixtures/hsbc/input.pdf (100%) rename tests/{ => integration}/fixtures/ocbc/expected.csv (100%) rename tests/{ => integration}/fixtures/ocbc/input.pdf (100%) rename tests/{ => integration}/fixtures/protected.pdf (100%) rename tests/{gmail => integration}/test_main_entrypoint.py (96%) rename tests/{ => integration}/test_parser.py (71%) rename tests/{ => integration}/test_statement_date.py (100%) rename tests/{gmail => unit}/test_check_trusted_user.py (100%) rename tests/{ => unit}/test_generate_name.py (100%) rename tests/{gmail => unit}/test_get_attachment.py (100%) rename tests/{gmail => unit}/test_persist_attachment.py (100%) diff --git a/.gitattributes b/.gitattributes index 7fbd9d32..6e5b05df 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -tests/fixtures/**/input.pdf filter=git-crypt diff=git-crypt +tests/integration/fixtures/**/input.pdf filter=git-crypt diff=git-crypt diff --git a/.gitignore b/.gitignore index 5b39bd82..3c29102e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,8 @@ _ignore* *.tfvars # allowed pdf files/fixtures -!tests/fixtures/*/** -!tests/fixtures/*.pdf +!tests/integration/fixtures/*/** +!tests/integration/fixtures/*.pdf !monopoly/examples/*.pdf # john files diff --git a/tests/conftest.py b/tests/conftest.py index 9625eb0f..58dfaadb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,19 +15,19 @@ @pytest.fixture(scope="session") def citibank(): - citibank = Citibank(file_path="tests/fixtures/citibank/input.pdf") + citibank = Citibank(file_path="tests/integration/fixtures/citibank/input.pdf") yield citibank @pytest.fixture(scope="session") def ocbc(): - ocbc = Ocbc(file_path="tests/fixtures/ocbc/input.pdf") + ocbc = Ocbc(file_path="tests/integration/fixtures/ocbc/input.pdf") yield ocbc @pytest.fixture(scope="session") def hsbc(): - hsbc = Hsbc(file_path="tests/fixtures/hsbc/input.pdf") + hsbc = Hsbc(file_path="tests/integration/fixtures/hsbc/input.pdf") yield hsbc diff --git a/tests/citibank/test_citibank_extract.py b/tests/integration/banks/citibank/test_citibank_extract.py similarity index 83% rename from tests/citibank/test_citibank_extract.py rename to tests/integration/banks/citibank/test_citibank_extract.py index 05397194..c78d31b4 100644 --- a/tests/citibank/test_citibank_extract.py +++ b/tests/integration/banks/citibank/test_citibank_extract.py @@ -7,7 +7,7 @@ def test_citibank_extract_unprotected_pdf(citibank: Citibank): raw_df = citibank.extract().df - expected_df = pd.read_csv("tests/fixtures/citibank/expected.csv") + expected_df = pd.read_csv("tests/integration/fixtures/citibank/expected.csv") assert_frame_equal(raw_df, expected_df) diff --git a/tests/citibank/test_citibank_transform.py b/tests/integration/banks/citibank/test_citibank_transform.py similarity index 100% rename from tests/citibank/test_citibank_transform.py rename to tests/integration/banks/citibank/test_citibank_transform.py diff --git a/tests/hsbc/test_hsbc_extract.py b/tests/integration/banks/hsbc/test_hsbc_extract.py similarity index 81% rename from tests/hsbc/test_hsbc_extract.py rename to tests/integration/banks/hsbc/test_hsbc_extract.py index 48f31447..b5e0e399 100644 --- a/tests/hsbc/test_hsbc_extract.py +++ b/tests/integration/banks/hsbc/test_hsbc_extract.py @@ -7,7 +7,7 @@ def test_hsbc_extract_unprotected_pdf(hsbc: Hsbc): raw_df = hsbc.extract().df - expected_df = pd.read_csv("tests/fixtures/hsbc/expected.csv") + expected_df = pd.read_csv("tests/integration/fixtures/hsbc/expected.csv") assert_frame_equal(raw_df, expected_df) diff --git a/tests/hsbc/test_hsbc_transform.py b/tests/integration/banks/hsbc/test_hsbc_transform.py similarity index 100% rename from tests/hsbc/test_hsbc_transform.py rename to tests/integration/banks/hsbc/test_hsbc_transform.py diff --git a/tests/ocbc/test_ocbc_extract.py b/tests/integration/banks/ocbc/test_ocbc_extract.py similarity index 83% rename from tests/ocbc/test_ocbc_extract.py rename to tests/integration/banks/ocbc/test_ocbc_extract.py index 2ad74440..9a208941 100644 --- a/tests/ocbc/test_ocbc_extract.py +++ b/tests/integration/banks/ocbc/test_ocbc_extract.py @@ -8,7 +8,7 @@ def test_ocbc_extract_unprotected_pdf(ocbc: Ocbc): raw_df = ocbc.extract().df - expected_df = pd.read_csv("tests/fixtures/ocbc/expected.csv") + expected_df = pd.read_csv("tests/integration/fixtures/ocbc/expected.csv") assert_frame_equal(raw_df, expected_df) diff --git a/tests/ocbc/test_ocbc_load.py b/tests/integration/banks/ocbc/test_ocbc_load.py similarity index 100% rename from tests/ocbc/test_ocbc_load.py rename to tests/integration/banks/ocbc/test_ocbc_load.py diff --git a/tests/ocbc/test_ocbc_transform.py b/tests/integration/banks/ocbc/test_ocbc_transform.py similarity index 100% rename from tests/ocbc/test_ocbc_transform.py rename to tests/integration/banks/ocbc/test_ocbc_transform.py diff --git a/tests/fixtures/4_pages_blank.pdf b/tests/integration/fixtures/4_pages_blank.pdf similarity index 100% rename from tests/fixtures/4_pages_blank.pdf rename to tests/integration/fixtures/4_pages_blank.pdf diff --git a/tests/fixtures/citibank/expected.csv b/tests/integration/fixtures/citibank/expected.csv similarity index 100% rename from tests/fixtures/citibank/expected.csv rename to tests/integration/fixtures/citibank/expected.csv diff --git a/tests/fixtures/citibank/input.pdf b/tests/integration/fixtures/citibank/input.pdf similarity index 100% rename from tests/fixtures/citibank/input.pdf rename to tests/integration/fixtures/citibank/input.pdf diff --git a/tests/fixtures/hsbc/expected.csv b/tests/integration/fixtures/hsbc/expected.csv similarity index 100% rename from tests/fixtures/hsbc/expected.csv rename to tests/integration/fixtures/hsbc/expected.csv diff --git a/tests/fixtures/hsbc/input.pdf b/tests/integration/fixtures/hsbc/input.pdf similarity index 100% rename from tests/fixtures/hsbc/input.pdf rename to tests/integration/fixtures/hsbc/input.pdf diff --git a/tests/fixtures/ocbc/expected.csv b/tests/integration/fixtures/ocbc/expected.csv similarity index 100% rename from tests/fixtures/ocbc/expected.csv rename to tests/integration/fixtures/ocbc/expected.csv diff --git a/tests/fixtures/ocbc/input.pdf b/tests/integration/fixtures/ocbc/input.pdf similarity index 100% rename from tests/fixtures/ocbc/input.pdf rename to tests/integration/fixtures/ocbc/input.pdf diff --git a/tests/fixtures/protected.pdf b/tests/integration/fixtures/protected.pdf similarity index 100% rename from tests/fixtures/protected.pdf rename to tests/integration/fixtures/protected.pdf diff --git a/tests/gmail/test_main_entrypoint.py b/tests/integration/test_main_entrypoint.py similarity index 96% rename from tests/gmail/test_main_entrypoint.py rename to tests/integration/test_main_entrypoint.py index 31245cb5..73fdf8df 100644 --- a/tests/gmail/test_main_entrypoint.py +++ b/tests/integration/test_main_entrypoint.py @@ -1,3 +1,4 @@ +"""Test for entrypoint used by Cloud Run""" from unittest.mock import Mock, PropertyMock, patch import pytest diff --git a/tests/test_parser.py b/tests/integration/test_parser.py similarity index 71% rename from tests/test_parser.py rename to tests/integration/test_parser.py index 0b598ed0..7c61470a 100644 --- a/tests/test_parser.py +++ b/tests/integration/test_parser.py @@ -4,14 +4,14 @@ def test_can_open_protected(parser: PdfParser): - parser.file_path = "tests/fixtures/protected.pdf" + parser.file_path = "tests/integration/fixtures/protected.pdf" parser.password = "foobar123" parser.open() def test_wrong_password_raises_error(parser: PdfParser): - parser.file_path = "tests/fixtures/protected.pdf" + parser.file_path = "tests/integration/fixtures/protected.pdf" parser.password = "wrong_pw" with pytest.raises(ValueError, match="document is encrypted"): @@ -19,7 +19,7 @@ def test_wrong_password_raises_error(parser: PdfParser): def test_get_pages(parser: PdfParser): - parser.file_path = "tests/fixtures/4_pages_blank.pdf" + parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf" parser.page_range = slice(0, -1) pages = parser.get_pages() @@ -27,7 +27,7 @@ def test_get_pages(parser: PdfParser): def test_get_pages_invalid_returns_error(parser: PdfParser): - parser.file_path = "tests/fixtures/4_pages_blank.pdf" + parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf" parser.page_range = slice(99, -99) with pytest.raises(ValueError, match="bad page number"): @@ -36,7 +36,7 @@ def test_get_pages_invalid_returns_error(parser: PdfParser): def test_pdf_unlock(parser: PdfParser): password = parser.unlock_pdf( - pdf_file_path="tests/fixtures/protected.pdf", + pdf_file_path="tests/integration/fixtures/protected.pdf", static_string="foobar", mask="?d?d?d", ) diff --git a/tests/test_statement_date.py b/tests/integration/test_statement_date.py similarity index 100% rename from tests/test_statement_date.py rename to tests/integration/test_statement_date.py diff --git a/tests/gmail/test_check_trusted_user.py b/tests/unit/test_check_trusted_user.py similarity index 100% rename from tests/gmail/test_check_trusted_user.py rename to tests/unit/test_check_trusted_user.py diff --git a/tests/test_generate_name.py b/tests/unit/test_generate_name.py similarity index 100% rename from tests/test_generate_name.py rename to tests/unit/test_generate_name.py diff --git a/tests/gmail/test_get_attachment.py b/tests/unit/test_get_attachment.py similarity index 100% rename from tests/gmail/test_get_attachment.py rename to tests/unit/test_get_attachment.py diff --git a/tests/gmail/test_persist_attachment.py b/tests/unit/test_persist_attachment.py similarity index 100% rename from tests/gmail/test_persist_attachment.py rename to tests/unit/test_persist_attachment.py