Skip to content

Commit

Permalink
Move the import into the class to avoid circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
saruniitr committed Dec 9, 2024
1 parent ed49b60 commit b768b39
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
3 changes: 2 additions & 1 deletion api/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from api.appeals.models import Appeal
from api.applications.exceptions import AmendmentError
from api.applications.managers import BaseApplicationManager
from api.applications.validators import StandardApplicationValidator
from api.applications.libraries.application_helpers import create_submitted_audit
from api.audit_trail.models import AuditType
from api.audit_trail import service as audit_trail_service
Expand Down Expand Up @@ -278,6 +277,8 @@ def create_amendment(self, user):

# Licence Applications
class StandardApplication(BaseApplication, Clonable):
from api.applications.validators import StandardApplicationValidator

GB = "GB"
NI = "NI"
GOODS_STARTING_POINT_CHOICES = [
Expand Down
5 changes: 3 additions & 2 deletions api/applications/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
CaseStatusEnum,
)
from api.users.enums import SystemUser
from api.users.models import ExporterUser
from api.users.models import BaseUser, ExporterUser
from api.users.tests.factories import BaseUserFactory


Expand Down Expand Up @@ -603,7 +603,8 @@ def test_clone_with_party_override(self):
@pytest.mark.requires_transactions
class TestStandardApplicationRaceConditions(TransactionTestCase):
def test_create_amendment_race_condition_success(self):
BaseUserFactory(id=SystemUser.id)
if not BaseUser.objects.filter(id=SystemUser.id).exists():
BaseUserFactory(id=SystemUser.id)

original_application = StandardApplicationFactory()

Expand Down
18 changes: 1 addition & 17 deletions api/applications/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db.models import Q

from api.applications.enums import ApplicationExportType
from api.core.model_mixins import BaseApplicationValidator
from api.goods.models import GoodDocument
from api.parties.models import PartyDocument

Expand Down Expand Up @@ -161,23 +162,6 @@ def siel_temporary_export_details_validator(application):
return None


class BaseApplicationValidator:
config = {}

def __init__(self, application):
self.application = application

def validate(self):
all_errors = {}
for entity, func in self.config.items():
error = func(self.application)
if error:
entity_errors = {entity: [error]}
all_errors = {**entity_errors, **all_errors}

return all_errors


class StandardApplicationValidator(BaseApplicationValidator):
config = {
"location": siel_locations_validator,
Expand Down
17 changes: 17 additions & 0 deletions api/core/model_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,20 @@ class Trackable:

def get_history(self, field):
raise NotImplementedError()


class BaseApplicationValidator:
config = {}

def __init__(self, application):
self.application = application

def validate(self):
all_errors = {}
for entity, func in self.config.items():
error = func(self.application)
if error:
entity_errors = {entity: [error]}
all_errors = {**entity_errors, **all_errors}

return all_errors

0 comments on commit b768b39

Please sign in to comment.