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

DWPF-1477 Migrate CI pipeline to GitHub Actions #479

Merged
merged 15 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 0 additions & 50 deletions .circleci/config.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -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=False
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This repo is maintained by the Employee Experience team
* @uktrade/employee-experience
* @uktrade/employee-experience
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
SamDudley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: FFT CI

on:
pull_request:
merge_group:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.9"

- uses: actions/setup-node@v4
with:
node-version: 18

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

- name: Build images
run: make build

- name: Run containers
run: make up-detatched

- name: Install React app
run: npm ci

- name: Collect static
run: make collectstatic

- name: Run Flake8
run: make flake8

- name: Run isort
run: make isort-check

- name: Run black
run: make black-check

- name: Run tests
run: make pytest

- name: Run BDD tests
run: make bdd

- name: 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
63 changes: 29 additions & 34 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,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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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()
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 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]
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 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)
Expand Down
12 changes: 8 additions & 4 deletions future_years/test/test_end_of_month_archive_forecast.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 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)
Expand Down
Loading