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

Add stage validation for site_address_is_company_address field #5928

Merged
merged 1 commit into from
Jan 30, 2025
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
1 change: 1 addition & 0 deletions datahub/investment/project/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class VerifyWinInvestmentProjectFactory(ActiveInvestmentProjectFactory):
non_fdi_r_and_d_budget = False
new_tech_to_uk = True
export_revenue = True
site_address_is_company_address = False
address_1 = factory.Faker('street_address')
address_town = factory.Faker('city')
address_postcode = factory.Faker('postcode')
Expand Down
67 changes: 63 additions & 4 deletions datahub/investment/project/test/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from datahub.investment.project.test.factories import (
ActiveInvestmentProjectFactory,
InvestmentProjectFactory,
VerifyWinInvestmentProjectFactory,
)
from datahub.investment.project.validate import (
_get_desired_stage_order,
Expand Down Expand Up @@ -271,6 +272,7 @@ def test_validate_verify_win_instance_failure():
total_investment=100,
client_considering_other_countries=False,
client_requirements='client reqs',
site_address_is_company_address=None,
site_decided=False,
strategic_drivers=strategic_drivers,
uk_region_locations=[random_obj_for_model(UKRegion)],
Expand All @@ -287,10 +289,7 @@ def test_validate_verify_win_instance_failure():
'non_fdi_r_and_d_budget': 'This field is required.',
'new_tech_to_uk': 'This field is required.',
'export_revenue': 'This field is required.',
'address_1': 'This field is required.',
'address_town': 'This field is required.',
'address_postcode': 'This field is required.',
'actual_uk_regions': 'This field is required.',
'site_address_is_company_address': 'This field is required.',
'delivery_partners': 'This field is required.',
'client_cannot_provide_foreign_investment': 'This field is required.',
'foreign_equity_investment': 'This field is required.',
Expand Down Expand Up @@ -345,6 +344,7 @@ def test_validate_verify_win_instance_with_cond_fields():
number_new_jobs=10,
client_considering_other_countries=False,
client_requirements='client reqs',
site_address_is_company_address=False,
site_decided=False,
strategic_drivers=strategic_drivers,
uk_region_locations=[random_obj_for_model(UKRegion)],
Expand Down Expand Up @@ -396,3 +396,62 @@ def test_likelihood_to_land_assign_pm_stage_missing_error():
def test_get_desired_stage_order(desired_stage, next_stage, expected_stage_order):
"""Test get desired stage order."""
assert _get_desired_stage_order(desired_stage, next_stage) == expected_stage_order


def test_site_address_is_company_address_is_marked_incomplete_at_active_stage():
project = ActiveInvestmentProjectFactory(
site_address_is_company_address=None,
address_1=None,
address_town=None,
address_postcode=None,
)
incomplete_fields = project.incomplete_fields # this calls validate(self, next_stage=True)
assert 'site_address_is_company_address' in incomplete_fields
# Address fields are conditionally marked if site_address_is_company_address has a value
assert 'address_1' not in incomplete_fields
assert 'address_town' not in incomplete_fields
assert 'address_postcode' not in incomplete_fields


@pytest.mark.parametrize('value', (True, False))
def test_site_address_fields_are_marked_incomplete_at_active_stage(value):
project = ActiveInvestmentProjectFactory(
site_address_is_company_address=False,
address_1=None,
address_town=None,
address_postcode=None,
)
incomplete_fields = project.incomplete_fields # this calls validate(self, next_stage=True)
assert 'site_address_is_company_address' not in incomplete_fields
# Address fields are conditionally marked if site_address_is_company_address has a value
assert 'address_1' in incomplete_fields
assert 'address_town' in incomplete_fields
assert 'address_postcode' in incomplete_fields


def test_site_address_is_company_address_is_required_at_verify_win_stage():
project = VerifyWinInvestmentProjectFactory(
site_address_is_company_address=None,
)
errors = validate(instance=project)
assert 'site_address_is_company_address' in errors
# Address fields are conditionally required if site_address_is_company_address has a value
assert 'address_1' not in errors
assert 'address_town' not in errors
assert 'address_postcode' not in errors


@pytest.mark.parametrize('value', (True, False))
def test_site_address_fields_are_required_at_verify_win_stage_after_condition_met(value):
project = VerifyWinInvestmentProjectFactory(
site_address_is_company_address=value,
address_1=None,
address_town=None,
address_postcode=None,
)
errors = validate(instance=project)
assert 'site_address_is_company_address' not in errors
# Address fields are conditionally required if site_address_is_company_address has a value
assert 'address_1' in errors
assert 'address_town' in errors
assert 'address_postcode' in errors
6 changes: 2 additions & 4 deletions datahub/investment/project/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,7 @@ def test_change_stage_verify_win_failure(self):
'non_fdi_r_and_d_budget': ['This field is required.'],
'new_tech_to_uk': ['This field is required.'],
'export_revenue': ['This field is required.'],
'address_1': ['This field is required.'],
'address_town': ['This field is required.'],
'address_postcode': ['This field is required.'],
'actual_uk_regions': ['This field is required.'],
'site_address_is_company_address': ['This field is required.'],
'delivery_partners': ['This field is required.'],
'client_cannot_provide_foreign_investment': ['This field is required.'],
'foreign_equity_investment': ['This field is required.'],
Expand Down Expand Up @@ -1581,6 +1578,7 @@ def test_change_stage_verify_win_success(self, field):
associated_non_fdi_r_and_d_project=InvestmentProjectFactory(),
new_tech_to_uk=True,
export_revenue=True,
site_address_is_company_address=False,
address_1='12 London Road',
address_town='London',
address_postcode='SW1A 2AA',
Expand Down
21 changes: 17 additions & 4 deletions datahub/investment/project/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def _get_to_many_id(instance):
return instance.id


def _is_not_none(value):
return value is not None


class InvestmentProjectStageValidationConfig:
"""Investment Project stage validation config."""

Expand All @@ -54,10 +58,7 @@ def get_required_fields_after_stage(cls):
'non_fdi_r_and_d_budget': Stage.verify_win.value,
'new_tech_to_uk': Stage.verify_win.value,
'export_revenue': Stage.verify_win.value,
'address_1': Stage.verify_win.value,
'address_town': Stage.verify_win.value,
'address_postcode': Stage.verify_win.value,
'actual_uk_regions': Stage.verify_win.value,
'site_address_is_company_address': Stage.verify_win.value,
'delivery_partners': Stage.verify_win.value,
'actual_land_date': Stage.verify_win.value,
'specific_programmes': Stage.verify_win.value,
Expand Down Expand Up @@ -105,6 +106,18 @@ def get_conditional_rules_after_stage(cls):
CondValRule(
'allow_blank_possible_uk_regions', False, Stage.assign_pm.value,
),
'address_1':
CondValRule(
'site_address_is_company_address', _is_not_none, Stage.verify_win.value,
),
'address_town':
CondValRule(
'site_address_is_company_address', _is_not_none, Stage.verify_win.value,
),
'address_postcode':
CondValRule(
'site_address_is_company_address', _is_not_none, Stage.verify_win.value,
),
'foreign_equity_investment':
CondValRule(
'client_cannot_provide_foreign_investment', not_, Stage.verify_win.value,
Expand Down
20 changes: 10 additions & 10 deletions datahub/search/investment/test/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):
"""
project = InvestmentProjectFactory(
stage_id=InvestmentProjectStage.won.value.id,
likelihood_to_land_id=None)
likelihood_to_land_id=None,
address_1=None,
address_town=None,
address_postcode=None,
)
adviser = AdviserFactory()

opensearch_with_signals.indices.refresh()
Expand All @@ -367,10 +371,7 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):
'non_fdi_r_and_d_budget',
'new_tech_to_uk',
'export_revenue',
'address_1',
'address_town',
'address_postcode',
'actual_uk_regions',
'site_address_is_company_address',
'delivery_partners',
'actual_land_date',
'specific_programmes',
Expand All @@ -396,9 +397,7 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):
project.non_fdi_r_and_d_budget = True
project.new_tech_to_uk = True
project.export_revenue = True
project.address_1 = 'Downing Street'
project.address_town = 'London'
project.address_postcode = 'SW1A 2AA'
project.site_address_is_company_address = False
project.actual_land_date = date(2020, 1, 1)
project.total_investment = Decimal('100.00')
project.foreign_equity_investment = Decimal('50.00')
Expand All @@ -410,7 +409,6 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):

assert result.hits[0]['incomplete_fields'] == [
'strategic_drivers',
'actual_uk_regions',
'delivery_partners',
'specific_programmes',
'uk_company',
Expand All @@ -419,6 +417,9 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):
'likelihood_to_land',
'competitor_countries',
'uk_region_locations',
'address_1',
'address_town',
'address_postcode',
'average_salary',
'associated_non_fdi_r_and_d_project',
]
Expand All @@ -429,7 +430,6 @@ def test_incomplete_fields_syncs_when_project_changes(opensearch_with_signals):
(
('competitor_countries', lambda: Country.objects.all()[:3]),
('uk_region_locations', lambda: UKRegion.objects.all()[:3]),
('actual_uk_regions', lambda: UKRegion.objects.all()[:2]),
('delivery_partners', lambda: InvestmentDeliveryPartner.objects.all()[:2]),
('strategic_drivers', lambda: InvestmentStrategicDriver.objects.all()[:1]),
),
Expand Down