-
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.
Update bdd tests for destinations endpoint
- Loading branch information
Showing
4 changed files
with
58 additions
and
163 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
125 changes: 5 additions & 120 deletions
125
api/data_workspace/v2/tests/bdd/licences/test_destinations.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 |
---|---|---|
@@ -1,125 +1,10 @@ | ||
import pytest | ||
from pytest_bdd import given, scenarios, then, when | ||
from datetime import datetime | ||
from pytest_bdd import scenarios, when | ||
|
||
from django.urls import reverse | ||
|
||
from api.applications.models import PartyOnApplication | ||
from api.licences.enums import LicenceStatus | ||
from api.parties.enums import PartyType | ||
from api.staticdata.statuses.enums import CaseStatusEnum | ||
|
||
scenarios("../scenarios/destinations.feature") | ||
|
||
|
||
@pytest.fixture() | ||
def destinations_list_url(): | ||
return reverse("data_workspace:v2:dw-destinations-list") | ||
|
||
|
||
@given("a standard licence is created", target_fixture="licence") | ||
def standard_licence_created(standard_licence): | ||
assert standard_licence.status == LicenceStatus.ISSUED | ||
return standard_licence | ||
|
||
|
||
@when("I fetch all destinations", target_fixture="destinations") | ||
def fetch_all_destinations(destinations_list_url, unpage_data): | ||
return unpage_data(destinations_list_url) | ||
|
||
|
||
@then("the country code and type are included in the extract") | ||
def country_code_and_type_included_in_extract(destinations): | ||
party_on_application = PartyOnApplication.objects.get() | ||
application_id = party_on_application.application_id | ||
country_code = party_on_application.party.country.id | ||
party_type = party_on_application.party.type | ||
|
||
destination = {"application_id": str(application_id), "country_code": country_code, "type": party_type} | ||
assert destination in destinations | ||
|
||
|
||
@given("a licence with deleted party is created", target_fixture="licence_with_deleted_party") | ||
def licence_with_deleted_party_created(licence_with_deleted_party): | ||
assert licence_with_deleted_party.status == LicenceStatus.ISSUED | ||
application = licence_with_deleted_party.case.baseapplication | ||
assert PartyOnApplication.objects.filter(application=application).count() == 2 | ||
|
||
|
||
@then("the existing party is included in the extract") | ||
def existing_party_included_in_extract(destinations): | ||
existing_party_on_application = PartyOnApplication.objects.get(deleted_at__isnull=True) | ||
application_id = existing_party_on_application.application_id | ||
country_code = existing_party_on_application.party.country.id | ||
party_type = existing_party_on_application.party.type | ||
|
||
assert PartyOnApplication.objects.filter(application_id=application_id).count() == 2 | ||
|
||
destination = {"application_id": str(application_id), "country_code": country_code, "type": party_type} | ||
assert destination in destinations | ||
assert len(destinations) == 1 | ||
|
||
|
||
@then("the deleted party is not included in the extract") | ||
def deleted_party_not_included_in_extract(destinations): | ||
deleted_party_on_application = PartyOnApplication.objects.get(deleted_at__isnull=False) | ||
application_id = deleted_party_on_application.application_id | ||
country_code = deleted_party_on_application.party.country.id | ||
party_type = deleted_party_on_application.party.type | ||
|
||
assert PartyOnApplication.objects.filter(application_id=application_id).count() == 2 | ||
|
||
destination = {"application_id": str(application_id), "country_code": country_code, "type": party_type} | ||
assert destination not in destinations | ||
assert len(destinations) == 1 | ||
|
||
|
||
@given("a draft application is created") | ||
def draft_application_created(draft_application): | ||
assert draft_application.status.status == CaseStatusEnum.DRAFT | ||
return draft_application | ||
|
||
|
||
@then("the non-draft party is included in the extract") | ||
def non_draft_party_is_included_in_extract(destinations): | ||
non_draft_party_on_application = PartyOnApplication.objects.get( | ||
application__status__status=CaseStatusEnum.FINALISED | ||
) | ||
application_id = non_draft_party_on_application.application_id | ||
country_code = non_draft_party_on_application.party.country.id | ||
party_type = non_draft_party_on_application.party.type | ||
|
||
destination = {"application_id": str(application_id), "country_code": country_code, "type": party_type} | ||
assert destination in destinations | ||
assert len(destinations) == 1 | ||
|
||
|
||
@then("draft parties are not included in the extract") | ||
def draft_parties_not_included_in_extract(destinations): | ||
draft_parties_on_application = PartyOnApplication.objects.filter(application__status__status=CaseStatusEnum.DRAFT) | ||
|
||
application_id = draft_parties_on_application.first().application_id | ||
|
||
draft_end_user = draft_parties_on_application.get(party__type=PartyType.END_USER) | ||
draft_end_user_country_code = draft_end_user.party.country.id | ||
draft_end_user_party_type = draft_end_user.party.type | ||
|
||
assert PartyOnApplication.objects.filter(application_id=application_id).count() == 2 | ||
|
||
draft_end_user_destination = { | ||
"application_id": str(application_id), | ||
"country_code": draft_end_user_country_code, | ||
"type": draft_end_user_party_type, | ||
} | ||
assert draft_end_user_destination not in destinations | ||
|
||
draft_consignee = draft_parties_on_application.get(party__type=PartyType.CONSIGNEE) | ||
draft_consignee_country_code = draft_consignee.party.country.id | ||
draft_consignee_party_type = draft_consignee.party.type | ||
|
||
draft_consignee_destination = { | ||
"application_id": str(application_id), | ||
"country_code": draft_consignee_country_code, | ||
"party_type": draft_consignee_party_type, | ||
} | ||
assert draft_consignee_destination not in destinations | ||
assert len(destinations) == 1 | ||
@when("the parties are deleted") | ||
def when_parties_are_deleted(issued_application): | ||
issued_application.parties.update(deleted_at=datetime.now()) |
39 changes: 24 additions & 15 deletions
39
api/data_workspace/v2/tests/bdd/scenarios/destinations.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 |
---|---|---|
@@ -1,20 +1,29 @@ | ||
@db | ||
Feature: Destinations | ||
Feature: destinations Table | ||
|
||
|
||
Scenario: Draft application | ||
Given a draft standard application | ||
Then the `destinations` table is empty | ||
|
||
|
||
Scenario: Check that the country code and type are included in the extract | ||
Given a standard licence is created | ||
When I fetch all destinations | ||
Then the country code and type are included in the extract | ||
Given a draft standard application with attributes: | ||
| name | value | | ||
| id | 03fb08eb-1564-4b68-9336-3ca8906543f9 | | ||
When the application is submitted | ||
And the application is issued at 2024-11-22T13:35:15 | ||
Then the `destinations` table has the following rows: | ||
| application_id | country_code | type | | ||
| 03fb08eb-1564-4b68-9336-3ca8906543f9 | IT | end_user | | ||
| 03fb08eb-1564-4b68-9336-3ca8906543f9 | ES | consignee | | ||
|
||
Scenario: Deleted parties are not included in the extract | ||
Given a licence with deleted party is created | ||
When I fetch all destinations | ||
Then the existing party is included in the extract | ||
And the deleted party is not included in the extract | ||
|
||
Scenario: Draft applications are not included in the extract | ||
Given a standard licence is created | ||
And a draft application is created | ||
When I fetch all destinations | ||
Then the non-draft party is included in the extract | ||
And draft parties are not included in the extract | ||
Scenario: Deleted parties are not included in the extract | ||
Given a draft standard application with attributes: | ||
| name | value | | ||
| id | 03fb08eb-1564-4b68-9336-3ca8906543f9 | | ||
When the application is submitted | ||
And the application is issued at 2024-11-22T13:35:15 | ||
And the parties are deleted | ||
Then the `destinations` 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