Skip to content

Commit

Permalink
Merge pull request #2259 from uktrade/dev
Browse files Browse the repository at this point in the history
extended UAT release
  • Loading branch information
hnryjmes authored Oct 29, 2024
2 parents 5d85d9a + c3e9f79 commit 20db030
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 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
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
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 20db030

Please sign in to comment.