Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UAT release #2230

Merged
merged 7 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion api/applications/views/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
from api.staticdata.statuses.models import CaseSubStatus
from api.users.libraries.notifications import get_case_notifications
from api.users.models import ExporterUser
from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case
from lite_routing.routing_rules_internal.flagging_engine import apply_flagging_rules_to_case

from lite_routing.routing_rules_internal.routing_engine import run_routing_rules

Expand Down
79 changes: 0 additions & 79 deletions api/applications/views/tests/test_parties.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,85 +84,6 @@ def setUp(self):

self.party_on_application = PartyOnApplicationFactory(application=self.application)

@parameterized.expand(
[
(
{"name": "end_user", "address": "1 Example Street"},
True,
{
"name": [
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
]
},
),
(
{"name": "end\auser", "address": "1 Example Street"},
True,
{
"name": [
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
]
},
),
(
{"name": "end£user", "address": "1 Example Street"},
True,
{
"name": [
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
]
},
),
(
{"name": "end user", "address": "1_Example Street"},
True,
{
"address": [
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
]
},
),
(
{"name": "end user", "address": "1\aExample Street"},
True,
{
"address": [
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
]
},
),
(
{"name": "end_user", "address": "1\aExample Street"},
True,
{
"name": [
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
],
"address": [
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
],
},
),
]
)
def test_party_post_invalid(self, data, error, error_message):
data["country"] = {"id": "FR", "name": "France"}
self.url = reverse(
"applications:party",
kwargs={"pk": str(self.application.pk), "party_pk": str(self.party_on_application.party.pk)},
)
party = Party.objects.get(id=self.party_on_application.party.pk)
versions = Version.objects.get_for_object(party)
self.assertEqual(versions.count(), 0)

self.application.status = CaseStatus.objects.get(status="draft")
self.application.save()

response = self.client.put(self.url, **self.exporter_headers, data=data)
if error:
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.json()["errors"], error_message)

@parameterized.expand(
[
({"name": "end user", "address": "1 Example Street"},),
Expand Down
2 changes: 1 addition & 1 deletion api/cases/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api.cases.models import Case
from api.staticdata.statuses.enums import CaseStatusEnum
from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status
from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case
from lite_routing.routing_rules_internal.flagging_engine import apply_flagging_rules_to_case


@receiver(pre_save)
Expand Down
20 changes: 0 additions & 20 deletions api/core/tests/test_validators.py

This file was deleted.

25 changes: 0 additions & 25 deletions api/core/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.utils.deconstruct import deconstructible
from rest_framework.exceptions import ValidationError
import re
from api.staticdata.control_list_entries.models import ControlListEntry


Expand All @@ -22,27 +21,3 @@ def __call__(self, value):
ControlListEntry.objects.get(rating=value)
except ControlListEntry.DoesNotExist:
raise ValidationError(self.message, code=self.code)


class EdifactStringValidator:
message = "Undefined Error"
regex_string = r"^[a-zA-Z0-9 .,\-\)\(\/'+:=\?\!\"%&\*;\<\>]+$"

def __call__(self, value):
match_regex = re.compile(self.regex_string)
is_value_valid = bool(match_regex.match(value))
if not is_value_valid:
raise ValidationError(self.message)


class GoodNameValidator(EdifactStringValidator):
message = "Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"


class PartyAddressValidator(EdifactStringValidator):
regex_string = re.compile(r"^[a-zA-Z0-9 .,\-\)\(\/'+:=\?\!\"%&\*;\<\>\r\n]+$")
message = "Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"


class PartyNameValidator(EdifactStringValidator):
message = "Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes"
5 changes: 4 additions & 1 deletion api/flags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
from api.queries.end_user_advisories.models import EndUserAdvisoryQuery
from api.queries.goods_query.models import GoodsQuery

from api.workflow.flagging_rules_automation import apply_flagging_rule_to_all_open_cases, apply_flagging_rule_for_flag
from lite_routing.routing_rules_internal.flagging_engine import (
apply_flagging_rule_to_all_open_cases,
apply_flagging_rule_for_flag,
)

from lite_content.lite_api import strings

Expand Down
11 changes: 5 additions & 6 deletions api/goods/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from rest_framework.relations import PrimaryKeyRelatedField
from api.core.helpers import str_to_bool
from api.core.serializers import KeyValueChoiceField, ControlListEntryField, GoodControlReviewSerializer
from api.core.validators import GoodNameValidator
from api.documents.libraries.process_document import process_document
from api.goods.enums import (
FirearmCategory,
Expand Down Expand Up @@ -308,7 +307,7 @@ def update(self, instance, validated_data):

class GoodListSerializer(serializers.Serializer):
id = serializers.UUIDField()
name = serializers.CharField(validators=[GoodNameValidator()])
name = serializers.CharField()
description = serializers.CharField()
control_list_entries = ControlListEntrySerializer(many=True, allow_null=True)
part_number = serializers.CharField()
Expand Down Expand Up @@ -357,7 +356,7 @@ class GoodCreateSerializer(serializers.ModelSerializer):
Because of this, each 'get' override must check the instance type before creating queries
"""

name = serializers.CharField(error_messages={"blank": "Enter a product name"}, validators=[GoodNameValidator()])
name = serializers.CharField(error_messages={"blank": "Enter a product name"})
description = serializers.CharField(max_length=280, allow_blank=True, required=False)
is_good_controlled = KeyValueChoiceField(choices=GoodControlled.choices, allow_null=True)
control_list_entries = ControlListEntryField(required=False, many=True, allow_null=True, allow_empty=True)
Expand Down Expand Up @@ -690,7 +689,7 @@ def create(self, validated_data):
class GoodDocumentViewSerializer(serializers.Serializer):
id = serializers.UUIDField()
created_at = serializers.DateTimeField()
name = serializers.CharField(validators=[GoodNameValidator()])
name = serializers.CharField()
description = serializers.CharField()
user = ExporterUserSimpleSerializer()
s3_key = serializers.SerializerMethodField()
Expand Down Expand Up @@ -788,7 +787,7 @@ class Meta:

class GoodSerializerInternal(serializers.Serializer):
id = serializers.UUIDField()
name = serializers.CharField(validators=[GoodNameValidator()])
name = serializers.CharField()
description = serializers.CharField()
part_number = serializers.CharField()
no_part_number_comments = serializers.CharField()
Expand Down Expand Up @@ -871,7 +870,7 @@ def get_user(self, instance):

class GoodSerializerExporter(serializers.Serializer):
id = serializers.UUIDField()
name = serializers.CharField(validators=[GoodNameValidator()])
name = serializers.CharField()
description = serializers.CharField()
control_list_entries = ControlListEntryField(many=True)
part_number = serializers.CharField()
Expand Down
48 changes: 0 additions & 48 deletions api/goods/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,6 @@ def test_validate_good_internal_name_valid(self, name):
[
("", "This field may not be blank."),
("\r\n", "This field may not be blank."),
(
"good\rname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good\nname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good\r\nname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good_name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good$name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good@name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
]
)
def test_validate_good_internal_name_invalid(self, name, error_message):
Expand Down Expand Up @@ -258,30 +234,6 @@ def test_validate_good_exporter_name_valid(self, address):
[
("", "This field may not be blank."),
("\r\n", "This field may not be blank."),
(
"good\rname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good\nname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good\r\nname",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good_name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good$name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"good@name",
"Product name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
]
)
def test_validate_good_exporter_name_invalid(self, name, error_message):
Expand Down
2 changes: 1 addition & 1 deletion api/organisations/views/organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from api.staticdata.statuses.libraries.get_case_status import get_case_status_by_status
from api.staticdata.statuses.models import CaseStatus
from api.users.enums import UserType
from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case
from lite_routing.routing_rules_internal.flagging_engine import apply_flagging_rules_to_case


class OrganisationsList(generics.ListCreateAPIView):
Expand Down
5 changes: 2 additions & 3 deletions api/parties/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from api.cases.enums import CaseTypeSubTypeEnum
from api.core.serializers import KeyValueChoiceField, CountrySerializerField
from api.core.validators import PartyAddressValidator, PartyNameValidator
from api.documents.libraries.process_document import process_document
from api.flags.serializers import FlagSerializer
from api.goods.enums import PvGrading
Expand All @@ -15,8 +14,8 @@


class PartySerializer(serializers.ModelSerializer):
name = serializers.CharField(error_messages=PartyErrors.NAME, validators=[PartyNameValidator()])
address = serializers.CharField(error_messages=PartyErrors.ADDRESS, validators=[PartyAddressValidator()])
name = serializers.CharField(error_messages=PartyErrors.NAME)
address = serializers.CharField(error_messages=PartyErrors.ADDRESS)
country = CountrySerializerField()
website = serializers.CharField(required=False, allow_blank=True)
signatory_name_euu = serializers.CharField(allow_blank=True)
Expand Down
57 changes: 0 additions & 57 deletions api/parties/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,6 @@ def test_validate_party_address_valid(self, address):
@parameterized.expand(
[
("\r\n", "Enter an address"),
(
"party\address",
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party-\waddress",
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party_address",
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party$address",
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party@address",
"Address must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
]
)
def test_validate_party_address_invalid(self, address, error_message):
Expand Down Expand Up @@ -107,40 +87,3 @@ def test_validate_party_name_valid(self, name):
partial=True,
)
self.assertTrue(serializer.is_valid())

@parameterized.expand(
[
(
"party\aname",
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party-\wname",
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party_name",
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party$name",
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
(
"party@name",
"Party name must only include letters, numbers, and common special characters such as hyphens, brackets and apostrophes",
),
]
)
def test_party_name_invalid(self, name, error_message):
serializer = PartySerializer(
data={"name": name},
partial=True,
)
self.assertFalse(serializer.is_valid())
serializer_error = serializer.errors["name"]
self.assertEqual(len(serializer_error), 1)
self.assertEqual(
str(serializer_error[0]),
error_message,
)
2 changes: 1 addition & 1 deletion api/queries/end_user_advisories/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from api.queries.end_user_advisories.models import EndUserAdvisoryQuery
from api.queries.end_user_advisories.serializers import EndUserAdvisoryViewSerializer, EndUserAdvisoryListSerializer
from api.users.libraries.notifications import get_case_notifications
from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case
from lite_routing.routing_rules_internal.flagging_engine import apply_flagging_rules_to_case


class EndUserAdvisoriesList(ListAPIView):
Expand Down
Loading