Skip to content

Commit

Permalink
Merge pull request #2260 from uktrade/uat
Browse files Browse the repository at this point in the history
PROD release
  • Loading branch information
hnryjmes authored Oct 31, 2024
2 parents 935cec1 + 20db030 commit 420043e
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 56 deletions.
7 changes: 2 additions & 5 deletions api/cases/tests/test_rerun_routing_rules.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pytest
import unittest

from django.urls import reverse
from rest_framework import status

from api.audit_trail.enums import AuditType
from api.audit_trail.models import Audit
from api.staticdata.statuses.enums import CaseStatusEnum
from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status
from api.staticdata.statuses.models import CaseStatus
from api.workflow.routing_rules.models import RoutingRule
from test_helpers.clients import DataTestClient


Expand All @@ -27,6 +23,7 @@ def setUp(self):
additional_rules=[],
)

@unittest.skip("Skipping due to backwards compatability issues")
def test_rules_rerun(self):
self.case.queues.set([self.other_queue.id])

Expand Down
2 changes: 1 addition & 1 deletion api/organisations/caseworker/views/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
)
self.data = {
"role": Roles.EXPORTER_ADMINISTRATOR_ROLE_ID,
"email": self.faker.email(),
"email": self.faker.unique.email(),
"sites": [self.organisation.primary_site.id],
"phone_number": "+441234567895",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,72 @@ def populate_control_list_entries(apps, schema_editor):
those that are parents to newly add CLEs via migration as migration runs first
"""
ratings = (
"1C35023",
"1C35029",
"1C3504",
"1C35065",
"1C35066",
"1C35067",
"1C35068",
"1C35069",
"1C35070",
"1C35071",
"1C35072",
"1C35073",
"1C35074",
"1C35075",
"1C35076",
"1C35077",
"1C35078",
"1C35079",
"1C35080",
"1C35081",
"1C35082",
"1C35083",
"1C35084",
"1C35085",
"1C35086",
"1C35087",
"1C35088",
"1C35089",
("1C35023", "45da2c59-d371-412d-8a62-2208ab676e30"),
("1C35029", "e96122e1-6725-495d-84ab-a35fe461be92"),
("1C3504", "e68b01d3-5042-4510-9b88-73cb98e45fbc"),
("1C35065", "f241e745-cdeb-4faa-a2a7-98125aa96fb0"),
("1C35066", "bca1cba3-7790-4da5-8ea8-e09c34743610"),
("1C35067", "9aec94d8-dd93-42f8-9a83-65af03762cef"),
("1C35068", "85b81dab-3859-4e7f-a92f-7e1d8daeb1da"),
("1C35069", "bee397e1-f5a4-49fd-bdf0-e98aea5cb5f1"),
("1C35070", "75fa569e-9123-45d0-95ad-a7beddba17cb"),
("1C35071", "6e4e3024-0ea1-4675-b777-583173c45ad4"),
("1C35072", "d05172be-1ccd-4c82-977a-2f9516990321"),
("1C35073", "2b5c19ef-d5a8-407c-ac7e-cdd2d59bc72a"),
("1C35074", "c51f7b0c-026c-473b-bb69-c11e4c2fc376"),
("1C35075", "de85dc72-5e30-47d7-af50-b8c4f75b7047"),
("1C35076", "d75b13f4-2732-418c-b723-3537cf6f1675"),
("1C35077", "5d856f38-e97c-43d6-9881-a55f3fb65726"),
("1C35078", "29aee271-0b0c-4ff3-a762-a3880520c734"),
("1C35079", "c0c809e3-68bc-4f42-9ea3-75d5357b874e"),
("1C35080", "4922b413-213e-4139-a38c-53dd6c1a0ef9"),
("1C35081", "9b8b92e5-d190-4a35-98e6-6a2e3f90e290"),
("1C35082", "974757c1-3de7-49a3-bbba-10fdd63379be"),
("1C35083", "852aff79-28dc-4081-afde-17451a177a40"),
("1C35084", "d08d0a82-1751-433f-ac2b-114901ca08cb"),
("1C35085", "61a6131c-c501-48d2-952f-85c271469f48"),
("1C35086", "7db5f50b-6129-4281-96ea-1496a351147b"),
("1C35087", "5d088e66-db5b-4506-8b7b-9b53eaca8021"),
("1C35088", "f11f0eb7-04e5-4fda-aafd-124d07fc95a2"),
("1C35089", "95747628-147e-4376-be97-751032cc0e9b"),
)
family_category = "Dual-Use List"
ControlListEntry = apps.get_model("control_list_entries", "ControlListEntry")

with transaction.atomic():
great_grandparent_cle, created = ControlListEntry.objects.get_or_create(
id="e1c5cdcb-d72d-49fa-85c7-b0a01678a9e3",
rating="1",
text="Special Materials and Related Equipment",
parent_id=None,
category=family_category,
controlled=True,
)
grandparent_cle, created = ControlListEntry.objects.get_or_create(
id="d296d395-e122-4766-b834-5d9564f5e886",
rating="1C",
text="Materials",
parent_id=great_grandparent_cle.id,
category=family_category,
controlled=True,
)
parent_cle, created = ControlListEntry.objects.get_or_create(
id="29b46846-175c-4018-bf0f-f9b5ad145b9c",
rating="1C350",
text="Chemicals that may be used as precursors for toxic chemical agents, and chemical mixtures",
parent_id=grandparent_cle.id,
category=family_category,
controlled=True,
)

for rating in ratings:
for rating, id in ratings:
ControlListEntry.objects.get_or_create(
rating=rating, text=rating, parent_id=parent_cle.id, category=family_category, controlled=True
id=id,
rating=rating,
text=rating,
parent_id=parent_cle.id,
category=family_category,
controlled=True,
)

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
def populate_control_list_entries(apps, schema_editor):
ControlListEntry = apps.get_model("control_list_entries", "ControlListEntry")

great_grandparent_cle, _ = ControlListEntry.objects.update_or_create(
id="ce17c22f-cc8c-4fa5-af3a-92c5310a9a46",
rating="5",
parent_id=None,
category="Dual-Use List",
controlled=True,
defaults={"text": "Telecommunications and Information Security"},
)
grandparent_cle, _ = ControlListEntry.objects.update_or_create(
id="addb336b-4ef2-4515-b1ea-493f11f95b03",
rating="5P1",
text="Telecommunications",
parent_id=great_grandparent_cle.id,
category="Dual-Use List",
controlled=True,
)
parent_cle, _ = ControlListEntry.objects.update_or_create(
id="f7ecac05-ef4c-4724-a89f-0972d449bc63",
rating="5D1",
parent_id=grandparent_cle.id,
category="Dual-Use List",
Expand Down
6 changes: 2 additions & 4 deletions api/users/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import factory

from faker import Faker


from api.organisations.tests.factories import OrganisationFactory
from api.users import models
from api.users.enums import UserType, UserStatuses
from api.users.models import Role, UserOrganisationRelationship
from api.teams.tests.factories import TeamFactory

faker = Faker()
from test_helpers.faker import faker


class BaseUserFactory(factory.django.DjangoModelFactory):
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
email = factory.LazyAttribute(lambda n: faker.email())
email = factory.LazyAttribute(lambda n: faker.unique.email())

class Meta:
model = models.BaseUser
Expand Down
2 changes: 1 addition & 1 deletion lite_routing
17 changes: 8 additions & 9 deletions test_helpers/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import django.utils.timezone
from django.db import connection
from django.test import override_settings
from faker import Faker
from rest_framework.test import APITestCase, URLPatternsTestCase, APIClient
import pytest

Expand Down Expand Up @@ -84,6 +83,7 @@
from api.teams.models import Team
from api.users.tests.factories import GovUserFactory
from test_helpers import colours
from test_helpers.faker import faker
from api.users.enums import SystemUser, UserType
from api.users.libraries.user_to_token import user_to_token
from api.users.models import ExporterUser, UserOrganisationRelationship, BaseUser, GovUser, Role
Expand All @@ -96,11 +96,6 @@ class Static:
seeded = False


# Instantiating this once so that we have a single instance across all tests allowing us to use things like .unique
# and we can guarantee that we will always have unique values even if we use things like `setUpClass`.
faker = Faker()


class DataTestClient(APITestCase, URLPatternsTestCase):
"""
Test client which creates seeds the database with system data and sets up an initial organisation and user
Expand All @@ -110,6 +105,8 @@ class DataTestClient(APITestCase, URLPatternsTestCase):
client = APIClient
faker = faker # Assigning this to the class as `self.faker` is expected in tests

INITIAL_QUEUE_ID = uuid.uuid4()

@classmethod
def setUpClass(cls):
"""Run seed operations ONCE for the entire test suite."""
Expand Down Expand Up @@ -163,7 +160,7 @@ def setUp(self):
"HTTP_ORGANISATION_ID": str(self.hmrc_organisation.id),
}

self.queue = self.create_queue("Initial Queue", self.team)
self.queue = self.create_queue("Initial Queue", self.team, pk=self.INITIAL_QUEUE_ID)

if settings.TIME_TESTS:
self.tick = timezone.localtime()
Expand Down Expand Up @@ -291,8 +288,10 @@ def create_case_note_mention(case_note: CaseNote, user: GovUser):
return case_note_mention

@staticmethod
def create_queue(name: str, team: Team):
queue = Queue(name=name, team=team)
def create_queue(name: str, team: Team, pk=None):
if not pk:
pk = uuid.uuid4()
queue = Queue(id=pk, name=name, team=team)
queue.save()
return queue

Expand Down
6 changes: 6 additions & 0 deletions test_helpers/faker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from faker import Faker


# Instantiating this once so that we have a single instance across all tests allowing us to use things like .unique
# and we can guarantee that we will always have unique values even if we use things like `setUpClass`.
faker = Faker()
8 changes: 3 additions & 5 deletions test_helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

from importlib import import_module, reload

from faker import Faker

from django.conf import settings
from django.urls import clear_url_caches

from test_helpers.faker import faker

from api.core.constants import Roles
from api.flags.enums import SystemFlags
from api.staticdata.countries.models import Country
from api.users.models import ExporterUser, UserOrganisationRelationship

faker = Faker()


def generate_key_value_pair(key, choices):
"""
Expand All @@ -37,7 +35,7 @@ def create_exporter_users(organisation, quantity=1, role_id=Roles.EXPORTER_EXPOR
users = []

for i in range(quantity):
user, created = ExporterUser.objects.get_or_create(email=faker.email())
user, created = ExporterUser.objects.get_or_create(email=faker.unique.email())
if created:
user.first_name = faker.first_name()
user.last_name = faker.last_name()
Expand Down

0 comments on commit 420043e

Please sign in to comment.