Skip to content

Commit

Permalink
Merge branch 'dev' into LTD-modify-bdd-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saruniitr committed Dec 3, 2024
2 parents 61647af + 8accc65 commit b953229
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 25 deletions.
10 changes: 10 additions & 0 deletions api/data_workspace/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from api.licences.models import GoodOnLicence
from api.staticdata.control_list_entries.models import ControlListEntry
from api.staticdata.countries.models import Country
from api.staticdata.denial_reasons.models import DenialReason
from api.staticdata.report_summaries.models import ReportSummary


Expand Down Expand Up @@ -163,3 +164,12 @@ class Meta:
"good_id",
"rating",
)


class LicenceRefusalCriteriaSerializer(serializers.ModelSerializer):
criteria = serializers.CharField(source="display_value")
licence_decision_id = serializers.UUIDField()

class Meta:
model = DenialReason
fields = ("criteria", "licence_decision_id")
26 changes: 19 additions & 7 deletions api/data_workspace/v2/tests/bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
PartyOnApplicationFactory,
StandardApplicationFactory,
)
from api.cases.tests.factories import FinalAdviceFactory
from api.cases.enums import AdviceLevel, AdviceType, CaseTypeEnum
from api.cases.models import CaseType, LicenceDecision
from api.cases.tests.factories import FinalAdviceFactory
from api.core.constants import (
ExporterPermissions,
GovPermissions,
Roles,
)
from api.goods.tests.factories import GoodFactory
from api.flags.enums import SystemFlags
from api.documents.libraries.s3_operations import init_s3_client
from api.flags.enums import SystemFlags
from api.goods.tests.factories import GoodFactory
from api.letter_templates.models import LetterTemplate
from api.licences.enums import LicenceStatus
from api.licences.models import Licence
from api.parties.tests.factories import PartyDocumentFactory
from api.organisations.tests.factories import OrganisationFactory
from api.parties.tests.factories import PartyDocumentFactory
from api.staticdata.letter_layouts.models import LetterLayout
from api.staticdata.report_summaries.models import (
ReportSummaryPrefix,
Expand Down Expand Up @@ -570,10 +570,19 @@ def _issue_licence(application):


@pytest.fixture()
def refuse_licence(api_client, lu_case_officer, gov_headers, siel_refusal_template):
def _refuse_licence(application):
def refuse_application(
api_client,
lu_case_officer,
siel_refusal_template,
gov_headers,
):
def _refuse_application(application, denial_reasons=None):
if not denial_reasons:
denial_reasons = ["1a", "1b", "1c"]

# delete previous final advice if any before we change decision
application.advice.filter(level=AdviceLevel.FINAL).delete()

data = {"action": AdviceType.REFUSE}
for good_on_app in application.goods.all():
good_on_app.quantity = 100
Expand All @@ -586,6 +595,7 @@ def _refuse_licence(application):
case=application,
good=good_on_app.good,
type=AdviceType.REFUSE,
denial_reasons=denial_reasons,
)

application.flags.remove(SystemFlags.ENFORCEMENT_CHECK_REQUIRED)
Expand Down Expand Up @@ -615,7 +625,9 @@ def _refuse_licence(application):
response = api_client.put(url, data={}, **gov_headers)
assert response.status_code == 201, response.content

return _refuse_licence
application.refresh_from_db()

return _refuse_application


@when(parsers.parse("the application is issued at {timestamp}"), target_fixture="issued_application")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@db
Feature: licence_refusal_criteria Table

Scenario: Draft application
Given a draft standard application
Then the `licence_refusal_criteria` table is empty

Scenario: Submit an application
Given a draft standard application
When the application is submitted
Then the `licence_refusal_criteria` table is empty

Scenario: Issuing an application
Given a draft standard application
When the application is submitted
And the application is issued
Then the `licence_refusal_criteria` table is empty

Scenario: Refusing an application
Given a draft standard application
When the application is submitted
And the application is refused with criteria:
| 1 |
| 2c |
Then the `licence_refusal_criteria` table has the following rows:
| licence_decision_id | criteria |
| 03fb08eb-1564-4b68-9336-3ca8906543f9 | 1 |
| 03fb08eb-1564-4b68-9336-3ca8906543f9 | 2c |
22 changes: 4 additions & 18 deletions api/data_workspace/v2/tests/bdd/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ def _exporter_change_status(application, status):
return _exporter_change_status


@given("a draft standard application", target_fixture="draft_standard_application")
def given_draft_standard_application(organisation):
application = DraftStandardApplicationFactory(
organisation=organisation,
)

PartyDocumentFactory(
party=application.end_user.party,
s3_key="party-document",
safe=True,
)

return application


@given(
parsers.parse("a draft temporary standard application with attributes:{attributes}"),
target_fixture="draft_standard_application",
Expand Down Expand Up @@ -139,11 +124,12 @@ def given_a_good_is_onward_incorporated(draft_standard_application):


@when(
"the application is submitted",
parsers.parse("the application is submitted at {submission_time}"),
target_fixture="submitted_standard_application",
)
def when_the_application_is_submitted(submit_application, draft_standard_application):
return submit_application(draft_standard_application)
def when_the_application_is_submitted_at(submit_application, draft_standard_application, submission_time):
with freeze_time(submission_time):
return submit_application(draft_standard_application)


@when(parsers.parse("the application is withdrawn at {timestamp}"))
Expand Down
39 changes: 39 additions & 0 deletions api/data_workspace/v2/tests/bdd/test_licence_refusal_criteria.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import uuid

from pytest_bdd import (
parsers,
scenarios,
when,
)


scenarios("./scenarios/licence_refusal_criteria.feature")


@when(parsers.parse("the application is refused with criteria:{criteria}"))
def when_the_application_is_refused_with_criteria(
submitted_standard_application, refuse_application, parse_table, criteria
):
criteria = [c[0] for c in parse_table(criteria)]
refuse_application(submitted_standard_application, criteria)
refused_application = submitted_standard_application
licence_decision = refused_application.licence_decisions.get()
old_pk = licence_decision.pk
licence_decision.pk = uuid.UUID("03fb08eb-1564-4b68-9336-3ca8906543f9") # /PS-IGNORE
licence_decision.save()
licence_decision.denial_reasons.through.objects.filter(licencedecision_id=old_pk).update(
licencedecision_id=licence_decision.pk
)


@when("the application is issued")
def when_the_application_is_issued(
issue_licence,
submitted_standard_application,
):
issue_licence(submitted_standard_application)

submitted_standard_application.refresh_from_db()
issued_application = submitted_standard_application

return issued_application
1 change: 1 addition & 0 deletions api/data_workspace/v2/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
router_v2.register(views.UnitViewSet)
router_v2.register(views.FootnoteViewSet)
router_v2.register(views.AssessmentViewSet)
router_v2.register(views.LicenceRefusalCriteriaViewSet)
12 changes: 12 additions & 0 deletions api/data_workspace/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
LicenceDecisionSerializer,
UnitSerializer,
GoodOnLicenceSerializer,
LicenceRefusalCriteriaSerializer,
)
from api.licences.enums import LicenceStatus
from api.licences.models import GoodOnLicence
from api.staticdata.control_list_entries.models import ControlListEntry
from api.staticdata.countries.models import Country
from api.staticdata.report_summaries.models import ReportSummary
from api.staticdata.denial_reasons.models import DenialReason
from api.staticdata.statuses.enums import CaseStatusEnum
from api.staticdata.units.enums import Units

Expand Down Expand Up @@ -197,3 +199,13 @@ def get_queryset(self):

class DataWorkspace:
table_name = "goods_ratings"


class LicenceRefusalCriteriaViewSet(BaseViewSet):
serializer_class = LicenceRefusalCriteriaSerializer
queryset = DenialReason.objects.exclude(licencedecision__denial_reasons__isnull=True).annotate(
licence_decision_id=F("licencedecision__id")
)

class DataWorkspace:
table_name = "licence_refusal_criteria"
1 change: 1 addition & 0 deletions pii-secret-exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ api/cases/generated_documents/tests/data/dummy.pdf
api/cases/generated_documents/tests/data/signed.pdf
api/data_workspace/v2/tests/bdd/scenarios/applications.feature
api/data_workspace/v2/tests/bdd/scenarios/goods_on_licences.feature
api/data_workspace/v2/tests/bdd/scenarios/licence_refusal_criteria.feature

0 comments on commit b953229

Please sign in to comment.