Skip to content

Commit

Permalink
Merge branch 'master' into TP2000-460-fix-business-rule-checker-asser…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
stuaxo authored Aug 10, 2022
2 parents 625c7e9 + 2b52aac commit 25debc2
Show file tree
Hide file tree
Showing 107 changed files with 4,401 additions and 741 deletions.
14 changes: 12 additions & 2 deletions additional_codes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def __init__(self, *args, **kwargs):
Field("type"),
Field("start_date"),
Field("end_date"),
Submit("submit", "Save"),
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)

def clean(self):
Expand Down Expand Up @@ -122,7 +127,12 @@ def __init__(self, *args, **kwargs):
"start_date",
Field.textarea("description", rows=5),
DescriptionHelpBox(),
Submit("submit", "Save"),
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)

def clean(self):
Expand Down
7 changes: 6 additions & 1 deletion additional_codes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def test_additional_code_delete_form(factory, use_delete_form):
),
ids=view_urlpattern_ids,
)
def test_additional_codes_detail_views(view, url_pattern, valid_user_client):
def test_additional_codes_detail_views(
view,
url_pattern,
valid_user_client,
session_with_workbasket,
):
"""Verify that additional code detail views are under the url
additional_codes/ and don't return an error."""
model_overrides = {
Expand Down
14 changes: 12 additions & 2 deletions certificates/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def __init__(self, *args, **kwargs):
"start_date",
Field.textarea("description", rows=5),
DescriptionHelpBox(),
Submit("submit", "Save"),
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)

def clean_sid(self):
Expand Down Expand Up @@ -142,7 +147,12 @@ def __init__(self, *args, **kwargs):
"certificate_type",
"start_date",
"end_date",
Submit("submit", "Save"),
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)

def clean(self):
Expand Down
23 changes: 23 additions & 0 deletions certificates/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,26 @@ def test_validation_error_raised_for_duplicate_sid(session_with_workbasket):
f"Certificate with sid A01 and type {certificate_type} already exists."
in form.errors["sid"]
)


def test_certificate_description_valid_data():
certificate = factories.CertificateFactory.create()
data = {
"described_certificate": certificate.pk,
"description": "certifiably certified",
"validity_start_0": 1,
"validity_start_1": 1,
"validity_start_2": 2022,
}
form = forms.CertificateCreateDescriptionForm(data=data)

assert form.is_valid()


def test_certificate_description_invalid_data():
form = forms.CertificateCreateDescriptionForm(data={})

assert not form.is_valid()
assert "This field is required." in form.errors["described_certificate"]
assert "This field is required." in form.errors["description"]
assert "Enter the day, month and year" in form.errors["validity_start"]
55 changes: 54 additions & 1 deletion certificates/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from django.urls import reverse

from certificates import models
from certificates.views import CertificateDescriptionCreate
from certificates.views import CertificateList
from common.models.utils import override_current_transaction
from common.tests import factories
from common.tests.util import assert_model_view_renders
from common.tests.util import get_class_based_view_urls_matching_url
Expand All @@ -13,6 +15,8 @@
from common.views import TamatoListView
from common.views import TrackedModelDetailMixin

pytestmark = pytest.mark.django_db


@pytest.mark.parametrize(
"factory",
Expand Down Expand Up @@ -58,7 +62,12 @@ def test_certificate_create_form_creates_certificate_description_object(
),
ids=view_urlpattern_ids,
)
def test_certificate_detail_views(view, url_pattern, valid_user_client):
def test_certificate_detail_views(
view,
url_pattern,
valid_user_client,
session_with_workbasket,
):
"""Verify that certificate detail views are under the url certificates/ and
don't return an error."""
model_overrides = {
Expand All @@ -81,3 +90,47 @@ def test_certificate_list_view(view, url_pattern, valid_user_client):
"""Verify that certificate list view is under the url certificates/ and
doesn't return an error."""
assert_model_view_renders(view, url_pattern, valid_user_client)


# https://uktrade.atlassian.net/browse/TP2000-450 /PS-IGNORE
def test_description_create_get_initial():
"""Test that, where more than one version of a certificate exists,
get_initial returns only the current version."""
certificate = factories.CertificateFactory.create()
new_version = certificate.new_version(certificate.transaction.workbasket)
view = CertificateDescriptionCreate(
kwargs={
"certificate_type__sid": certificate.certificate_type.sid,
"sid": certificate.sid,
},
)
with override_current_transaction(new_version.transaction):
initial = view.get_initial()

assert initial["described_certificate"] == new_version


def test_description_create_get_context_data(valid_user_api_client):
"""Test that posting to certificate create endpoint with valid data returns
a 302 and creates new description matching certificate."""
certificate = factories.CertificateFactory.create(description=None)
new_version = certificate.new_version(certificate.transaction.workbasket)
url = reverse(
"certificate-ui-description-create",
args=(certificate.certificate_type.sid, certificate.sid),
)
post_data = {
"description": "certifiably certified",
"described_certificate": new_version.pk,
"validity_start_0": 1,
"validity_start_1": 1,
"validity_start_2": 2022,
}
assert not models.CertificateDescription.objects.exists()
response = valid_user_api_client.post(url, post_data)

assert response.status_code == 302
assert models.CertificateDescription.objects.filter(
described_certificate__sid=new_version.sid,
described_certificate__certificate_type__sid=new_version.certificate_type.sid,
).exists()
4 changes: 2 additions & 2 deletions certificates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CertificateCreateDescriptionMixin:

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["described_object"] = models.Certificate.objects.get(
context["described_object"] = models.Certificate.objects.current().get(
certificate_type__sid=(self.kwargs.get("certificate_type__sid")),
sid=(self.kwargs.get("sid")),
)
Expand All @@ -157,7 +157,7 @@ class CertificateDescriptionCreate(
):
def get_initial(self):
initial = super().get_initial()
initial["described_certificate"] = models.Certificate.objects.get(
initial["described_certificate"] = models.Certificate.objects.current().get(
certificate_type__sid=(self.kwargs.get("certificate_type__sid")),
sid=(self.kwargs.get("sid")),
)
Expand Down
114 changes: 114 additions & 0 deletions commodities/assets/commodities_envelope.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" schemaLocation="commodities_taric3.xsd" />
<xs:element name="envelope">
<xs:annotation>
<xs:documentation>Message envelope</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="header" type="Header" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="transaction" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="header" type="Header" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="status" minOccurs="0"/>
<xs:element name="app.message" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="abstract.message"/>
</xs:sequence>
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{5}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:complexType name="Header">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
<xs:simpleType name="MMIMessageType">
<xs:restriction base="xs:string">
<xs:maxLength value="500"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="abstract.message" abstract="true"/>
<xs:element name="abstract.ref" abstract="true"/>
<xs:element name="status">
<xs:complexType>
<xs:sequence>
<xs:element name="mmi.message" type="MMIMessageType" minOccurs="0"/>
<xs:element name="status.detail" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="business.ref" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="abstract.ref"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="binary" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="mime.type" type="xs:string" default="application/octet-stream"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="mmi.message" type="MMIMessageType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="category" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="error"/>
<xs:enumeration value="info"/>
<xs:enumeration value="warning"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="location" type="xs:string" use="required"/>
<xs:attribute name="code" type="xs:NMTOKEN" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="category" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ok"/>
<xs:enumeration value="error"/>
<xs:enumeration value="rejected"/>
<xs:enumeration value="warning"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="location" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

Loading

0 comments on commit 25debc2

Please sign in to comment.