Skip to content

Commit

Permalink
Merge pull request #265 from uktrade/LTD-3688-add/amend-units-of-meas…
Browse files Browse the repository at this point in the history
…urement

LTD-3688-add/amend-units-of-measurement
  • Loading branch information
markj0hnst0n authored Jul 4, 2024
2 parents 0d96206 + b438143 commit 2b80a62
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
12 changes: 11 additions & 1 deletion mail/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,19 @@ class UnitMapping(enum.Enum):
MTR = 57 # meters
LTR = 94 # litre
MTQ = 2 # meters_cubed
MIR = 74 # millilitre
MLT = 74 # millilitre
ITG = 30 # intangible
MGM = 111 # milligram
TON = 25 # tonne
MCG = 116 # microgram
MCL = 110 # microlitre

# These units below are the old values or LegacyUnitMapping that are
# not used going forward. They are kept here for backwards compatibility
MIM = 111 # milligram
MCM = 116 # microgram
MIR = 74 # millilitre
MCR = 110 # microlitre

@classmethod
def serializer_choices(cls):
Expand Down
37 changes: 36 additions & 1 deletion mail/tests/files/licence_payload_file
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,43 @@
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed2",
"name": "Stock",
"description": "",
"unit": "MIM",
"unit": "MGM",
"quantity": 11.0
},
{
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed3",
"name": "Metal",
"description": "",
"unit": "TON",
"quantity": 1.0
},
{
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed4",
"name": "Chemical",
"description": "",
"unit": "MCG",
"quantity": 20.0
},
{
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed5",
"name": "Chemical",
"description": "",
"unit": "MCL",
"quantity": 20.0
},
{
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed6",
"name": "Chemical",
"description": "",
"unit": "MLT",
"quantity": 20.0
},
{
"id": "f95ded2a-354f-46f1-a572-c7f97d63bed7",
"name": "Old Chemical",
"description": "",
"unit": "MIM",
"quantity": 20.0
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions mail/tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ def test_send_email_to_hmrc_e2e(self, mock_cache):
6\restrictions\Provisos may apply please see licence
7\line\1\\\\\Sporting shotgun\Q\\030\\10\\\\\\
8\line\2\\\\\Stock\Q\\111\\11.0\\\\\\
9\end\licence\8
10\fileTrailer\1"""
9\line\3\\\\\Metal\Q\\025\\1.0\\\\\\
10\line\4\\\\\Chemical\Q\\116\\20.0\\\\\\
11\line\5\\\\\Chemical\Q\\110\\20.0\\\\\\
12\line\6\\\\\Chemical\Q\\074\\20.0\\\\\\
13\line\7\\\\\Old Chemical\Q\\111\\20.0\\\\\\
14\end\licence\13
15\fileTrailer\1"""
assert body == expected_mail_body # nosec
encoded_reference_code = quote("GBSIEL/2020/0000001/P", safe="")
response = self.client.get(f"{reverse('mail:licence')}?id={encoded_reference_code}")
Expand Down
29 changes: 27 additions & 2 deletions mail/tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ def test_convert_code(self):
("MTR", 57),
("LTR", 94),
("MTQ", 2),
("MIR", 74),
("MLT", 74),
("ITG", 30),
("MGM", 111),
("TON", 25),
("MCG", 116),
("MCL", 110),
("MIM", 111),
("MCM", 116),
("MIR", 74),
("MCR", 110),
]

for code, value in data:
Expand All @@ -28,6 +35,24 @@ def test_convert_none(self):

def test_serializer_choices(self):
choices = UnitMapping.serializer_choices()
expected = ["NAR", "GRM", "KGM", "MTK", "MTR", "LTR", "MTQ", "MIR", "ITG", "MIM"]
expected = [
"NAR",
"GRM",
"KGM",
"MTK",
"MTR",
"LTR",
"MTQ",
"MLT",
"ITG",
"MGM",
"TON",
"MCG",
"MCL",
"MIM",
"MCM",
"MIR",
"MCR",
]

self.assertEqual(choices, expected)
18 changes: 14 additions & 4 deletions mail/tests/test_licence_to_edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ def test_single_siel(self):
+ "\n6\\restrictions\\Provisos may apply please see licence"
+ "\n7\\line\\1\\\\\\\\\\Sporting shotgun\\Q\\\\030\\\\10\\\\\\\\\\\\"
+ "\n8\\line\\2\\\\\\\\\\Stock\\Q\\\\111\\\\11.0\\\\\\\\\\\\"
+ "\n9\\end\\licence\\8"
+ "\n10\\fileTrailer\\1\n"
+ "\n9\\line\\3\\\\\\\\\\Metal\\Q\\\\025\\\\1.0\\\\\\\\\\\\"
+ "\n10\\line\\4\\\\\\\\\\Chemical\\Q\\\\116\\\\20.0\\\\\\\\\\\\"
+ "\n11\\line\\5\\\\\\\\\\Chemical\\Q\\\\110\\\\20.0\\\\\\\\\\\\"
+ "\n12\\line\\6\\\\\\\\\\Chemical\\Q\\\\074\\\\20.0\\\\\\\\\\\\"
+ "\n13\\line\\7\\\\\\\\\\Old Chemical\\Q\\\\111\\\\20.0\\\\\\\\\\\\"
+ "\n14\\end\\licence\\13"
+ "\n15\\fileTrailer\\1\n"
)

self.assertEqual(result, expected)
Expand Down Expand Up @@ -112,8 +117,13 @@ def test_update_edifact_file(self):
+ "\n8\\restrictions\\Provisos may apply please see licence"
+ "\n9\\line\\1\\\\\\\\\\Sporting shotgun\\Q\\\\030\\\\15\\\\\\\\\\\\"
+ "\n10\\line\\2\\\\\\\\\\Stock\\Q\\\\111\\\\11.0\\\\\\\\\\\\"
+ "\n11\\end\\licence\\8"
+ "\n12\\fileTrailer\\2\n"
+ "\n11\\line\\3\\\\\\\\\\Metal\\Q\\\\025\\\\1.0\\\\\\\\\\\\"
+ "\n12\\line\\4\\\\\\\\\\Chemical\\Q\\\\116\\\\20.0\\\\\\\\\\\\"
+ "\n13\\line\\5\\\\\\\\\\Chemical\\Q\\\\110\\\\20.0\\\\\\\\\\\\"
+ "\n14\\line\\6\\\\\\\\\\Chemical\\Q\\\\074\\\\20.0\\\\\\\\\\\\"
+ "\n15\\line\\7\\\\\\\\\\Old Chemical\\Q\\\\111\\\\20.0\\\\\\\\\\\\"
+ "\n16\\end\\licence\\13"
+ "\n17\\fileTrailer\\2\n"
)

self.assertEqual(result, expected)
Expand Down

0 comments on commit 2b80a62

Please sign in to comment.