Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samwip #491

Merged
merged 29 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
node-version: 18

- uses: browser-actions/setup-chrome@v1

- name: Create a .env file
run: cp .env.ci .env

Expand All @@ -41,7 +41,7 @@ jobs:

- name: Run isort
run: make isort-check

- name: Run black
run: make black-check

Expand All @@ -52,4 +52,4 @@ jobs:
run: make bdd

- name: Docker compose down
run: docker compose down
run: docker compose down
Empty file removed config/test/__init__.py
Empty file.
18 changes: 0 additions & 18 deletions config/test/conftest.py

This file was deleted.

5 changes: 0 additions & 5 deletions core/management/commands/create_stub_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.core.management.base import BaseCommand

import core
from chartofaccountDIT.models import (
Analysis1,
Analysis2,
Expand Down Expand Up @@ -360,21 +359,17 @@ 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)
)
)

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))
)
Expand Down
52 changes: 26 additions & 26 deletions end_of_month/test/test_end_of_month_process.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.db.models import F
from django.test import TestCase

Expand Down Expand Up @@ -111,15 +112,16 @@ def test_end_of_month_mar(self):
self.assertEqual(count, 129)


class ReadArchivedForecastTest(TestCase):
archived_figure = []

def setUp(self):
class TestReadArchivedForecastTest:
@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()
self.post_setup()

for period in range(0, 16):
self.archived_figure.append(0)
def post_setup(self):
pass
SamDudley marked this conversation as resolved.
Show resolved Hide resolved

def get_period_total(self, period):
data_model = forecast_budget_view_model[period]
Expand Down Expand Up @@ -152,17 +154,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.
Expand Down Expand Up @@ -333,18 +333,21 @@ def test_end_of_month_mar(self):
self.assertEqual(budget_total_count, 12)


class ReadArchivedBudgetTest(TestCase):
archived_figure = []

def setUp(self):
# fails
SamDudley marked this conversation as resolved.
Show resolved Hide resolved
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()
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]
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)
SamDudley marked this conversation as resolved.
Show resolved Hide resolved
return tot_q[0].budget

def get_current_budget_total(self):
Expand All @@ -355,23 +358,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.
Expand Down
20 changes: 9 additions & 11 deletions end_of_month/test/test_outturn_variance.py
Original file line number Diff line number Diff line change
@@ -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 TestReadMonthlyVarianceTest:
@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]
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions end_of_month/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions future_years/test/test_end_of_month_archive_budget.py
Original file line number Diff line number Diff line change
@@ -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 TestReadArchivedBudgetTest
from end_of_month.test.test_utils import MonthlyFigureSetup
from forecast.models import BudgetMonthlyFigure


class ReadArchivedFutureDataForecast(ReadArchivedBudgetTest):
def setUp(self):
super().setUp()
# fails
SamDudley marked this conversation as resolved.
Show resolved Hide resolved
class ReadArchivedFutureDataForecast(TestReadArchivedBudgetTest):
@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)
Expand Down
7 changes: 3 additions & 4 deletions future_years/test/test_end_of_month_archive_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

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):
def setUp(self):
super().setUp()
class ReadArchivedFutureDataForecast(TestReadArchivedForecastTest):
def _post_setup(self):
SamDudley marked this conversation as resolved.
Show resolved Hide resolved
current_year = get_current_financial_year()
# Create a set of future forecast data
self.init_data.set_year(current_year + 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.core.management.base import BaseCommand

import core
from gifthospitality.models import (
GiftAndHospitalityCategory,
GiftAndHospitalityClassification,
Expand Down Expand Up @@ -264,21 +263,17 @@ 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)
)
)

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)
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
SamDudley marked this conversation as resolved.
Show resolved Hide resolved

black-check:
docker-compose run --rm --no-deps web black --check .
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down