Skip to content

Commit

Permalink
Merge pull request #822 from uktrade/LTD-1159-turn-off-compliance
Browse files Browse the repository at this point in the history
Feature flag compliance case creation for SIELs
  • Loading branch information
eadpearce authored Sep 27, 2021
2 parents b1d2fde + 56c0fa8 commit e8bfdd7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
13 changes: 7 additions & 6 deletions api/compliance/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Optional

from django.utils import timezone
from django.conf import settings

from rest_framework.exceptions import ValidationError

from api.audit_trail.enums import AuditType
Expand Down Expand Up @@ -38,15 +40,14 @@ def get_compliance_site_case(pk):

def case_meets_conditions_for_compliance(case: Case):
if case.case_type.id == CaseTypeEnum.SIEL.id:
if not (
Good.objects.filter(
if settings.FEATURE_SIEL_COMPLIANCE_ENABLED:
if Good.objects.filter(
goods_on_application__application_id=case.id,
control_list_entries__rating__regex=COMPLIANCE_CASE_ACCEPTABLE_GOOD_CONTROL_CODES,
goods_on_application__licence__quantity__isnull=False,
).exists()
):
return False
return True
).exists():
return True
return False
elif case.case_type.id in [CaseTypeEnum.OIEL.id, CaseTypeEnum.OICL.id, *CaseTypeEnum.OPEN_GENERAL_LICENCE_IDS]:
return True
else:
Expand Down
22 changes: 20 additions & 2 deletions api/compliance/tests/test_compliance_creation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.test import override_settings

from parameterized import parameterized

from api.applications.models import SiteOnApplication, GoodOnApplication
from api.applications.models import SiteOnApplication
from api.applications.tests.factories import GoodOnApplicationFactory
from api.cases.enums import CaseTypeEnum
from api.cases.models import CaseType
Expand All @@ -10,7 +12,6 @@
from api.licences.tests.factories import LicenceFactory, GoodOnLicenceFactory
from api.open_general_licences.tests.factories import OpenGeneralLicenceCaseFactory, OpenGeneralLicenceFactory
from api.organisations.tests.factories import SiteFactory
from api.staticdata.control_list_entries.factories import ControlListEntriesFactory
from test_helpers.clients import DataTestClient


Expand Down Expand Up @@ -55,6 +56,7 @@ def tests_siel_bad_control_code(self):
@parameterized.expand(
[("ML21", True), ("ML22", True), ("ML2", False), ("0D", True),]
)
@override_settings(FEATURE_SIEL_COMPLIANCE_ENABLED=True)
def tests_siel_good_control_code(self, control_code, exists):
case = self.create_standard_application_case(self.organisation)

Expand All @@ -72,6 +74,22 @@ def tests_siel_good_control_code(self, control_code, exists):

self.assertEqual(ComplianceSiteCase.objects.exists(), exists)

@override_settings(FEATURE_SIEL_COMPLIANCE_ENABLED=False)
def tests_siel_no_compliance_feature_flag_off(self):
case = self.create_standard_application_case(self.organisation)

good = GoodFactory(organisation=self.organisation, is_good_controlled=True, control_list_entries=["ML22"],)
GoodOnLicenceFactory(
good=GoodOnApplicationFactory(application=case, good=good),
licence=LicenceFactory(case=case),
quantity=100,
value=1,
)

generate_compliance_site_case(case)

self.assertEqual(ComplianceSiteCase.objects.exists(), False)

def test_multiple_cases_creates_one_compliance_case(self):
# Both cases uses the organisation primary site by default on creation
case = self.create_open_application_case(self.organisation)
Expand Down
4 changes: 4 additions & 0 deletions api/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,7 @@
LITE_OPS_EMAIL = env.str("LITE_OPS_EMAIL")
LITE_REPORTS_RECIPIENTS = env.list("LITE_REPORTS_RECIPIENTS", default=[])
LITE_REPORTS_EMAIL_TEMPLATE_ID = env.str("LITE_REPORTS_EMAIL_TEMPLATE_ID", default="reports-email-template_id")

# Controls whether a ComplianceSiteCase is automatically created when a SIEL licence is issued that has goods with certain control codes
# See LTD-1159
FEATURE_SIEL_COMPLIANCE_ENABLED = env.bool("FEATURE_SIEL_COMPLIANCE_ENABLED", False)
2 changes: 2 additions & 0 deletions local.env
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ SIGNING_REASON=SIGNING_REASON
PERMISSIONS_FINDER_URL='' # required for accessing exporter lite content, can be empty string

ELASTICSEARCH_HOST=http://localost:9200

FEATURE_SIEL_COMPLIANCE_ENABLED=False

0 comments on commit e8bfdd7

Please sign in to comment.