-
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 #2386 from uktrade/uat
Production release
- Loading branch information
Showing
8 changed files
with
236 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import pytest | ||
|
||
from django.urls import reverse | ||
from urllib import parse | ||
|
||
from api.applications.tests.factories import StandardSubmittedApplicationFactory | ||
from api.flags.enums import FlagLevels | ||
from api.queues.constants import ALL_CASES_QUEUE_ID | ||
|
||
from lite_routing.routing_rules_internal.enums import FlagsEnum | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture | ||
def all_cases_queue_url(): | ||
query_params = {"queue_id": ALL_CASES_QUEUE_ID} | ||
return f"{reverse('cases:search')}?{parse.urlencode(query_params, doseq=True)}" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"flags_data", | ||
( | ||
{FlagLevels.CASE: [FlagsEnum.UNSCR_OFSI_SANCTIONS]}, | ||
{FlagLevels.GOOD: [FlagsEnum.SMALL_ARMS, FlagsEnum.UK_DUAL_USE_SCH3]}, | ||
{FlagLevels.DESTINATION: [FlagsEnum.OIL_AND_GAS_ID]}, | ||
{FlagLevels.PARTY_ON_APPLICATION: [FlagsEnum.SANCTION_UK_MATCH, FlagsEnum.SANCTION_OFSI_MATCH]}, | ||
), | ||
) | ||
def test_queue_view_case_flags( | ||
api_client, | ||
all_cases_queue_url, | ||
gov_headers, | ||
mocker, | ||
flags_data, | ||
): | ||
# When changes are saved in factory then post_save() signal can trigger flagging rules | ||
# and alter flags applied which is not desirable in these tests hence mock that function. | ||
mocker.patch("api.cases.signals.apply_flagging_rules_to_case", return_value=None) | ||
StandardSubmittedApplicationFactory(flags=flags_data) | ||
|
||
response = api_client.get(all_cases_queue_url, **gov_headers) | ||
assert response.status_code == 200 | ||
|
||
for case in response.json()["results"]["cases"]: | ||
all_flags = [ | ||
item["id"] for flag_level in ["flags", "goods_flags", "destinations_flags"] for item in case[flag_level] | ||
] | ||
|
||
expected_flags = [] | ||
for flags in flags_data.values(): | ||
expected_flags.extend(flags) | ||
|
||
assert sorted(all_flags) == sorted(expected_flags) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"flags_data", | ||
( | ||
{ | ||
FlagLevels.CASE: [FlagsEnum.UNSCR_OFSI_SANCTIONS], | ||
FlagLevels.GOOD: [FlagsEnum.DUAL_USE_ANNEX_1], | ||
}, | ||
{FlagLevels.GOOD: [FlagsEnum.SMALL_ARMS, FlagsEnum.UK_DUAL_USE_SCH3]}, | ||
{FlagLevels.DESTINATION: [FlagsEnum.OIL_AND_GAS_ID]}, | ||
{ | ||
FlagLevels.CASE: [FlagsEnum.GOODS_NOT_LISTED], | ||
FlagLevels.PARTY_ON_APPLICATION: [FlagsEnum.SANCTION_UK_MATCH, FlagsEnum.SANCTION_OFSI_MATCH], | ||
}, | ||
), | ||
) | ||
def test_case_detail_flags( | ||
api_client, | ||
gov_headers, | ||
mocker, | ||
flags_data, | ||
): | ||
mocker.patch("api.cases.signals.apply_flagging_rules_to_case", return_value=None) | ||
case = StandardSubmittedApplicationFactory(flags=flags_data) | ||
|
||
url = reverse("cases:case", kwargs={"pk": case.id}) | ||
response = api_client.get(url, **gov_headers) | ||
assert response.status_code == 200 | ||
|
||
response = response.json() | ||
all_flags = [item["id"] for item in response["case"]["all_flags"]] | ||
|
||
expected_flags = [] | ||
for flags in flags_data.values(): | ||
expected_flags.extend(flags) | ||
|
||
assert sorted(all_flags) == sorted(expected_flags) |
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
19 changes: 19 additions & 0 deletions
19
api/staticdata/denial_reasons/migrations/0007_criterion_1_description_update.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,19 @@ | ||
from django.db import migrations | ||
|
||
|
||
def update_denial_reason(apps, schema_editor): | ||
DenialReason = apps.get_model("denial_reasons", "DenialReason") | ||
denial_reason = DenialReason.objects.get(id=1) | ||
if denial_reason: | ||
denial_reason.description = "Respect for the UK's international obligations and commitments, in particular sanctions adopted by the UN Security Council, agreements on non-proliferation and other subjects, as well as other international obligations." | ||
denial_reason.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("denial_reasons", "0006_populate_uuid_field"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_denial_reason, migrations.RunPython.noop), | ||
] |
32 changes: 32 additions & 0 deletions
32
api/staticdata/denial_reasons/migrations/tests/test_0007_criterion_1_description_update.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,32 @@ | ||
import pytest | ||
|
||
from django_test_migrations.migrator import Migrator | ||
|
||
from api.staticdata.denial_reasons.constants import DENIAL_REASON_ID_TO_UUID_MAP | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_populate_uuid_field(): | ||
migrator = Migrator(database="default") | ||
|
||
old_state = migrator.apply_initial_migration(("denial_reasons", "0006_populate_uuid_field")) | ||
DenialReason = old_state.apps.get_model("denial_reasons", "DenialReason") | ||
denial_reason = DenialReason.objects.get(id=1) | ||
assert ( | ||
denial_reason.description | ||
== """Respect for the UK's international obligations and commitments, in particular sanctions adopted by the UN Security Council, agreements on non-proliferation and other subjects, as well as other international obligations. | ||
Military End Use Control.""" | ||
) | ||
|
||
new_state = migrator.apply_tested_migration(("denial_reasons", "0007_criterion_1_description_update")) | ||
DenialReason = new_state.apps.get_model("denial_reasons", "DenialReason") | ||
denial_reason = DenialReason.objects.get(id=1) | ||
assert ( | ||
denial_reason.description | ||
== "Respect for the UK's international obligations and commitments, in particular sanctions adopted by the UN Security Council, agreements on non-proliferation and other subjects, as well as other international obligations." | ||
) | ||
|
||
expected_uuids = set(DENIAL_REASON_ID_TO_UUID_MAP.values()) | ||
actual_uuids = set([str(denial_reason.uuid) for denial_reason in DenialReason.objects.all()]) | ||
assert expected_uuids == actual_uuids |
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