From 033ce2df77edd03250b730126d43f822eb7c17a4 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 15 Mar 2024 13:33:45 +0000 Subject: [PATCH 01/15] added github actions --- .env.ci | 4 +++ .github/CODEOWNERS | 2 +- .github/workflows/ci.yml | 73 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.env.ci b/.env.ci index cd7345ba7..f4128172e 100644 --- a/.env.ci +++ b/.env.ci @@ -3,3 +3,7 @@ DATABASE_URL=psql://postgres:postgres@db:5432/fido FLASK_CONFIG=testing SECRET_KEY=used_for_testing ALLOWED_HOSTS="*" +AUTHBROKER_CLIENT_ID="" +AUTHBROKER_CLIENT_SECRET="" +AUTHBROKER_URL="" +DEBUG=true \ No newline at end of file diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0affcb5c3..738de65ed 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # This repo is maintained by the Employee Experience team -* @uktrade/employee-experience \ No newline at end of file +* @uktrade/employee-experience diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..665e08e2d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,73 @@ +name: FFT CI + +on: + pull_request: + merge_group: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: KengoTODA/actions-setup-docker-compose@v1 + if: ${{ env.ACT }} + name: Install `docker-compose` for local simulations + with: + version: '2.14.2' + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Create a .env file + run: cp .env.ci .env + + - name: Build images + run: make build + + - name: First use + run: make first-use + + - nmae: Run containers + run: make up-detatched + + - name: Install React app + run: npm install + + - name: Collect static + run: make collectstatic + + - name: Compile CSS + run: make compilescss + + - name: Run tests + run: make pytest + + - name: Run BDD tests + run: make bdd + + - name: Run Flake8 + run: make flake8 + + - name: Run isort + run: make isort-check + + - name: Run black + run: make black-check + + - name: Install node packages + run: npm ci + + - name: Build frontend + run: npm run build + + - name: Run checks + run: make check-ci + + - name: Docker compose down + run: docker-compose down From e9b104547e67b85f58ffb81206298b12cd7689be Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 15 Mar 2024 14:59:25 +0000 Subject: [PATCH 02/15] updated ci --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 665e08e2d..85ea7ce9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,11 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.9" - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 18 - name: Create a .env file run: cp .env.ci .env @@ -30,9 +30,6 @@ jobs: - name: Build images run: make build - - name: First use - run: make first-use - - nmae: Run containers run: make up-detatched @@ -70,4 +67,4 @@ jobs: run: make check-ci - name: Docker compose down - run: docker-compose down + run: docker-compose down \ No newline at end of file From 4356b5ecc57cb22872bf7295aa75292e0fa500d2 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 15 Mar 2024 15:03:33 +0000 Subject: [PATCH 03/15] fixed field name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85ea7ce9c..46ee0c1f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: - name: Build images run: make build - - nmae: Run containers + - name: Run containers run: make up-detatched - name: Install React app From 1c9531ac9a82b6bfba652853485a872ff4f34d3f Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 18 Mar 2024 09:49:26 +0000 Subject: [PATCH 04/15] temp disable bdd --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46ee0c1f9..58564e50c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,8 +45,8 @@ jobs: - name: Run tests run: make pytest - - name: Run BDD tests - run: make bdd + # - name: Run BDD tests + # run: make bdd - name: Run Flake8 run: make flake8 From 7c15d99f54071648d7b5057d07657831856e039f Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 18 Mar 2024 10:04:03 +0000 Subject: [PATCH 05/15] re-ordered list --- .github/workflows/ci.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58564e50c..f7295ff37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,12 +42,6 @@ jobs: - name: Compile CSS run: make compilescss - - name: Run tests - run: make pytest - - # - name: Run BDD tests - # run: make bdd - - name: Run Flake8 run: make flake8 @@ -57,14 +51,11 @@ jobs: - name: Run black run: make black-check - - name: Install node packages - run: npm ci - - - name: Build frontend - run: npm run build - - - name: Run checks - run: make check-ci + - name: Run tests + run: make pytest + # - name: Run BDD tests + # run: make bdd + - name: Docker compose down run: docker-compose down \ No newline at end of file From 265e6040480c1622d70f4d35957429430da91a17 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 18 Mar 2024 10:24:40 +0000 Subject: [PATCH 06/15] re-enabled bdd --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7295ff37..5064db9c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,8 +54,8 @@ jobs: - name: Run tests run: make pytest - # - name: Run BDD tests - # run: make bdd - + - name: Run BDD tests + run: make bdd + - name: Docker compose down run: docker-compose down \ No newline at end of file From 96270bbe692f0c3ed0d30b03a75dd490cf4b2dd5 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 19 Mar 2024 11:20:34 +0000 Subject: [PATCH 07/15] changes --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5064db9c0..41cbd9ea5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: name: Install `docker-compose` for local simulations with: version: '2.14.2' + - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -23,7 +24,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 18 - + - name: Create a .env file run: cp .env.ci .env From 157b75d6830878df50c3dde5c4855fa53c58d05b Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 21 Mar 2024 09:41:31 +0000 Subject: [PATCH 08/15] updated with main, & changes --- .env.ci | 2 +- .github/workflows/ci.yml | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.env.ci b/.env.ci index f4128172e..819399bd8 100644 --- a/.env.ci +++ b/.env.ci @@ -6,4 +6,4 @@ ALLOWED_HOSTS="*" AUTHBROKER_CLIENT_ID="" AUTHBROKER_CLIENT_SECRET="" AUTHBROKER_URL="" -DEBUG=true \ No newline at end of file +DEBUG=false \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41cbd9ea5..1b22999f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,12 +9,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: KengoTODA/actions-setup-docker-compose@v1 - if: ${{ env.ACT }} - name: Install `docker-compose` for local simulations - with: - version: '2.14.2' - - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -35,14 +29,11 @@ jobs: run: make up-detatched - name: Install React app - run: npm install + run: npm ci - name: Collect static run: make collectstatic - - name: Compile CSS - run: make compilescss - - name: Run Flake8 run: make flake8 @@ -59,4 +50,4 @@ jobs: run: make bdd - name: Docker compose down - run: docker-compose down \ No newline at end of file + run: docker compose down \ No newline at end of file From 1c0b30071a9ff306bd9a02f819e342db0b7b225e Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 21 Mar 2024 10:37:35 +0000 Subject: [PATCH 09/15] added -t flag --- .github/workflows/ci.yml | 2 ++ makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b22999f1..19dcd3733 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,8 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 18 + + - uses: browser-actions/setup-chrome@v1 - name: Create a .env file run: cp .env.ci .env diff --git a/makefile b/makefile index 0e4232423..0a3736c23 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec web sh -c "python manage.py behave $(feature) --settings=config.settings.bdd --no-capture" + docker-compose exec -t web sh -c "python manage.py behave $(feature) --settings=config.settings.bdd --no-capture" elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From 0db3d776c5cbe235664190668c374b5a2d6f5180 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 21 Mar 2024 11:28:47 +0000 Subject: [PATCH 10/15] test --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 0a3736c23..489e6989f 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 -raP --capture=sys --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles black-check: docker-compose run --rm --no-deps web black --check . From aeb4db39c53872944e1dc2cc0add911a3350b2fb Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 21 Mar 2024 11:41:59 +0000 Subject: [PATCH 11/15] revert --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 489e6989f..0a3736c23 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 + docker-compose run --rm web pytest -raP --capture=sys --ignore=node_modules --ignore=front_end --ignore=features --ignore=staticfiles -n 4 black-check: docker-compose run --rm --no-deps web black --check . From 0c0b24ab1eed495780f01c4a86ff415511f3a6ca Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 21 Mar 2024 13:52:50 +0000 Subject: [PATCH 12/15] changes --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 0a3736c23..fefcbf811 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec -t web sh -c "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 elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions From 7a4b575048458adc8722d0b9486ac231945f8fe0 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Tue, 26 Mar 2024 10:55:53 +0000 Subject: [PATCH 13/15] possibly fix flaky tests (#491) --- .github/workflows/ci.yml | 6 +- config/test/__init__.py | 0 config/test/conftest.py | 18 ------ core/management/commands/create_stub_data.py | 5 -- .../test/test_end_of_month_process.py | 63 +++++++++---------- end_of_month/test/test_outturn_variance.py | 20 +++--- end_of_month/test/test_utils.py | 5 +- .../test/test_end_of_month_archive_budget.py | 12 ++-- .../test_end_of_month_archive_forecast.py | 12 ++-- .../populate_gift_hospitality_table.py | 5 -- makefile | 4 +- poetry.lock | 16 ++++- pyproject.toml | 1 + 13 files changed, 77 insertions(+), 90 deletions(-) delete mode 100644 config/test/__init__.py delete mode 100644 config/test/conftest.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19dcd3733..7bcf7c2bc 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,7 +41,7 @@ jobs: - name: Run isort run: make isort-check - + - name: Run black run: make black-check @@ -52,4 +52,4 @@ jobs: run: make bdd - name: Docker compose down - run: docker compose down \ No newline at end of file + run: docker compose down 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..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, @@ -360,10 +359,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 +368,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 3ed71ad51..8af3c485e 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,16 +112,7 @@ def test_end_of_month_mar(self): self.assertEqual(count, 129) -class ReadArchivedForecastTest(TestCase): - archived_figure = [] - - def setUp(self): - self.init_data = MonthlyFigureSetup() - self.init_data.setup_forecast() - - for period in range(0, 16): - self.archived_figure.append(0) - +class ReadArchivedForecastTestMixin: def get_period_total(self, period): data_model = forecast_budget_view_model[period] tot_q = data_model.objects.filter( @@ -152,17 +144,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. @@ -226,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,15 +331,7 @@ def test_end_of_month_mar(self): self.assertEqual(budget_total_count, 12) -class ReadArchivedBudgetTest(TestCase): - archived_figure = [] - - def setUp(self): - self.init_data = MonthlyFigureSetup() - self.init_data.setup_budget() - for period in range(0, 16): - self.archived_figure.append(0) - +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) @@ -355,23 +345,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) - # 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] == monthly_budget.amount + # 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 # changing the current figures. @@ -433,3 +420,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/end_of_month/test/test_outturn_variance.py b/end_of_month/test/test_outturn_variance.py index 7b2dad2f0..610087b37 100644 --- a/end_of_month/test/test_outturn_variance.py +++ b/end_of_month/test/test_outturn_variance.py @@ -1,19 +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): - archived_figure = [] - - def setUp(self): +class TestReadMonthlyVariance: + @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() - for period in range(0, 16): - self.archived_figure.append(0) def get_period_total(self, period): data_model = forecast_budget_view_model[period] @@ -52,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. 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 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..b93949c5c 100644 --- a/future_years/test/test_end_of_month_archive_budget.py +++ b/future_years/test/test_end_of_month_archive_budget.py @@ -1,15 +1,19 @@ +import pytest from django.test import TestCase 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 ReadArchivedBudgetTestMixin from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import BudgetMonthlyFigure -class ReadArchivedFutureDataForecast(ReadArchivedBudgetTest): - def setUp(self): - super().setUp() +class TestReadArchivedFutureDataForecast(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() 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 1f25cc0d9..77f8ea41a 100644 --- a/future_years/test/test_end_of_month_archive_forecast.py +++ b/future_years/test/test_end_of_month_archive_forecast.py @@ -1,15 +1,19 @@ +import pytest from django.test import TestCase 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 ReadArchivedForecastTestMixin from end_of_month.test.test_utils import MonthlyFigureSetup from forecast.models import ForecastMonthlyFigure -class ReadArchivedFutureDataForecast(ReadArchivedForecastTest): - def setUp(self): - super().setUp() +class TestReadArchivedFutureDataForecast(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() current_year = get_current_financial_year() # Create a set of future forecast data self.init_data.set_year(current_year + 2) diff --git a/gifthospitality/management/commands/populate_gift_hospitality_table.py b/gifthospitality/management/commands/populate_gift_hospitality_table.py index 58b0f10cd..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, @@ -264,10 +263,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 +272,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/makefile b/makefile index fefcbf811..a49a52af2 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 -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 @@ -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 --random-order -n 4 -v black-check: docker-compose run --rm --no-deps web black --check . 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 f51549ec24a2ee535ea9db92c0e75d5d5014442b Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Tue, 26 Mar 2024 11:39:08 +0000 Subject: [PATCH 14/15] wip --- .circleci/config.yml | 50 ---------------------------------------- .env.ci | 8 +++---- .github/workflows/ci.yml | 2 -- 3 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 87a93fef6..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,50 +0,0 @@ -version: 2.1 - -orbs: - browser-tools: circleci/browser-tools@1.4.8 -jobs: - build: - machine: - image: ubuntu-2204:2023.04.2 - docker_layer_caching: true - - steps: - - checkout - - run: mkdir test-reports - - run: cp .env.ci .env - - run: - name: Build images - command: make build - - run: - name: Run containers - command: make up-detatched - - run: - name: Install npm packages - command: npm ci - - run: - name: Run postinstall script - command: npm run postinstall - - run: - name: Collect static - command: make collectstatic - - run: - name: Run Flake8 - command: make flake8 - - run: - name: Run isort - command: make isort-check - - run: - name: Run black - command: make black-check - - run: - name: Run tests - command: make pytest - - run: - name: Run BDD tests - command: make bdd - - - store_artifacts: - path: test-reports/ - destination: tr1 - - store_test_results: - path: test-reports/ diff --git a/.env.ci b/.env.ci index 819399bd8..761b61594 100644 --- a/.env.ci +++ b/.env.ci @@ -3,7 +3,7 @@ DATABASE_URL=psql://postgres:postgres@db:5432/fido FLASK_CONFIG=testing SECRET_KEY=used_for_testing ALLOWED_HOSTS="*" -AUTHBROKER_CLIENT_ID="" -AUTHBROKER_CLIENT_SECRET="" -AUTHBROKER_URL="" -DEBUG=false \ No newline at end of file +AUTHBROKER_CLIENT_ID= +AUTHBROKER_CLIENT_SECRET= +AUTHBROKER_URL= +DEBUG=False diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bcf7c2bc..d9cef327f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,6 @@ jobs: with: node-version: 18 - - uses: browser-actions/setup-chrome@v1 - - name: Create a .env file run: cp .env.ci .env From 4893a599fd2f19332fceaeead629a54e63405af2 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Tue, 26 Mar 2024 11:58:22 +0000 Subject: [PATCH 15/15] wip --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index a49a52af2..e05019d12 100644 --- a/makefile +++ b/makefile @@ -77,7 +77,7 @@ flake8: docker-compose run --rm web flake8 $(file) bdd: - docker-compose exec -T web 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 elevate: docker-compose run --rm web python manage.py elevate_sso_user_permissions