From aa3271e6e1eb7e62281c311c3dc9d9b371d627f7 Mon Sep 17 00:00:00 2001 From: Oliver Roberts Date: Tue, 4 Jun 2024 07:24:52 +0100 Subject: [PATCH] Require uk recipient company before project can move to verify win stage --- datahub/investment/project/test/factories.py | 5 +++++ datahub/investment/project/test/test_validate.py | 4 +++- datahub/investment/project/test/test_views.py | 4 ++++ datahub/investment/project/validate.py | 1 + datahub/search/investment/test/test_signals.py | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/datahub/investment/project/test/factories.py b/datahub/investment/project/test/factories.py index 97467af02e..a4df1993b0 100644 --- a/datahub/investment/project/test/factories.py +++ b/datahub/investment/project/test/factories.py @@ -12,6 +12,7 @@ ContactFactory, ) from datahub.core.constants import ( + Country, InvestmentBusinessActivity, InvestmentProjectStage, InvestmentStrategicDriver, @@ -169,6 +170,10 @@ class VerifyWinInvestmentProjectFactory(ActiveInvestmentProjectFactory): address_postcode = factory.Faker('postcode') average_salary_id = SalaryRange.below_25000.value.id specific_programme_id = SpecificProgramme.space.value.id + uk_company = factory.SubFactory( + CompanyFactory, + address_country_id=Country.united_kingdom.value.id, + ) @to_many_field def actual_uk_regions(self): diff --git a/datahub/investment/project/test/test_validate.py b/datahub/investment/project/test/test_validate.py index 3114c3075e..7bb79065f5 100644 --- a/datahub/investment/project/test/test_validate.py +++ b/datahub/investment/project/test/test_validate.py @@ -2,7 +2,7 @@ import pytest -from datahub.company.test.factories import AdviserFactory, ContactFactory +from datahub.company.test.factories import AdviserFactory, CompanyFactory, ContactFactory from datahub.core import constants from datahub.core.test_utils import random_obj_for_model from datahub.investment.project.constants import SpecificProgramme @@ -293,6 +293,7 @@ def test_validate_verify_win_instance_failure(): 'foreign_equity_investment': 'This field is required.', 'actual_land_date': 'This field is required.', 'specific_programme': 'This field is required.', + 'uk_company': 'This field is required.', } @@ -359,6 +360,7 @@ def test_validate_verify_win_instance_with_cond_fields(): average_salary_id=constants.SalaryRange.below_25000.value.id, actual_land_date=date.today(), specific_programme_id=SpecificProgramme.space.value.id, + uk_company=CompanyFactory(address_country_id=constants.Country.united_kingdom.value.id), ) errors = validate(instance=project) assert not errors diff --git a/datahub/investment/project/test/test_views.py b/datahub/investment/project/test/test_views.py index 5badba85a8..b89fedb8a4 100644 --- a/datahub/investment/project/test/test_views.py +++ b/datahub/investment/project/test/test_views.py @@ -1518,6 +1518,7 @@ def test_change_stage_verify_win_failure(self): 'foreign_equity_investment': ['This field is required.'], 'actual_land_date': ['This field is required.'], 'specific_programme': ['This field is required.'], + 'uk_company': ['This field is required.'], } @pytest.mark.parametrize( @@ -1556,6 +1557,9 @@ def test_change_stage_verify_win_success(self, field): average_salary_id=constants.SalaryRange.below_25000.value.id, actual_land_date=factory.Faker('past_date'), specific_programme_id=SpecificProgramme.space.value.id, + uk_company=CompanyFactory( + address_country_id=constants.Country.united_kingdom.value.id, + ), **extra, ) url = reverse('api-v3:investment:investment-item', kwargs={'pk': project.pk}) diff --git a/datahub/investment/project/validate.py b/datahub/investment/project/validate.py index 99f099a654..f3721ef06d 100644 --- a/datahub/investment/project/validate.py +++ b/datahub/investment/project/validate.py @@ -61,6 +61,7 @@ def get_required_fields_after_stage(cls): 'delivery_partners': Stage.verify_win.value, 'actual_land_date': Stage.verify_win.value, 'specific_programme': Stage.verify_win.value, + 'uk_company': Stage.verify_win.value, } @classmethod diff --git a/datahub/search/investment/test/test_signals.py b/datahub/search/investment/test/test_signals.py index 32874cce0c..240ee3fd65 100644 --- a/datahub/search/investment/test/test_signals.py +++ b/datahub/search/investment/test/test_signals.py @@ -372,6 +372,7 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals): 'delivery_partners', 'actual_land_date', 'specific_programme', + 'uk_company', 'total_investment', 'uk_region_locations', 'foreign_equity_investment', @@ -407,6 +408,7 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals): 'actual_uk_regions', 'delivery_partners', 'specific_programme', + 'uk_company', 'competitor_countries', 'uk_region_locations', 'average_salary',