-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2307 from uktrade/LTD-5674_Productionise_goods_on…
…_licences_endpoint Add goods on licences endpoint
- Loading branch information
Showing
8 changed files
with
246 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
api/data_workspace/v2/tests/bdd/scenarios/goods_on_licences.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@db | ||
Feature: Goods On Licences | ||
|
||
Scenario: Issue a licence | ||
Given a standard application with the following goods: | ||
| id | name | | ||
| 61d193bd-a4d8-4f7d-8c07-1ac5e03ea2c7 | A controlled good | | ||
And a draft licence with attributes: | ||
| name | value | | ||
| id | 962b4948-b87a-42fe-9c2b-61bdefd9cd21 | | ||
When the licence is issued | ||
Then the `goods_on_licences` table has the following rows: | ||
| good_id | licence_id | | ||
| 61d193bd-a4d8-4f7d-8c07-1ac5e03ea2c7 | 962b4948-b87a-42fe-9c2b-61bdefd9cd21 | | ||
|
||
Scenario: NLR goods not on licence | ||
Given a standard application with the following goods: | ||
| id | name | | ||
| aa9736f9-48f5-4d44-ace9-e4b8738591a5 | Another controlled good | | ||
| 56f562f6-b554-4bb3-923b-8695ab15afca | An NLR good | | ||
And the goods are assessed by TAU as: | ||
| id | Control list entry | Report summary prefix | Report summary subject | | ||
| aa9736f9-48f5-4d44-ace9-e4b8738591a5 | ML5b | accessories for | network analysers | | ||
| 56f562f6-b554-4bb3-923b-8695ab15afca | NLR | | | | ||
And a draft licence with attributes: | ||
| name | value | | ||
| id | 847a9a03-c35f-4036-ab8c-8b58d13482ab | | ||
When the licence is issued | ||
Then the `goods_on_licences` table has the following rows: | ||
| good_id | licence_id | | ||
| aa9736f9-48f5-4d44-ace9-e4b8738591a5 | 847a9a03-c35f-4036-ab8c-8b58d13482ab | | ||
|
||
Scenario: Draft licences | ||
Given a standard application with the following goods: | ||
| id | name | | ||
| f7c674b1-cd5e-4a6d-a1f5-d6ab58149d05 | A controlled good 2 | | ||
And a draft licence with attributes: | ||
| name | value | | ||
| id | 297e89b9-fc93-4f38-be46-c2ab38914007 | | ||
Then the `goods_on_licences` table is empty | ||
|
||
Scenario: Draft applications | ||
Given a draft standard application with the following goods: | ||
| id | name | | ||
| 8262dcf7-d932-4a33-978d-b5aa8a7878ee | A controlled good 3 | | ||
And a draft licence with attributes: | ||
| name | value | | ||
| id | 2078827b-6d67-406c-becc-41c423720cfc | | ||
Then the `goods_on_licences` table is empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
api/data_workspace/v2/tests/bdd/test_goods_on_licences.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from django.urls import reverse | ||
from pytest_bdd import given, parsers, scenarios, when | ||
|
||
from api.applications.tests.factories import GoodOnApplicationFactory | ||
from api.licences.tests.factories import StandardLicenceFactory | ||
from api.licences.enums import LicenceStatus | ||
from api.staticdata.report_summaries.models import ( | ||
ReportSummaryPrefix, | ||
ReportSummarySubject, | ||
) | ||
|
||
scenarios("./scenarios/goods_on_licences.feature") | ||
|
||
|
||
@given(parsers.parse("a standard application with the following goods:{goods}"), target_fixture="standard_application") | ||
def standard_application_with_following_goods(parse_table, goods, standard_application): | ||
standard_application.goods.all().delete() | ||
good_attributes = parse_table(goods)[1:] | ||
for id, name in good_attributes: | ||
GoodOnApplicationFactory( | ||
application=standard_application, | ||
id=id, | ||
good__name=name, | ||
) | ||
return standard_application | ||
|
||
|
||
@given(parsers.parse("a draft licence with attributes:{attributes}"), target_fixture="draft_licence") | ||
def draft_licence_with_attributes(parse_attributes, attributes, standard_application): | ||
draft_licence = StandardLicenceFactory( | ||
case=standard_application, status=LicenceStatus.DRAFT, **parse_attributes(attributes) | ||
) | ||
return draft_licence | ||
|
||
|
||
@when("the licence is issued") | ||
def licence_is_issued(standard_application, issue_licence): | ||
issue_licence(standard_application) | ||
standard_application.refresh_from_db() | ||
return standard_application | ||
|
||
|
||
@given(parsers.parse("the goods are assessed by TAU as:{assessments}")) | ||
def the_goods_are_assessed_by_tau_as( | ||
parse_table, | ||
standard_application, | ||
assessments, | ||
api_client, | ||
lu_case_officer, | ||
gov_headers, | ||
): | ||
assessments = parse_table(assessments)[1:] | ||
url = reverse("assessments:make_assessments", kwargs={"case_pk": standard_application.pk}) | ||
|
||
assessment_payload = [] | ||
for good_on_application_id, control_list_entry, report_summary_prefix, report_summary_subject in assessments: | ||
data = { | ||
"id": good_on_application_id, | ||
"comment": "Some comment", | ||
} | ||
|
||
if control_list_entry == "NLR": | ||
data.update( | ||
{ | ||
"control_list_entries": [], | ||
"is_good_controlled": False, | ||
} | ||
) | ||
else: | ||
if report_summary_prefix: | ||
prefix = ReportSummaryPrefix.objects.get(name=report_summary_prefix) | ||
else: | ||
prefix = None | ||
subject = ReportSummarySubject.objects.get(name=report_summary_subject) | ||
data.update( | ||
{ | ||
"control_list_entries": [control_list_entry], | ||
"report_summary_prefix": prefix.pk if prefix else None, | ||
"report_summary_subject": subject.pk, | ||
"is_good_controlled": True, | ||
"regime_entries": [], | ||
} | ||
) | ||
assessment_payload.append(data) | ||
|
||
response = api_client.put( | ||
url, | ||
assessment_payload, | ||
**gov_headers, | ||
) | ||
assert response.status_code == 200, response.content | ||
|
||
|
||
@given( | ||
parsers.parse("a draft standard application with the following goods:{goods}"), target_fixture="draft_application" | ||
) | ||
def draft_standard_application_with_following_goods(parse_table, goods, draft_application): | ||
draft_application.goods.all().delete() | ||
good_attributes = parse_table(goods)[1:] | ||
for id, name in good_attributes: | ||
GoodOnApplicationFactory( | ||
application=draft_application, | ||
id=id, | ||
good__name=name, | ||
) | ||
return draft_application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.