From fa2b5f98539976122b0395b3a7e196523e2e151b Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Thu, 21 Mar 2024 17:06:06 +0000 Subject: [PATCH 01/29] samwip --- end_of_month/test/test_end_of_month_process.py | 3 +-- makefile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 3ed71ad51..00c8a367b 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -112,9 +112,8 @@ def test_end_of_month_mar(self): class ReadArchivedForecastTest(TestCase): - archived_figure = [] - def setUp(self): + self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() diff --git a/makefile b/makefile index fefcbf811..c5a79bb80 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest -raP --capture=sys --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 black-check: docker-compose run --rm --no-deps web black --check . From 93efe0568eeccdb845b8c31632ac27f73cb1fed6 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Thu, 21 Mar 2024 17:11:46 +0000 Subject: [PATCH 02/29] samwip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index c5a79bb80..6cb33afa4 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 -vv black-check: docker-compose run --rm --no-deps web black --check . From 20ca9038e33a5e5f49903f85b8a6797b38d38ae6 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Thu, 21 Mar 2024 17:31:09 +0000 Subject: [PATCH 03/29] samwip --- end_of_month/test/test_end_of_month_process.py | 3 +-- end_of_month/test/test_outturn_variance.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 00c8a367b..7c0d318b7 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -333,9 +333,8 @@ def test_end_of_month_mar(self): class ReadArchivedBudgetTest(TestCase): - archived_figure = [] - def setUp(self): + self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() for period in range(0, 16): diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 7b2dad2f0..bbbc32728 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -7,9 +7,8 @@ class ReadMonthlyVarianceTest(TestCase): - archived_figure = [] - def setUp(self): + self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() for period in range(0, 16): From 946a94c442a9aa264913b492c76cfb41835cee40 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 09:24:47 +0000 Subject: [PATCH 04/29] samwip --- config/test/__init__.py | 0 config/test/conftest.py | 18 ------------------ core/management/commands/create_stub_data.py | 4 ---- end_of_month/test/test_end_of_month_process.py | 6 ++++-- end_of_month/test/test_outturn_variance.py | 3 ++- .../populate_gift_hospitality_table.py | 4 ---- poetry.lock | 16 +++++++++++++++- pyproject.toml | 1 + 8 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 config/test/__init__.py delete mode 100644 config/test/conftest.py diff --git a/config/test/__init__.py b/config/test/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/config/test/conftest.py b/config/test/conftest.py deleted file mode 100644 index c802caac8..000000000 --- a/config/test/conftest.py +++ /dev/null @@ -1,18 +0,0 @@ -# Used to detect if running from within a pytest run -# https://docs.pytest.org/en/latest/example/simple.html -# required because save in the meta model logchange (in core), save the changes to the log table, with the userid -# but the userid is not valid when we are running from test... - - -def pytest_configure(config): - import core - - print("In pytest_configure") - core._called_from_test = True - - -def pytest_unconfigure(config): - import core - - print("In pytest_unconfigure") - del core._called_from_test diff --git a/core/management/commands/create_stub_data.py b/core/management/commands/create_stub_data.py index 7285cc89d..21fc23c62 100644 --- a/core/management/commands/create_stub_data.py +++ b/core/management/commands/create_stub_data.py @@ -360,10 +360,8 @@ def create(self, what): # The modified save writes the current user to the log, but # the user is not available while we are running a command. # So set the test flag to stop writing to the log - core._called_from_test = True p = what() p.create() - del core._called_from_test self.stdout.write( self.style.SUCCESS( "Successfully completed stub data creation for {}.".format(p.name) @@ -371,10 +369,8 @@ def create(self, what): ) def clear(self, what): - core._called_from_test = True p = what() p.clear() - del core._called_from_test self.stdout.write( self.style.SUCCESS("Successfully cleared stub data for {}.".format(p.name)) ) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 7c0d318b7..3ed71ad51 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -112,8 +112,9 @@ def test_end_of_month_mar(self): class ReadArchivedForecastTest(TestCase): + archived_figure = [] + def setUp(self): - self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() @@ -333,8 +334,9 @@ def test_end_of_month_mar(self): class ReadArchivedBudgetTest(TestCase): + archived_figure = [] + def setUp(self): - self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() for period in range(0, 16): diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index bbbc32728..7b2dad2f0 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -7,8 +7,9 @@ class ReadMonthlyVarianceTest(TestCase): + archived_figure = [] + def setUp(self): - self.archived_figure = [] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() for period in range(0, 16): diff --git a/gifthospitality/management/commands/populate_gift_hospitality_table.py b/gifthospitality/management/commands/populate_gift_hospitality_table.py index 58b0f10cd..0c8c7acd3 100644 --- a/gifthospitality/management/commands/populate_gift_hospitality_table.py +++ b/gifthospitality/management/commands/populate_gift_hospitality_table.py @@ -264,10 +264,8 @@ def add_arguments(self, parser): ) def create(self, what): - core._called_from_test = True p = what() p.create() - del core._called_from_test self.stdout.write( self.style.SUCCESS( "Successfully completed G and H data creation for {}.".format(p.name) @@ -275,10 +273,8 @@ def create(self, what): ) def clear(self, what): - core._called_from_test = True p = what() p.clear() - del core._called_from_test self.stdout.write( self.style.SUCCESS( "Successfully cleared Gift and Hospitality data for {}.".format(p.name) diff --git a/poetry.lock b/poetry.lock index cdace48a6..3744d9c07 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2032,6 +2032,20 @@ pytest = ">=7.0.0" docs = ["sphinx", "sphinx-rtd-theme"] testing = ["Django", "django-configurations (>=2.0)"] +[[package]] +name = "pytest-random-order" +version = "1.1.1" +description = "Randomise the order in which pytest tests are run with some control over the randomness" +optional = false +python-versions = ">=3.5.0" +files = [ + {file = "pytest-random-order-1.1.1.tar.gz", hash = "sha256:4472d7d34f1f1c5f3a359c4ffc5c13ed065232f31eca19c8844c1ab406e79080"}, + {file = "pytest_random_order-1.1.1-py3-none-any.whl", hash = "sha256:882727a8b597ecd06ede28654ffeb8a6d511a1e4abe1054cca7982f2e42008cd"}, +] + +[package.dependencies] +pytest = ">=3.0.0" + [[package]] name = "pytest-xdist" version = "3.5.0" @@ -2723,4 +2737,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "7895d28da3f884172d0dfbfb68d2f18cd1527b4da89d626929ffebd4e74c22d0" +content-hash = "e33a3191e593867bcd2e20fb01070e9ef7994f01a95a98949d8058e5abf9c4e2" diff --git a/pyproject.toml b/pyproject.toml index 580b53a74..bd59ae090 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -147,6 +147,7 @@ wheel = "0.38.1" pep517 = "0.10.0" apipkg = "1.5" toml = "0.10.1" +pytest-random-order = "^1.1.1" [build-system] From 23b88025b6e39c096021ac89eadaaa7bd1792578 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 09:28:13 +0000 Subject: [PATCH 05/29] samwip --- core/management/commands/create_stub_data.py | 1 - .../management/commands/populate_gift_hospitality_table.py | 1 - 2 files changed, 2 deletions(-) diff --git a/core/management/commands/create_stub_data.py b/core/management/commands/create_stub_data.py index 21fc23c62..ec046200e 100644 --- a/core/management/commands/create_stub_data.py +++ b/core/management/commands/create_stub_data.py @@ -1,6 +1,5 @@ from django.core.management.base import BaseCommand -import core from chartofaccountDIT.models import ( Analysis1, Analysis2, diff --git a/gifthospitality/management/commands/populate_gift_hospitality_table.py b/gifthospitality/management/commands/populate_gift_hospitality_table.py index 0c8c7acd3..2cafc0d3f 100644 --- a/gifthospitality/management/commands/populate_gift_hospitality_table.py +++ b/gifthospitality/management/commands/populate_gift_hospitality_table.py @@ -1,6 +1,5 @@ from django.core.management.base import BaseCommand -import core from gifthospitality.models import ( GiftAndHospitalityCategory, GiftAndHospitalityClassification, From 83b8438c9d41e7d822f9575d8878709e903264cb Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 10:12:37 +0000 Subject: [PATCH 06/29] samwip --- end_of_month/test/test_end_of_month_process.py | 8 ++++++-- end_of_month/test/test_outturn_variance.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 3ed71ad51..65d4fbaca 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -112,7 +112,9 @@ def test_end_of_month_mar(self): class ReadArchivedForecastTest(TestCase): - archived_figure = [] + @classmethod + def setUpTestData(cls): + cls.archived_figure = [] def setUp(self): self.init_data = MonthlyFigureSetup() @@ -334,7 +336,9 @@ def test_end_of_month_mar(self): class ReadArchivedBudgetTest(TestCase): - archived_figure = [] + @classmethod + def setUpTestData(cls): + cls.archived_figure = [] def setUp(self): self.init_data = MonthlyFigureSetup() diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 7b2dad2f0..963553ea3 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -7,7 +7,9 @@ class ReadMonthlyVarianceTest(TestCase): - archived_figure = [] + @classmethod + def setUpTestData(cls): + cls.archived_figure = [] def setUp(self): self.init_data = MonthlyFigureSetup() From 0a5d57a1fb5f3ac4138175b3cf7325f1a378b219 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 10:24:47 +0000 Subject: [PATCH 07/29] samwip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 6cb33afa4..443cb8d52 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec web python manage.py behave $(feature) --settings=config.settings.bdd --no-capture + docker-compose exec web python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From 28b5130749a8a5f1e8d12ce1228d139dfa67d261 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 10:51:59 +0000 Subject: [PATCH 08/29] samwip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 443cb8d52..e650d440b 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 -vv + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -v --random-order black-check: docker-compose run --rm --no-deps web black --check . From 523bfb70bd0d4f9d50c275805e76c15ca84e20d8 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 11:09:55 +0000 Subject: [PATCH 09/29] samwip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index e650d440b..d8959e520 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec web python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color + docker-compose exec web -t python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From 8bdd3e3ec8d382e1560e2ace1a59a16014696198 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 11:21:32 +0000 Subject: [PATCH 10/29] samwip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index d8959e520..a575988ea 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec web -t python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color + docker-compose exec web -T python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From 71bd7c5e6d2d2ac6d86ca7f67568c9d867273732 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 11:33:37 +0000 Subject: [PATCH 11/29] wip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index a575988ea..15f8e4cd7 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec web -T python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color + docker-compose exec -T web python manage.py behave $(feature) --settings=config.settings.bdd --no-capture --no-color elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From f48bbcff804630a729de5008e3daf9fe98862801 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 14:47:07 +0000 Subject: [PATCH 12/29] wip --- .../test/test_end_of_month_process.py | 26 +++++++------------ end_of_month/test/test_outturn_variance.py | 14 ++++------ .../test/test_end_of_month_archive_budget.py | 4 +-- .../test_end_of_month_archive_forecast.py | 4 +-- makefile | 2 +- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 65d4fbaca..7df159fd4 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -1,3 +1,4 @@ +import pytest from django.db.models import F from django.test import TestCase @@ -111,18 +112,13 @@ def test_end_of_month_mar(self): self.assertEqual(count, 129) -class ReadArchivedForecastTest(TestCase): - @classmethod - def setUpTestData(cls): - cls.archived_figure = [] - - def setUp(self): +class TestReadArchivedForecastTest: + @pytest.fixture(autouse=True) + def _setup(self): + self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() - for period in range(0, 16): - self.archived_figure.append(0) - def get_period_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter( @@ -335,16 +331,12 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) -class ReadArchivedBudgetTest(TestCase): - @classmethod - def setUpTestData(cls): - cls.archived_figure = [] - - def setUp(self): +class TestReadArchivedBudgetTest: + @pytest.fixture(autouse=True) + def _setup(self): + self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() - for period in range(0, 16): - self.archived_figure.append(0) def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 963553ea3..558503432 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -1,21 +1,17 @@ +import pytest from django.db.models import F -from django.test import TestCase from end_of_month.end_of_month_actions import end_of_month_archive from end_of_month.models import forecast_budget_view_model from end_of_month.test.test_utils import MonthlyFigureSetup -class ReadMonthlyVarianceTest(TestCase): - @classmethod - def setUpTestData(cls): - cls.archived_figure = [] - - def setUp(self): +class TestReadMonthlyVarianceTest: + @pytest.fixture(autouse=True) + def _setup(self): + self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() - for period in range(0, 16): - self.archived_figure.append(0) def get_period_total(self, period): data_model = forecast_budget_view_model[period] diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index c083826fe..cd4713bee 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -2,12 +2,12 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import ReadArchivedBudgetTest +from end_of_month.test.test_end_of_month_process import TestReadArchivedBudgetTest from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import BudgetMonthlyFigure -class ReadArchivedFutureDataForecast(ReadArchivedBudgetTest): +class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest): def setUp(self): super().setUp() current_year = get_current_financial_year() diff --git a/future_years/test/test_end_of_month_archive_forecast.py b/future_years/test/test_end_of_month_archive_forecast.py index 1f25cc0d9..671601082 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -2,12 +2,12 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import ReadArchivedForecastTest +from end_of_month.test.test_end_of_month_process import TestReadArchivedForecastTest from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import ForecastMonthlyFigure -class ReadArchivedFutureDataForecast(ReadArchivedForecastTest): +class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest, TestCase): def setUp(self): super().setUp() current_year = get_current_financial_year() diff --git a/makefile b/makefile index 15f8e4cd7..a49a52af2 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -v --random-order + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles --random-order -n 4 -v black-check: docker-compose run --rm --no-deps web black --check . From aa2987dc210830e185af19d0cbf61fee0cd5b467 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 14:54:00 +0000 Subject: [PATCH 13/29] wip --- end_of_month/test/test_end_of_month_process.py | 4 ++-- end_of_month/test/test_outturn_variance.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 7df159fd4..62ed9a8de 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -114,7 +114,7 @@ def test_end_of_month_mar(self): class TestReadArchivedForecastTest: @pytest.fixture(autouse=True) - def _setup(self): + def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() @@ -333,7 +333,7 @@ def test_end_of_month_mar(self): class TestReadArchivedBudgetTest: @pytest.fixture(autouse=True) - def _setup(self): + def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 558503432..8343f2319 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -8,7 +8,7 @@ class TestReadMonthlyVarianceTest: @pytest.fixture(autouse=True) - def _setup(self): + def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() From 90be41975b3b1328118b8b04a99096c2b64abe22 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 15:03:28 +0000 Subject: [PATCH 14/29] wip --- .../test/test_end_of_month_process.py | 23 ++++++++----------- end_of_month/test/test_outturn_variance.py | 8 +++---- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 62ed9a8de..6c8f80aae 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -150,17 +150,15 @@ def check_archive_period(self, tested_period): end_of_month_archive(tested_period) # run a query giving the full total archived_total = self.get_period_total(tested_period) - self.assertEqual(total_before, archived_total) + assert total_before == archived_total change_amount = tested_period * 10000 self.init_data.monthly_figure_update(tested_period + 1, change_amount) current_total = self.get_current_total() self.archived_figure[tested_period] = archived_total - self.assertNotEqual(current_total, archived_total) - self.assertEqual(current_total, (archived_total + change_amount)) + assert current_total != archived_total + assert current_total == (archived_total + change_amount) for period in range(1, tested_period + 1): - self.assertEqual( - self.archived_figure[period], self.get_period_total(period) - ) + assert self.archived_figure[period] == self.get_period_total(period) # The following tests check that the archived figures are not changed by # changing the current figures. @@ -351,23 +349,20 @@ def check_archive_period(self, tested_period): end_of_month_archive(tested_period) # run a query giving the full total archived_total = self.get_period_budget_total(tested_period) - self.assertEqual(total_before, archived_total) + assert total_before == archived_total change_amount = tested_period * 10000 self.init_data.monthly_figure_update(tested_period + 1, change_amount, "budget") current_total = self.get_current_budget_total() self.archived_figure[tested_period] = archived_total - self.assertNotEqual(current_total, archived_total) - self.assertNotEqual(current_total, archived_total) - self.assertEqual(current_total, (archived_total + change_amount)) + assert current_total != archived_total + assert current_total == (archived_total + change_amount) for period in range(1, tested_period + 1): # Check the full total. It is saved in a different table, for convenience monthly_budget = MonthlyTotalBudget.objects.get(archived_period=period) - self.assertEqual(self.archived_figure[period], monthly_budget.amount) + assert self.archived_figure[period], monthly_budget.amount) # Check that nothig has corrupted the archived figures - self.assertEqual( - self.archived_figure[period], self.get_period_budget_total(period) - ) + assert self.archived_figure[period] == self.get_period_budget_total(period) # The following tests check that the archived figures are not changed by # changing the current figures. diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 8343f2319..a0c5a9b0f 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -50,17 +50,17 @@ def check_archive_period(self, tested_period): end_of_month_archive(tested_period, True) # run a query giving the full total archived_total = self.get_period_total(tested_period) - self.assertEqual(total_before, archived_total) + assert total_before == archived_total previous_outurn = self.get_current_previous_outturn() - self.assertEqual(total_before, previous_outurn) + assert total_before == previous_outurn change_amount = tested_period * 10000 self.init_data.monthly_figure_update(tested_period + 1, change_amount) current_total = self.get_current_total() self.archived_figure[tested_period] = archived_total - self.assertNotEqual(current_total, previous_outurn) - self.assertEqual(current_total, (previous_outurn + change_amount)) + assert current_total != previous_outurn + assert current_total == (previous_outurn + change_amount) # The following tests check that the previous outturn figure is not changed by # changing the current figures. From d5ca279172ce34fe309243fb27106a016a0dc74f Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 15:06:51 +0000 Subject: [PATCH 15/29] wip --- end_of_month/test/test_end_of_month_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 6c8f80aae..db264d69c 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -360,7 +360,7 @@ def check_archive_period(self, tested_period): for period in range(1, tested_period + 1): # Check the full total. It is saved in a different table, for convenience monthly_budget = MonthlyTotalBudget.objects.get(archived_period=period) - assert self.archived_figure[period], monthly_budget.amount) + assert self.archived_figure[period] == monthly_budget.amount # Check that nothig has corrupted the archived figures assert self.archived_figure[period] == self.get_period_budget_total(period) From dc377dca0b2e006812ef900feefb6bd412a381be Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Fri, 22 Mar 2024 17:01:17 +0000 Subject: [PATCH 16/29] wip --- end_of_month/test/test_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/end_of_month/test/test_utils.py b/end_of_month/test/test_utils.py index 0854a2820..0c11d0337 100644 --- a/end_of_month/test/test_utils.py +++ b/end_of_month/test/test_utils.py @@ -124,9 +124,6 @@ def setup_budget(self): class SetFullYearArchive(MonthlyFigureSetup): - archived_forecast = [] - archived_budget = [] - def set_period_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.all() @@ -164,6 +161,8 @@ def set_archive_period(self, last_archived_period=13): def __init__(self, last_archived_period=16, year=0): super().__init__(year) + self.archived_forecast = [] + self.archived_budget = [] self.setup_forecast() self.setup_budget() # prepares the lists used to store the totals From 2abb68ae925513c910b9e5a46e429235118be59d Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 08:36:44 +0000 Subject: [PATCH 17/29] wip --- end_of_month/test/test_end_of_month_process.py | 8 ++++++++ future_years/test/test_end_of_month_archive_budget.py | 3 +-- future_years/test/test_end_of_month_archive_forecast.py | 5 ++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index db264d69c..3a187d4ee 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -118,6 +118,10 @@ def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() + self.post_setup() + + def post_setup(self): + pass def get_period_total(self, period): data_model = forecast_budget_view_model[period] @@ -335,6 +339,10 @@ def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() + self.post_setup() + + def post_setup(self): + pass def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index cd4713bee..c5381b3f1 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -8,8 +8,7 @@ class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest): - def setUp(self): - super().setUp() + def post_setup(self): current_year = get_current_financial_year() # Create a set of future budget data self.init_data.set_year(current_year + 2) diff --git a/future_years/test/test_end_of_month_archive_forecast.py b/future_years/test/test_end_of_month_archive_forecast.py index 671601082..9347a5b56 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -7,9 +7,8 @@ from forecast.models import ForecastMonthlyFigure -class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest, TestCase): - def setUp(self): - super().setUp() +class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest): + def _post_setup(self): current_year = get_current_financial_year() # Create a set of future forecast data self.init_data.set_year(current_year + 2) From bef708958d4f1e0f30b54b5e6453d360dcd6e5af Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 08:44:53 +0000 Subject: [PATCH 18/29] wip --- .github/workflows/ci.yml | 19 ++++++++++++++++--- .../test/test_end_of_month_process.py | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19dcd3733..f93d77a9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: node-version: 18 - uses: browser-actions/setup-chrome@v1 - + - name: Create a .env file run: cp .env.ci .env @@ -41,15 +41,28 @@ jobs: - name: Run isort run: make isort-check - + - name: Run black run: make black-check - name: Run tests run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true - name: Run BDD tests run: make bdd - name: Docker compose down - run: docker compose down \ No newline at end of file + run: docker compose down diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 3a187d4ee..ebd5fc467 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -340,7 +340,7 @@ def _setup(self, db): self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() self.post_setup() - + def post_setup(self): pass From 77bc8b98de74623041a96f192060e29039169b17 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 09:13:30 +0000 Subject: [PATCH 19/29] wip --- end_of_month/test/test_end_of_month_process.py | 9 +++++---- end_of_month/test/test_utils.py | 2 -- future_years/test/test_end_of_month_archive_budget.py | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index ebd5fc467..9d903fdcb 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -333,20 +333,21 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) +# fails class TestReadArchivedBudgetTest: @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_budget() - self.post_setup() - - def post_setup(self): - pass def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) + print("period", period) + print("data_model", data_model) + print("year_used", self.init_data.year_used) + print("tot_q", tot_q) return tot_q[0].budget def get_current_budget_total(self): diff --git a/end_of_month/test/test_utils.py b/end_of_month/test/test_utils.py index 0c11d0337..4b41966d8 100644 --- a/end_of_month/test/test_utils.py +++ b/end_of_month/test/test_utils.py @@ -107,12 +107,10 @@ def set_year(self, year): self.factor = 100000 * (self.year_used - get_current_financial_year() + 1) def setup_forecast(self): - self.value_dict = {} self.total_forecast = 0 for period in range(1, 16): amount = period * self.factor self.total_forecast += amount - self.value_dict[period] = amount self.monthly_figure_create(period, amount) def setup_budget(self): diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index c5381b3f1..ea646f65a 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -1,3 +1,4 @@ +import pytest from django.test import TestCase from core.utils.generic_helpers import get_current_financial_year @@ -7,8 +8,12 @@ from forecast.models import BudgetMonthlyFigure +# fails class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest): - def post_setup(self): + @pytest.fixture(autouse=True) + def _setup(self, db): + self.archived_figure = [0 for _ in range(16)] + self.init_data = MonthlyFigureSetup() current_year = get_current_financial_year() # Create a set of future budget data self.init_data.set_year(current_year + 2) From 389964c2929d386cf3015e625226df8b21f40d51 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 09:30:22 +0000 Subject: [PATCH 20/29] wip --- end_of_month/test/test_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/end_of_month/test/test_utils.py b/end_of_month/test/test_utils.py index 4b41966d8..0c11d0337 100644 --- a/end_of_month/test/test_utils.py +++ b/end_of_month/test/test_utils.py @@ -107,10 +107,12 @@ def set_year(self, year): self.factor = 100000 * (self.year_used - get_current_financial_year() + 1) def setup_forecast(self): + self.value_dict = {} self.total_forecast = 0 for period in range(1, 16): amount = period * self.factor self.total_forecast += amount + self.value_dict[period] = amount self.monthly_figure_create(period, amount) def setup_budget(self): From 5d6343b17002db6db2d4925b547572292af5bd1e Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 09:30:56 +0000 Subject: [PATCH 21/29] wip --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f93d77a9d..77be7123d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,22 @@ jobs: run: make pytest continue-on-error: true + - name: Run tests + run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true + + - name: Run tests + run: make pytest + continue-on-error: true + - name: Run BDD tests run: make bdd From b66c001af4bc582d880cd44a0af9d3fd8b8a14cd Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 10:07:15 +0000 Subject: [PATCH 22/29] wip --- .github/workflows/ci.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77be7123d..7bcf7c2bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,35 +47,6 @@ jobs: - name: Run tests run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - - - name: Run tests - run: make pytest - continue-on-error: true - name: Run BDD tests run: make bdd From 75f9f7f66d7eb7de17bd64f0a0b1f20549bbedde Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 11:12:16 +0000 Subject: [PATCH 23/29] wip --- end_of_month/test/test_end_of_month_process.py | 9 --------- future_years/test/test_end_of_month_archive_budget.py | 1 - future_years/test/test_end_of_month_archive_forecast.py | 6 +++++- makefile | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 9d903fdcb..db264d69c 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -118,10 +118,6 @@ def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() self.init_data.setup_forecast() - self.post_setup() - - def post_setup(self): - pass def get_period_total(self, period): data_model = forecast_budget_view_model[period] @@ -333,7 +329,6 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) -# fails class TestReadArchivedBudgetTest: @pytest.fixture(autouse=True) def _setup(self, db): @@ -344,10 +339,6 @@ def _setup(self, db): def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) - print("period", period) - print("data_model", data_model) - print("year_used", self.init_data.year_used) - print("tot_q", tot_q) return tot_q[0].budget def get_current_budget_total(self): diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index ea646f65a..0bef79678 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -8,7 +8,6 @@ from forecast.models import BudgetMonthlyFigure -# fails class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest): @pytest.fixture(autouse=True) def _setup(self, db): diff --git a/future_years/test/test_end_of_month_archive_forecast.py b/future_years/test/test_end_of_month_archive_forecast.py index 9347a5b56..0cb833a8a 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -1,3 +1,4 @@ +import pytest from django.test import TestCase from core.utils.generic_helpers import get_current_financial_year @@ -8,7 +9,10 @@ class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest): - def _post_setup(self): + @pytest.fixture(autouse=True) + def _setup(self, db): + self.archived_figure = [0 for _ in range(16)] + self.init_data = MonthlyFigureSetup() current_year = get_current_financial_year() # Create a set of future forecast data self.init_data.set_year(current_year + 2) diff --git a/makefile b/makefile index a49a52af2..9709ec9c7 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles --random-order -n 4 -v + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles --random-order -n 4 black-check: docker-compose run --rm --no-deps web black --check . From 144c1af614f17f8bfe2de95b27343c49244242b4 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 12:11:16 +0000 Subject: [PATCH 24/29] wip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 9709ec9c7..a49a52af2 100644 --- a/makefile +++ b/makefile @@ -95,7 +95,7 @@ test: docker-compose run --rm web python manage.py test $(test) pytest: - docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles --random-order -n 4 + docker-compose run --rm web pytest --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles --random-order -n 4 -v black-check: docker-compose run --rm --no-deps web black --check . From 491844c1b5dfaadf8d3f730a2bafd09840cca02b Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 12:13:01 +0000 Subject: [PATCH 25/29] wip --- .github/workflows/ci.yml | 15 +++++++++++++++ end_of_month/test/test_end_of_month_process.py | 1 + 2 files changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bcf7c2bc..059776a20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: jobs: build: runs-on: ubuntu-latest + continue-on-error: true steps: - uses: actions/checkout@v4 @@ -45,6 +46,20 @@ jobs: - name: Run black run: make black-check + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest + - name: Run tests + run: make pytest - name: Run tests run: make pytest diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index db264d69c..58bbb3054 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -339,6 +339,7 @@ def _setup(self, db): def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) + print(period, data_model, self.init_data.year_used, tot_q, tot_q.budget) return tot_q[0].budget def get_current_budget_total(self): From 09ceeee020bd6acdf87576b664e46cfaa925d5ac Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 12:19:30 +0000 Subject: [PATCH 26/29] wip --- end_of_month/test/test_end_of_month_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 58bbb3054..70109d8de 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -339,7 +339,7 @@ def _setup(self, db): def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) - print(period, data_model, self.init_data.year_used, tot_q, tot_q.budget) + print(period, data_model, self.init_data.year_used, tot_q, tot_q[0].budget) return tot_q[0].budget def get_current_budget_total(self): From 77e63fb0ec6d3c146b865c19844e0d1042478520 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 25 Mar 2024 15:36:35 +0000 Subject: [PATCH 27/29] wip --- end_of_month/test/test_end_of_month_process.py | 7 ++++--- end_of_month/test/test_outturn_variance.py | 2 +- future_years/test/test_end_of_month_archive_budget.py | 8 ++++++-- future_years/test/test_end_of_month_archive_forecast.py | 7 +++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 70109d8de..686cfbc9d 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -112,7 +112,7 @@ def test_end_of_month_mar(self): self.assertEqual(count, 129) -class TestReadArchivedForecastTest: +class TestReadArchivedForecast: @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] @@ -329,7 +329,8 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) -class TestReadArchivedBudgetTest: +# failed +class TestReadArchivedBudget: @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] @@ -362,7 +363,7 @@ def check_archive_period(self, tested_period): # Check the full total. It is saved in a different table, for convenience monthly_budget = MonthlyTotalBudget.objects.get(archived_period=period) assert self.archived_figure[period] == monthly_budget.amount - # Check that nothig has corrupted the archived figures + # Check that nothing has corrupted the archived figures assert self.archived_figure[period] == self.get_period_budget_total(period) # The following tests check that the archived figures are not changed by diff --git a/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index a0c5a9b0f..610087b37 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -6,7 +6,7 @@ from end_of_month.test.test_utils import MonthlyFigureSetup -class TestReadMonthlyVarianceTest: +class TestReadMonthlyVariance: @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index 0bef79678..2d7e2e84e 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -3,16 +3,20 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import TestReadArchivedBudgetTest +from end_of_month.test.test_end_of_month_process import ( + TestReadArchivedBudget as BaseTestReadArchivedBudget, +) from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import BudgetMonthlyFigure -class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest): +# fails +class TestReadArchivedFutureDataForecast(BaseTestReadArchivedBudget): @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() + self.init_data.setup_budget() current_year = get_current_financial_year() # Create a set of future budget data self.init_data.set_year(current_year + 2) diff --git a/future_years/test/test_end_of_month_archive_forecast.py b/future_years/test/test_end_of_month_archive_forecast.py index 0cb833a8a..fed8f1d1e 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -3,16 +3,19 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import TestReadArchivedForecastTest +from end_of_month.test.test_end_of_month_process import ( + TestReadArchivedForecast as BaseTestReadArchivedForecast, +) from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import ForecastMonthlyFigure -class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest): +class TestReadArchivedFutureDataForecast(BaseTestReadArchivedForecast): @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] self.init_data = MonthlyFigureSetup() + self.init_data.setup_forecast() current_year = get_current_financial_year() # Create a set of future forecast data self.init_data.set_year(current_year + 2) From bde05d99d3d31d208116aca007517c3392a16270 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Tue, 26 Mar 2024 10:38:55 +0000 Subject: [PATCH 28/29] wip --- end_of_month/test/test_end_of_month_process.py | 17 +++++++++-------- .../test/test_end_of_month_archive_budget.py | 7 ++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 686cfbc9d..9848a1759 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -329,14 +329,7 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) -# failed -class TestReadArchivedBudget: - @pytest.fixture(autouse=True) - def _setup(self, db): - self.archived_figure = [0 for _ in range(16)] - self.init_data = MonthlyFigureSetup() - self.init_data.setup_budget() - +class ReadArchivedBudgetTestMixin: def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) @@ -426,3 +419,11 @@ def test_read_archived_figure_mar(self): tested_period = 12 self.test_read_archived_figure_feb() self.check_archive_period(tested_period) + + +class TestReadArchivedBudget(ReadArchivedBudgetTestMixin): + @pytest.fixture(autouse=True) + def _setup(self, db): + self.archived_figure = [0 for _ in range(16)] + self.init_data = MonthlyFigureSetup() + self.init_data.setup_budget() diff --git a/future_years/test/test_end_of_month_archive_budget.py b/future_years/test/test_end_of_month_archive_budget.py index 2d7e2e84e..b93949c5c 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -3,15 +3,12 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import ( - TestReadArchivedBudget as BaseTestReadArchivedBudget, -) +from end_of_month.test.test_end_of_month_process import ReadArchivedBudgetTestMixin from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import BudgetMonthlyFigure -# fails -class TestReadArchivedFutureDataForecast(BaseTestReadArchivedBudget): +class TestReadArchivedFutureDataForecast(ReadArchivedBudgetTestMixin): @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)] From 971d6388cf9056a17aeae0848c864026441374e9 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Tue, 26 Mar 2024 10:45:36 +0000 Subject: [PATCH 29/29] wip --- .github/workflows/ci.yml | 15 --------------- end_of_month/test/test_end_of_month_process.py | 17 +++++++++-------- .../test/test_end_of_month_archive_forecast.py | 6 ++---- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 059776a20..7bcf7c2bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,6 @@ on: jobs: build: runs-on: ubuntu-latest - continue-on-error: true steps: - uses: actions/checkout@v4 @@ -46,20 +45,6 @@ jobs: - name: Run black run: make black-check - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - - name: Run tests - run: make pytest - name: Run tests run: make pytest diff --git a/end_of_month/test/test_end_of_month_process.py b/end_of_month/test/test_end_of_month_process.py index 9848a1759..8af3c485e 100644 --- a/end_of_month/test/test_end_of_month_process.py +++ b/end_of_month/test/test_end_of_month_process.py @@ -112,13 +112,7 @@ def test_end_of_month_mar(self): self.assertEqual(count, 129) -class TestReadArchivedForecast: - @pytest.fixture(autouse=True) - def _setup(self, db): - self.archived_figure = [0 for _ in range(16)] - self.init_data = MonthlyFigureSetup() - self.init_data.setup_forecast() - +class ReadArchivedForecastTestMixin: def get_period_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter( @@ -222,6 +216,14 @@ def test_read_archived_figure_mar(self): self.check_archive_period(tested_period) +class TestReadArchivedForecast(ReadArchivedForecastTestMixin): + @pytest.fixture(autouse=True) + def _setup(self, db): + self.archived_figure = [0 for _ in range(16)] + self.init_data = MonthlyFigureSetup() + self.init_data.setup_forecast() + + class EndOfMonthBudgetTest(TestCase): def setUp(self): self.init_data = MonthlyFigureSetup() @@ -333,7 +335,6 @@ class ReadArchivedBudgetTestMixin: def get_period_budget_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter(financial_year=self.init_data.year_used) - print(period, data_model, self.init_data.year_used, tot_q, tot_q[0].budget) return tot_q[0].budget def get_current_budget_total(self): diff --git a/future_years/test/test_end_of_month_archive_forecast.py b/future_years/test/test_end_of_month_archive_forecast.py index fed8f1d1e..77f8ea41a 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -3,14 +3,12 @@ from core.utils.generic_helpers import get_current_financial_year from end_of_month.end_of_month_actions import end_of_month_archive -from end_of_month.test.test_end_of_month_process import ( - TestReadArchivedForecast as BaseTestReadArchivedForecast, -) +from end_of_month.test.test_end_of_month_process import ReadArchivedForecastTestMixin from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import ForecastMonthlyFigure -class TestReadArchivedFutureDataForecast(BaseTestReadArchivedForecast): +class TestReadArchivedFutureDataForecast(ReadArchivedForecastTestMixin): @pytest.fixture(autouse=True) def _setup(self, db): self.archived_figure = [0 for _ in range(16)]