From c8eef941ac9037c425d27329b3a4c4fe5b5234db Mon Sep 17 00:00:00 2001 From: Alex Coleman Date: Mon, 8 Apr 2024 15:48:51 +0100 Subject: [PATCH] GH-100: Make funding programme mandatory --- schemes/domain/schemes/schemes.py | 4 +- schemes/infrastructure/database/__init__.py | 2 +- ...pital_scheme_funding_programme_nullable.py | 26 +++++++ .../database/schemes/schemes.py | 10 +-- schemes/views/schemes/schemes.py | 21 +++--- schemes/views/templates/scheme/_overview.html | 2 +- schemes/views/templates/schemes.html | 2 +- tests/builders.py | 12 +++- tests/domain/schemes/test_schemes.py | 67 ++++++++++++++----- tests/e2e/builders.py | 2 +- .../database/schemes/test_schemes.py | 39 +++++++++-- tests/integration/test_authorities.py | 19 ++++-- tests/integration/test_scheme.py | 12 +++- tests/integration/test_scheme_overview.py | 21 ++++-- tests/integration/test_schemes.py | 9 +-- tests/views/schemes/test_schemes.py | 45 +++++-------- 16 files changed, 204 insertions(+), 89 deletions(-) create mode 100644 schemes/infrastructure/database/migrations/versions/8e77c6c5b1b8_alter_capital_scheme_funding_programme_nullable.py diff --git a/schemes/domain/schemes/schemes.py b/schemes/domain/schemes/schemes.py index c7c12f98..a4be678a 100644 --- a/schemes/domain/schemes/schemes.py +++ b/schemes/domain/schemes/schemes.py @@ -10,12 +10,12 @@ class Scheme: - def __init__(self, id_: int, name: str, authority_id: int, type_: SchemeType): + def __init__(self, id_: int, name: str, authority_id: int, type_: SchemeType, funding_programme: FundingProgramme): self.id = id_ self.name = name self.authority_id = authority_id self.type = type_ - self.funding_programme: FundingProgramme | None = None + self.funding_programme = funding_programme self._funding = SchemeFunding() self._milestones = SchemeMilestones() self._outputs = SchemeOutputs() diff --git a/schemes/infrastructure/database/__init__.py b/schemes/infrastructure/database/__init__.py index f276ecb8..9b2aa21d 100644 --- a/schemes/infrastructure/database/__init__.py +++ b/schemes/infrastructure/database/__init__.py @@ -40,7 +40,7 @@ class CapitalSchemeEntity(Base): nullable=False, ) scheme_type_id: Mapped[int] - funding_programme_id: Mapped[int | None] + funding_programme_id: Mapped[int] capital_scheme_bid_statuses: Mapped[list[CapitalSchemeBidStatusEntity]] = relationship() capital_scheme_financials: Mapped[list[CapitalSchemeFinancialEntity]] = relationship() capital_scheme_milestones: Mapped[list[CapitalSchemeMilestoneEntity]] = relationship() diff --git a/schemes/infrastructure/database/migrations/versions/8e77c6c5b1b8_alter_capital_scheme_funding_programme_nullable.py b/schemes/infrastructure/database/migrations/versions/8e77c6c5b1b8_alter_capital_scheme_funding_programme_nullable.py new file mode 100644 index 00000000..7aa6bd7b --- /dev/null +++ b/schemes/infrastructure/database/migrations/versions/8e77c6c5b1b8_alter_capital_scheme_funding_programme_nullable.py @@ -0,0 +1,26 @@ +"""Alter capital scheme funding programme nullable + +Revision ID: 8e77c6c5b1b8 +Revises: 911e18fe1942 +Create Date: 2024-04-08 15:08:19.373194 + +""" + +from typing import Sequence, Union + +from alembic import op + +revision: str = "8e77c6c5b1b8" +down_revision: Union[str, None] = "911e18fe1942" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + with op.batch_alter_table("capital_scheme", schema="capital_scheme") as batch_op: + batch_op.alter_column("funding_programme_id", nullable=False) + + +def downgrade() -> None: + with op.batch_alter_table("capital_scheme", schema="capital_scheme") as batch_op: + batch_op.alter_column("funding_programme_id", nullable=True) diff --git a/schemes/infrastructure/database/schemes/schemes.py b/schemes/infrastructure/database/schemes/schemes.py index 4bdb28bb..29671671 100644 --- a/schemes/infrastructure/database/schemes/schemes.py +++ b/schemes/infrastructure/database/schemes/schemes.py @@ -122,8 +122,8 @@ def _capital_scheme_to_domain(self, capital_scheme: CapitalSchemeEntity) -> Sche name=capital_scheme.scheme_name, authority_id=capital_scheme.bid_submitting_authority_id, type_=self._scheme_type_mapper.to_domain(capital_scheme.scheme_type_id), + funding_programme=self._funding_programme_mapper.to_domain(capital_scheme.funding_programme_id), ) - scheme.funding_programme = self._funding_programme_mapper.to_domain(capital_scheme.funding_programme_id) for capital_scheme_bid_status in capital_scheme.capital_scheme_bid_statuses: scheme.funding.update_bid_status(self._capital_scheme_bid_status_to_domain(capital_scheme_bid_status)) @@ -288,8 +288,8 @@ class FundingProgrammeMapper: FundingProgrammes.CRSTS: 8, } - def to_id(self, funding_programme: FundingProgramme | None) -> int | None: - return self._IDS[funding_programme] if funding_programme else None + def to_id(self, funding_programme: FundingProgramme) -> int: + return self._IDS[funding_programme] - def to_domain(self, id_: int | None) -> FundingProgramme | None: - return inverse_dict(self._IDS)[id_] if id_ else None + def to_domain(self, id_: int) -> FundingProgramme: + return inverse_dict(self._IDS)[id_] diff --git a/schemes/views/schemes/schemes.py b/schemes/views/schemes/schemes.py index 01daeb3a..3559b62b 100644 --- a/schemes/views/schemes/schemes.py +++ b/schemes/views/schemes/schemes.py @@ -226,7 +226,7 @@ def from_domain(cls, type_: SchemeType) -> SchemeTypeContext: @dataclass(frozen=True) class FundingProgrammeContext: - name: str | None + name: str _NAMES = { FundingProgrammes.ATF2: "ATF2", FundingProgrammes.ATF3: "ATF3", @@ -239,8 +239,8 @@ class FundingProgrammeContext: } @classmethod - def from_domain(cls, funding_programme: FundingProgramme | None) -> FundingProgrammeContext: - return cls(name=cls._NAMES[funding_programme] if funding_programme else None) + def from_domain(cls, funding_programme: FundingProgramme) -> FundingProgrammeContext: + return cls(name=cls._NAMES[funding_programme]) @bp.get("/spend-to-date") @@ -375,7 +375,7 @@ class SchemeRepr: id: int name: str type: SchemeTypeRepr - funding_programme: FundingProgrammeRepr | None = None + funding_programme: FundingProgrammeRepr bid_status_revisions: list[BidStatusRevisionRepr] = field(default_factory=list) financial_revisions: list[FinancialRevisionRepr] = field(default_factory=list) milestone_revisions: list[MilestoneRevisionRepr] = field(default_factory=list) @@ -388,9 +388,7 @@ def from_domain(cls, scheme: Scheme) -> SchemeRepr: id=scheme.id, name=scheme.name, type=SchemeTypeRepr.from_domain(scheme.type), - funding_programme=( - FundingProgrammeRepr.from_domain(scheme.funding_programme) if scheme.funding_programme else None - ), + funding_programme=FundingProgrammeRepr.from_domain(scheme.funding_programme), bid_status_revisions=[ BidStatusRevisionRepr.from_domain(bid_status_revision) for bid_status_revision in scheme.funding.bid_status_revisions @@ -413,8 +411,13 @@ def from_domain(cls, scheme: Scheme) -> SchemeRepr: ) def to_domain(self, authority_id: int) -> Scheme: - scheme = Scheme(id_=self.id, name=self.name, authority_id=authority_id, type_=self.type.to_domain()) - scheme.funding_programme = self.funding_programme.to_domain() if self.funding_programme else None + scheme = Scheme( + id_=self.id, + name=self.name, + authority_id=authority_id, + type_=self.type.to_domain(), + funding_programme=self.funding_programme.to_domain(), + ) for bid_status_revision_repr in self.bid_status_revisions: scheme.funding.update_bid_status(bid_status_revision_repr.to_domain()) diff --git a/schemes/views/templates/scheme/_overview.html b/schemes/views/templates/scheme/_overview.html index a36ef9ff..7685fabb 100644 --- a/schemes/views/templates/scheme/_overview.html +++ b/schemes/views/templates/scheme/_overview.html @@ -28,7 +28,7 @@ "text": "Funding programme" }, "value": { - "text": overview.funding_programme.name | d("", true) + "text": overview.funding_programme.name } }, { diff --git a/schemes/views/templates/schemes.html b/schemes/views/templates/schemes.html index 702d862c..9042bef5 100644 --- a/schemes/views/templates/schemes.html +++ b/schemes/views/templates/schemes.html @@ -54,7 +54,7 @@

"html": referenceHtml }, { - "text": scheme.funding_programme.name | d("", true) + "text": scheme.funding_programme.name }, { "html": nameHtml diff --git a/tests/builders.py b/tests/builders.py index d7c1bf01..14630b96 100644 --- a/tests/builders.py +++ b/tests/builders.py @@ -1,7 +1,14 @@ from datetime import datetime from schemes.domain.dates import DateRange -from schemes.domain.schemes import BidStatus, BidStatusRevision, Scheme, SchemeType +from schemes.domain.schemes import ( + BidStatus, + BidStatusRevision, + FundingProgramme, + FundingProgrammes, + Scheme, + SchemeType, +) def build_scheme( @@ -9,6 +16,7 @@ def build_scheme( name: str, authority_id: int, type_: SchemeType = SchemeType.CONSTRUCTION, + funding_programme: FundingProgramme = FundingProgrammes.ATF2, bid_status: BidStatus = BidStatus.FUNDED, bid_status_revisions: list[BidStatusRevision] | None = None, ) -> Scheme: @@ -18,6 +26,6 @@ def build_scheme( else [BidStatusRevision(id_=None, effective=DateRange(datetime.min, None), status=bid_status)] ) - scheme = Scheme(id_, name, authority_id, type_) + scheme = Scheme(id_, name, authority_id, type_, funding_programme) scheme.funding.update_bid_statuses(*bid_status_revisions) return scheme diff --git a/tests/domain/schemes/test_schemes.py b/tests/domain/schemes/test_schemes.py index 4c1fc4b4..03cd1248 100644 --- a/tests/domain/schemes/test_schemes.py +++ b/tests/domain/schemes/test_schemes.py @@ -23,14 +23,20 @@ class TestScheme: def test_create(self) -> None: - scheme = Scheme(id_=1, name="Wirral Package", authority_id=2, type_=SchemeType.CONSTRUCTION) + scheme = Scheme( + id_=1, + name="Wirral Package", + authority_id=2, + type_=SchemeType.CONSTRUCTION, + funding_programme=FundingProgrammes.ATF4, + ) assert ( scheme.id == 1 and scheme.name == "Wirral Package" and scheme.authority_id == 2 and scheme.type == SchemeType.CONSTRUCTION - and scheme.funding_programme is None + and scheme.funding_programme == FundingProgrammes.ATF4 ) def test_get_reference(self) -> None: @@ -69,8 +75,13 @@ def test_get_reviews(self) -> None: ], ) def test_is_updateable_when_funded(self, bid_status: BidStatus, expected_updateable: bool) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status=bid_status) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=FundingProgrammes.ATF4, + bid_status=bid_status, + ) scheme.milestones.update_milestone( MilestoneRevision( id_=3, @@ -93,8 +104,13 @@ def test_is_updateable_when_funded(self, bid_status: BidStatus, expected_updatea ], ) def test_is_updateable_when_active_and_incomplete(self, milestone: Milestone, expected_updateable: bool) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status=BidStatus.FUNDED) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=FundingProgrammes.ATF4, + bid_status=BidStatus.FUNDED, + ) scheme.milestones.update_milestone( MilestoneRevision( id_=3, @@ -111,16 +127,20 @@ def test_is_updateable_when_active_and_incomplete(self, milestone: Milestone, ex @pytest.mark.parametrize( "funding_programme, expected_updateable", [ - (None, True), (FundingProgrammes.ATF4, True), (FundingProgramme("ATF100", True), False), ], ) def test_is_updateable_when_not_under_embargo( - self, funding_programme: FundingProgramme | None, expected_updateable: bool + self, funding_programme: FundingProgramme, expected_updateable: bool ) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status=BidStatus.FUNDED) - scheme.funding_programme = funding_programme + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=funding_programme, + bid_status=BidStatus.FUNDED, + ) scheme.milestones.update_milestone( MilestoneRevision( id_=3, @@ -135,8 +155,13 @@ def test_is_updateable_when_not_under_embargo( assert scheme.is_updateable == expected_updateable def test_is_updateable_when_no_bid_status_revision(self) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status_revisions=[]) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=FundingProgrammes.ATF4, + bid_status_revisions=[], + ) scheme.milestones.update_milestone( MilestoneRevision( id_=3, @@ -151,14 +176,24 @@ def test_is_updateable_when_no_bid_status_revision(self) -> None: assert scheme.is_updateable is False def test_is_updateable_when_no_milestone_revision(self) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status=BidStatus.FUNDED) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=FundingProgrammes.ATF4, + bid_status=BidStatus.FUNDED, + ) assert scheme.is_updateable is True def test_is_updateable_uses_latest_milestone_revision(self) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=2, bid_status=BidStatus.FUNDED) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=2, + funding_programme=FundingProgrammes.ATF4, + bid_status=BidStatus.FUNDED, + ) scheme.milestones.update_milestones( MilestoneRevision( id_=3, diff --git a/tests/e2e/builders.py b/tests/e2e/builders.py index 52909be0..4cd60201 100644 --- a/tests/e2e/builders.py +++ b/tests/e2e/builders.py @@ -12,7 +12,7 @@ def build_scheme( id_: int, name: str, type_: str = "construction", - funding_programme: str | None = None, + funding_programme: str = "ATF2", bid_status: str = "funded", financial_revisions: list[FinancialRevisionRepr] | None = None, milestone_revisions: list[MilestoneRevisionRepr] | None = None, diff --git a/tests/infrastructure/database/schemes/test_schemes.py b/tests/infrastructure/database/schemes/test_schemes.py index c58a56a2..deb322ea 100644 --- a/tests/infrastructure/database/schemes/test_schemes.py +++ b/tests/infrastructure/database/schemes/test_schemes.py @@ -60,8 +60,13 @@ def authority_fixture(self, authorities: DatabaseAuthorityRepository) -> None: ) def test_add_schemes(self, schemes: DatabaseSchemeRepository, engine: Engine) -> None: - scheme1 = Scheme(id_=1, name="Wirral Package", authority_id=1, type_=SchemeType.DEVELOPMENT) - scheme1.funding_programme = FundingProgrammes.ATF3 + scheme1 = Scheme( + id_=1, + name="Wirral Package", + authority_id=1, + type_=SchemeType.DEVELOPMENT, + funding_programme=FundingProgrammes.ATF3, + ) schemes.add(scheme1, build_scheme(id_=2, name="School Streets", authority_id=1)) @@ -325,6 +330,7 @@ def test_get_scheme_bid_status_revisions(self, schemes: DatabaseSchemeRepository scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeBidStatusEntity( capital_scheme_bid_status_id=2, @@ -370,6 +376,7 @@ def test_get_scheme_financial_revisions(self, schemes: DatabaseSchemeRepository, scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeFinancialEntity( capital_scheme_financial_id=2, @@ -423,6 +430,7 @@ def test_get_scheme_milestone_revisions(self, schemes: DatabaseSchemeRepository, scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeMilestoneEntity( capital_scheme_milestone_id=2, @@ -480,6 +488,7 @@ def test_get_scheme_output_revisions(self, schemes: DatabaseSchemeRepository, en scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeInterventionEntity( capital_scheme_intervention_id=2, @@ -533,6 +542,7 @@ def test_get_scheme_authority_reviews(self, schemes: DatabaseSchemeRepository, e scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeAuthorityReviewEntity( capital_scheme_authority_review_id=2, @@ -575,6 +585,7 @@ def test_get_scheme_that_does_not_exist(self, schemes: DatabaseSchemeRepository, scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ) ) session.commit() @@ -597,12 +608,14 @@ def test_get_all_schemes_by_authority(self, schemes: DatabaseSchemeRepository, e scheme_name="School Streets", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeEntity( capital_scheme_id=3, scheme_name="Hospital Fields Road", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), ] ) @@ -632,6 +645,7 @@ def test_get_all_schemes_bid_status_revisions_by_authority( scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeBidStatusEntity( capital_scheme_bid_status_id=3, @@ -645,6 +659,7 @@ def test_get_all_schemes_bid_status_revisions_by_authority( scheme_name="School Streets", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeBidStatusEntity( capital_scheme_bid_status_id=4, @@ -680,6 +695,7 @@ def test_get_all_schemes_financial_revisions_by_authority( scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeFinancialEntity( capital_scheme_financial_id=3, @@ -695,6 +711,7 @@ def test_get_all_schemes_financial_revisions_by_authority( scheme_name="School Streets", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeFinancialEntity( capital_scheme_financial_id=4, @@ -734,6 +751,7 @@ def test_get_all_schemes_milestone_revisions_by_authority( scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeMilestoneEntity( capital_scheme_milestone_id=4, @@ -750,6 +768,7 @@ def test_get_all_schemes_milestone_revisions_by_authority( scheme_name="School Streets", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeMilestoneEntity( capital_scheme_milestone_id=5, @@ -766,6 +785,7 @@ def test_get_all_schemes_milestone_revisions_by_authority( scheme_name="Hospital Fields Road", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeMilestoneEntity( capital_scheme_milestone_id=6, @@ -819,6 +839,7 @@ def test_get_all_schemes_output_revisions_by_authority( scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeInterventionEntity( capital_scheme_intervention_id=4, @@ -834,6 +855,7 @@ def test_get_all_schemes_output_revisions_by_authority( scheme_name="School Streets", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeInterventionEntity( capital_scheme_intervention_id=5, @@ -849,6 +871,7 @@ def test_get_all_schemes_output_revisions_by_authority( scheme_name="Hospital Fields Road", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeInterventionEntity( capital_scheme_intervention_id=6, @@ -899,6 +922,7 @@ def test_get_all_schemes_authority_reviews_by_authority( scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeAuthorityReviewEntity( capital_scheme_authority_review_id=2, @@ -911,6 +935,7 @@ def test_get_all_schemes_authority_reviews_by_authority( scheme_name="School Streets", bid_submitting_authority_id=2, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeAuthorityReviewEntity( capital_scheme_authority_review_id=3, @@ -943,6 +968,7 @@ def test_clear_all_schemes(self, schemes: DatabaseSchemeRepository, engine: Engi scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeBidStatusEntity( capital_scheme_id=1, @@ -983,6 +1009,7 @@ def test_clear_all_schemes(self, schemes: DatabaseSchemeRepository, engine: Engi scheme_name="School Streets", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), ] ) @@ -1002,6 +1029,7 @@ def test_update_scheme_financial_revisions(self, schemes: DatabaseSchemeReposito scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeFinancialEntity( capital_scheme_financial_id=2, @@ -1058,6 +1086,7 @@ def test_update_scheme_milestone_revisions(self, schemes: DatabaseSchemeReposito scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeMilestoneEntity( capital_scheme_milestone_id=2, @@ -1117,6 +1146,7 @@ def test_update_scheme_authority_reviews(self, schemes: DatabaseSchemeRepository scheme_name="Wirral Package", bid_submitting_authority_id=1, scheme_type_id=2, + funding_programme_id=3, ), CapitalSchemeAuthorityReviewEntity( capital_scheme_authority_review_id=2, @@ -1168,12 +1198,11 @@ def test_to_domain(self, type_: SchemeType, id_: int) -> None: (FundingProgrammes.MRN, 6), (FundingProgrammes.LUF, 7), (FundingProgrammes.CRSTS, 8), - (None, None), ], ) class TestFundingProgrammeMapper: - def test_to_id(self, funding_programme: FundingProgramme | None, id_: int | None) -> None: + def test_to_id(self, funding_programme: FundingProgramme, id_: int) -> None: assert FundingProgrammeMapper().to_id(funding_programme) == id_ - def test_to_domain(self, funding_programme: FundingProgramme | None, id_: int | None) -> None: + def test_to_domain(self, funding_programme: FundingProgramme, id_: int) -> None: assert FundingProgrammeMapper().to_domain(id_) == funding_programme diff --git a/tests/integration/test_authorities.py b/tests/integration/test_authorities.py index 95d67634..99f1136e 100644 --- a/tests/integration/test_authorities.py +++ b/tests/integration/test_authorities.py @@ -122,7 +122,7 @@ def test_add_schemes(self, schemes: SchemeRepository, client: FlaskClient) -> No headers={"Authorization": "API-Key boardman"}, json=[ {"id": 1, "name": "Wirral Package", "type": "construction", "funding_programme": "ATF4"}, - {"id": 2, "name": "School Streets", "type": "construction"}, + {"id": 2, "name": "School Streets", "type": "construction", "funding_programme": "ATF4"}, ], ) @@ -143,6 +143,7 @@ def test_add_schemes(self, schemes: SchemeRepository, client: FlaskClient) -> No and scheme2.name == "School Streets" and scheme2.authority_id == 1 and scheme2.type == SchemeType.CONSTRUCTION + and scheme2.funding_programme == FundingProgrammes.ATF4 ) def test_add_schemes_bid_status_revisions(self, schemes: SchemeRepository, client: FlaskClient) -> None: @@ -154,6 +155,7 @@ def test_add_schemes_bid_status_revisions(self, schemes: SchemeRepository, clien "id": 1, "name": "Wirral Package", "type": "construction", + "funding_programme": "ATF4", "bid_status_revisions": [ { "id": 2, @@ -186,6 +188,7 @@ def test_add_schemes_financial_revisions(self, schemes: SchemeRepository, client "id": 1, "name": "Wirral Package", "type": "construction", + "funding_programme": "ATF4", "financial_revisions": [ { "id": 2, @@ -222,6 +225,7 @@ def test_add_schemes_milestone_revisions(self, schemes: SchemeRepository, client "id": 1, "name": "Wirral Package", "type": "construction", + "funding_programme": "ATF4", "milestone_revisions": [ { "id": 2, @@ -260,6 +264,7 @@ def test_add_schemes_output_revisions(self, schemes: SchemeRepository, client: F "id": 1, "name": "Wirral Package", "type": "construction", + "funding_programme": "ATF4", "output_revisions": [ { "id": 2, @@ -297,6 +302,7 @@ def test_add_schemes_authority_reviews(self, schemes: SchemeRepository, client: "id": 1, "name": "Wirral Package", "type": "construction", + "funding_programme": "ATF4", "authority_reviews": [ { "id": 2, @@ -321,7 +327,8 @@ def test_add_schemes_authority_reviews(self, schemes: SchemeRepository, client: def test_cannot_add_schemes_when_no_credentials(self, schemes: SchemeRepository, client: FlaskClient) -> None: response = client.post( - "/authorities/1/schemes", json=[{"id": 1, "name": "Wirral Package", "type": "construction"}] + "/authorities/1/schemes", + json=[{"id": 1, "name": "Wirral Package", "type": "construction", "funding_programme": "ATF4"}], ) assert response.status_code == 401 @@ -333,7 +340,7 @@ def test_cannot_add_schemes_when_incorrect_credentials( response = client.post( "/authorities/1/schemes", headers={"Authorization": "API-Key obree"}, - json=[{"id": 1, "name": "Wirral Package", "type": "construction"}], + json=[{"id": 1, "name": "Wirral Package", "type": "construction", "funding_programme": "ATF4"}], ) assert response.status_code == 401 @@ -343,7 +350,9 @@ def test_cannot_add_schemes_with_invalid_repr(self, schemes: SchemeRepository, c response = client.post( "/authorities/1/schemes", headers={"Authorization": "API-Key boardman"}, - json=[{"id": 1, "name": "Wirral Package", "type": "construction", "foo": "bar"}], + json=[ + {"id": 1, "name": "Wirral Package", "type": "construction", "funding_programme": "ATF4", "foo": "bar"} + ], ) assert response.status_code == 400 @@ -403,7 +412,7 @@ def test_cannot_add_schemes(self, schemes: SchemeRepository, client: FlaskClient response = client.post( "/authorities/1/schemes", headers={"Authorization": "API-Key boardman"}, - json=[{"id": 1, "name": "Wirral Package", "type": "construction"}], + json=[{"id": 1, "name": "Wirral Package", "type": "construction", "funding_programme": "ATF4"}], ) assert response.status_code == 401 diff --git a/tests/integration/test_scheme.py b/tests/integration/test_scheme.py index eef3e815..6f319511 100644 --- a/tests/integration/test_scheme.py +++ b/tests/integration/test_scheme.py @@ -124,9 +124,15 @@ def config_fixture(self, config: Mapping[str, Any]) -> Mapping[str, Any]: return dict(config) | {"API_KEY": "boardman"} def test_get_scheme(self, schemes: SchemeRepository, client: FlaskClient) -> None: - scheme = Scheme(id_=1, name="Wirral Package", authority_id=1, type_=SchemeType.CONSTRUCTION) - scheme.funding_programme = FundingProgrammes.ATF4 - schemes.add(scheme) + schemes.add( + Scheme( + id_=1, + name="Wirral Package", + authority_id=1, + type_=SchemeType.CONSTRUCTION, + funding_programme=FundingProgrammes.ATF4, + ) + ) response = client.get("/schemes/1", headers={"Accept": "application/json", "Authorization": "API-Key boardman"}) diff --git a/tests/integration/test_scheme_overview.py b/tests/integration/test_scheme_overview.py index 8e9449d9..89272b03 100644 --- a/tests/integration/test_scheme_overview.py +++ b/tests/integration/test_scheme_overview.py @@ -29,20 +29,33 @@ def auth_fixture(self, authorities: AuthorityRepository, users: UserRepository, session["user"] = {"email": "boardman@example.com"} def test_scheme_shows_minimal_overview(self, schemes: SchemeRepository, client: FlaskClient) -> None: - schemes.add(build_scheme(id_=1, name="Wirral Package", authority_id=1, type_=SchemeType.CONSTRUCTION)) + schemes.add( + build_scheme( + id_=1, + name="Wirral Package", + authority_id=1, + type_=SchemeType.CONSTRUCTION, + funding_programme=FundingProgrammes.ATF4, + ) + ) scheme_page = SchemePage.open(client, id_=1) assert ( scheme_page.overview.reference == "ATE00001" and scheme_page.overview.scheme_type == "Construction" - and scheme_page.overview.funding_programme == "" + and scheme_page.overview.funding_programme == "ATF4" and scheme_page.overview.current_milestone == "" ) def test_scheme_shows_overview(self, schemes: SchemeRepository, client: FlaskClient) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=1, type_=SchemeType.CONSTRUCTION) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme( + id_=1, + name="Wirral Package", + authority_id=1, + type_=SchemeType.CONSTRUCTION, + funding_programme=FundingProgrammes.ATF4, + ) scheme.milestones.update_milestone( MilestoneRevision( id_=1, diff --git a/tests/integration/test_schemes.py b/tests/integration/test_schemes.py index 1f6b84f6..107e3afc 100644 --- a/tests/integration/test_schemes.py +++ b/tests/integration/test_schemes.py @@ -109,7 +109,9 @@ def test_schemes_shows_schemes(self, schemes: SchemeRepository, client: FlaskCli assert not schemes_page.is_no_schemes_message_visible def test_schemes_shows_minimal_scheme(self, schemes: SchemeRepository, client: FlaskClient) -> None: - schemes.add(build_scheme(id_=1, name="Wirral Package", authority_id=1)) + schemes.add( + build_scheme(id_=1, name="Wirral Package", authority_id=1, funding_programme=FundingProgrammes.ATF3) + ) schemes_page = SchemesPage.open(client) @@ -117,7 +119,7 @@ def test_schemes_shows_minimal_scheme(self, schemes: SchemeRepository, client: F assert schemes_page.schemes.to_dicts() == [ { "reference": "ATE00001", - "funding_programme": "", + "funding_programme": "ATF3", "name": "Wirral Package", "needs_review": True, "last_reviewed": "", @@ -125,8 +127,7 @@ def test_schemes_shows_minimal_scheme(self, schemes: SchemeRepository, client: F ] def test_schemes_shows_scheme(self, schemes: SchemeRepository, client: FlaskClient) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=1) - scheme.funding_programme = FundingProgrammes.ATF3 + scheme = build_scheme(id_=1, name="Wirral Package", authority_id=1, funding_programme=FundingProgrammes.ATF3) scheme.reviews.update_authority_review( AuthorityReview(id_=1, review_date=datetime(2020, 1, 2, 12), source=DataSource.ATF3_BID) ) diff --git a/tests/views/schemes/test_schemes.py b/tests/views/schemes/test_schemes.py index 363889e8..fc4eaa6c 100644 --- a/tests/views/schemes/test_schemes.py +++ b/tests/views/schemes/test_schemes.py @@ -118,8 +118,7 @@ def test_from_domain_sets_scheme_needs_review(self) -> None: class TestSchemeRowContext: def test_from_domain(self) -> None: - scheme = build_scheme(id_=1, name="Wirral Package", authority_id=1) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme(id_=1, name="Wirral Package", authority_id=1, funding_programme=FundingProgrammes.ATF4) context = SchemeRowContext.from_domain(dummy_reporting_window(), scheme) @@ -285,8 +284,7 @@ def test_from_domain_sets_type(self) -> None: assert context.type == SchemeTypeContext(name="Construction") def test_from_domain_sets_funding_programme(self) -> None: - scheme = build_scheme(id_=0, name="", authority_id=0) - scheme.funding_programme = FundingProgrammes.ATF4 + scheme = build_scheme(id_=0, name="", authority_id=0, funding_programme=FundingProgrammes.ATF4) context = SchemeOverviewContext.from_domain(scheme) @@ -348,10 +346,9 @@ class TestFundingProgrammeContext: (FundingProgrammes.MRN, "MRN"), (FundingProgrammes.LUF, "LUF"), (FundingProgrammes.CRSTS, "CRSTS"), - (None, None), ], ) - def test_from_domain(self, funding_programme: FundingProgramme | None, expected_name: str | None) -> None: + def test_from_domain(self, funding_programme: FundingProgramme, expected_name: str) -> None: context = FundingProgrammeContext.from_domain(funding_programme) assert context == FundingProgrammeContext(name=expected_name) @@ -359,22 +356,18 @@ def test_from_domain(self, funding_programme: FundingProgramme | None, expected_ class TestSchemeRepr: def test_from_domain(self) -> None: - scheme = Scheme(id_=1, name="Wirral Package", authority_id=2, type_=SchemeType.CONSTRUCTION) - scheme.funding_programme = FundingProgrammes.ATF4 - - scheme_repr = SchemeRepr.from_domain(scheme) - - assert scheme_repr == SchemeRepr( - id=1, name="Wirral Package", type=SchemeTypeRepr.CONSTRUCTION, funding_programme=FundingProgrammeRepr.ATF4 + scheme = Scheme( + id_=1, + name="Wirral Package", + authority_id=2, + type_=SchemeType.CONSTRUCTION, + funding_programme=FundingProgrammes.ATF4, ) - def test_from_domain_when_minimal(self) -> None: - scheme = Scheme(id_=1, name="Wirral Package", authority_id=2, type_=SchemeType.CONSTRUCTION) - scheme_repr = SchemeRepr.from_domain(scheme) assert scheme_repr == SchemeRepr( - id=1, name="Wirral Package", type=SchemeTypeRepr.CONSTRUCTION, funding_programme=None + id=1, name="Wirral Package", type=SchemeTypeRepr.CONSTRUCTION, funding_programme=FundingProgrammeRepr.ATF4 ) def test_from_domain_sets_bid_status_revisions(self) -> None: @@ -572,24 +565,12 @@ def test_to_domain(self) -> None: and scheme.funding_programme == FundingProgrammes.ATF4 ) - def test_to_domain_when_minimal(self) -> None: - scheme_repr = SchemeRepr(id=1, name="Wirral Package", type=SchemeTypeRepr.CONSTRUCTION) - - scheme = scheme_repr.to_domain(2) - - assert ( - scheme.id == 1 - and scheme.name == "Wirral Package" - and scheme.authority_id == 2 - and scheme.type == SchemeType.CONSTRUCTION - and scheme.funding_programme is None - ) - def test_to_domain_sets_bid_status_revisions(self) -> None: scheme_repr = SchemeRepr( id=0, name="", type=SchemeTypeRepr.CONSTRUCTION, + funding_programme=FundingProgrammeRepr.ATF4, bid_status_revisions=[ BidStatusRevisionRepr( id=2, @@ -624,6 +605,7 @@ def test_to_domain_sets_financial_revisions(self) -> None: id=0, name="", type=SchemeTypeRepr.CONSTRUCTION, + funding_programme=FundingProgrammeRepr.ATF4, financial_revisions=[ FinancialRevisionRepr( id=2, @@ -669,6 +651,7 @@ def test_to_domain_sets_milestone_revisions(self) -> None: id=0, name="", type=SchemeTypeRepr.CONSTRUCTION, + funding_programme=FundingProgrammeRepr.ATF4, milestone_revisions=[ MilestoneRevisionRepr( id=1, @@ -718,6 +701,7 @@ def test_to_domain_sets_output_revisions(self) -> None: id=0, name="", type=SchemeTypeRepr.CONSTRUCTION, + funding_programme=FundingProgrammeRepr.ATF4, output_revisions=[ OutputRevisionRepr( id=1, @@ -765,6 +749,7 @@ def test_to_domain_sets_authority_reviews(self) -> None: id=0, name="", type=SchemeTypeRepr.CONSTRUCTION, + funding_programme=FundingProgrammeRepr.ATF4, authority_reviews=[ AuthorityReviewRepr( id=2,