From bba298c635b13ff7346301d02b4fac07d06fcd23 Mon Sep 17 00:00:00 2001 From: Kevin Carrogan Date: Wed, 28 Aug 2024 14:09:40 +0100 Subject: [PATCH] Move submitted_at as an optional factory attribute to set --- api/applications/tests/factories.py | 7 ++--- .../v2/tests/bdd/test_licence_decisions.py | 21 ++++++++++--- .../v2/tests/bdd/test_siel_applications.py | 30 ++++++++++++++----- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/api/applications/tests/factories.py b/api/applications/tests/factories.py index 2d183a712..13bafaa60 100644 --- a/api/applications/tests/factories.py +++ b/api/applications/tests/factories.py @@ -1,4 +1,3 @@ -import datetime import factory from faker import Faker @@ -61,11 +60,11 @@ class Meta: @classmethod def _create(cls, model_class, *args, **kwargs): obj = model_class(*args, **kwargs) + obj.status = get_case_status_by_status(CaseStatusEnum.SUBMITTED) if "status" in kwargs and isinstance(kwargs["status"], CaseStatus): obj.status = kwargs["status"] - else: - obj.status = get_case_status_by_status(CaseStatusEnum.SUBMITTED) - obj.submitted_at = datetime.datetime.now() + if "submitted_at" in kwargs: + obj.submitted_at = kwargs["submitted_at"] obj.save() return obj diff --git a/api/data_workspace/v2/tests/bdd/test_licence_decisions.py b/api/data_workspace/v2/tests/bdd/test_licence_decisions.py index 098969c19..1505afd69 100644 --- a/api/data_workspace/v2/tests/bdd/test_licence_decisions.py +++ b/api/data_workspace/v2/tests/bdd/test_licence_decisions.py @@ -1,3 +1,4 @@ +import datetime import pytest import uuid @@ -44,7 +45,10 @@ def withdrawn_time(): @given("a SIEL application that has been withdrawn by the exporter", target_fixture="application") def withdrawn_siel_application(api_client, exporter_headers, organisation, withdrawn_time): - submitted_application = StandardApplicationFactory(organisation=organisation) + submitted_application = StandardApplicationFactory( + organisation=organisation, + submitted_at=datetime.datetime.now(), + ) change_status_url = reverse( "exporter_applications:change_status", kwargs={ @@ -83,7 +87,10 @@ def licence_decision_time(licence_decisions_data, withdrawn_time): @given("a SIEL application that has a licence issued", target_fixture="application") def application_with_licence_issued(organisation, api_client, gov_headers, gov_user, issued_time): - submitted_application = StandardApplicationFactory(organisation=organisation) + submitted_application = StandardApplicationFactory( + organisation=organisation, + submitted_at=datetime.datetime.now(), + ) finalise_application_url = reverse( "applications:finalise", kwargs={ @@ -161,7 +168,10 @@ def refused_time(): @given("a SIEL application that has a licence refused", target_fixture="application") def application_with_licence_refused(organisation, api_client, gov_headers, gov_user, refused_time): - submitted_application = StandardApplicationFactory(organisation=organisation) + submitted_application = StandardApplicationFactory( + organisation=organisation, + submitted_at=datetime.datetime.now(), + ) finalise_application_url = reverse( "applications:finalise", kwargs={ @@ -230,7 +240,10 @@ def nlr_time(): @given("a SIEL application that is NLR", target_fixture="application") def nlr_siel_application(gov_user, organisation, api_client, gov_headers, nlr_time): - submitted_application = StandardApplicationFactory(organisation=organisation) + submitted_application = StandardApplicationFactory( + organisation=organisation, + submitted_at=datetime.datetime.now(), + ) FinalAdviceFactory(user=gov_user, case=submitted_application, type=AdviceType.NO_LICENCE_REQUIRED) letter_layout = LetterLayoutFactory(id=uuid.UUID(int=1)) template = LetterTemplateFactory( diff --git a/api/data_workspace/v2/tests/bdd/test_siel_applications.py b/api/data_workspace/v2/tests/bdd/test_siel_applications.py index 26f8e784c..812a99e72 100644 --- a/api/data_workspace/v2/tests/bdd/test_siel_applications.py +++ b/api/data_workspace/v2/tests/bdd/test_siel_applications.py @@ -1,3 +1,4 @@ +import datetime import pytest from django.urls import reverse @@ -34,7 +35,9 @@ def draft_application_not_presented(unpage_data, siel_applications_list_url): @given("a submitted SIEL application without an amendment", target_fixture="siel_application") def siel_application_without_an_amendment(): - return StandardApplicationFactory() + return StandardApplicationFactory( + submitted_at=datetime.datetime.now(), + ) @then("it is presented as a single SIEL application", target_fixture="siel_application_data") @@ -51,8 +54,13 @@ def siel_application_id_of_itself(siel_application, siel_application_data): @given("a submitted SIEL application that has been amended", target_fixture="original_siel_application") def siel_application_with_an_amendment(): - original_siel_application = StandardApplicationFactory() - StandardApplicationFactory(amendment_of=original_siel_application) + original_siel_application = StandardApplicationFactory( + submitted_at=datetime.datetime.now(), + ) + StandardApplicationFactory( + amendment_of=original_siel_application, + submitted_at=datetime.datetime.now(), + ) return original_siel_application @@ -63,8 +71,16 @@ def siel_application_has_first_id_in_amendment_chain(original_siel_application, @given("a submitted SIEL application with multiple amendments", target_fixture="original_siel_application") def siel_application_with_multiple_amendments(): - original_siel_application = StandardApplicationFactory() - next_siel_application = StandardApplicationFactory(amendment_of=original_siel_application) - another_siel_application = StandardApplicationFactory(amendment_of=next_siel_application) - StandardApplicationFactory(amendment_of=another_siel_application) + original_siel_application = StandardApplicationFactory( + submitted_at=datetime.datetime.now(), + ) + next_siel_application = StandardApplicationFactory( + amendment_of=original_siel_application, + submitted_at=datetime.datetime.now(), + ) + another_siel_application = StandardApplicationFactory( + amendment_of=next_siel_application, + submitted_at=datetime.datetime.now(), + ) + StandardApplicationFactory(amendment_of=another_siel_application, submitted_at=datetime.datetime.now()) return original_siel_application