Skip to content

Commit

Permalink
Merge pull request #178 from uktrade/LTD-3148-fix-trader-address
Browse files Browse the repository at this point in the history
 LTD-3148-fix-trader-address
  • Loading branch information
depsiatwal authored Dec 16, 2022
2 parents 42d85e4 + cb1d20b commit 37e6195
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions mail/libraries/lite_to_edifact_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def generate_lines_for_licence(licence: LicencePayload) -> Iterable[chieftypes._

if licence.action != LicenceActionEnum.CANCEL:
trader = payload.get("organisation")
trader = sanitize_foreign_trader_address(trader)

yield chieftypes.Trader(
rpa_trader_id=trader.get("eori_number", ""),
Expand Down
49 changes: 47 additions & 2 deletions mail/tests/test_licence_to_edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,59 @@ def test_foreign_trader_address_sanitize(self, address_line_1, expected_trader_l
foreign_trader_line = edifact_file.split("\n")[4]
self.assertEqual(foreign_trader_line, expected_trader_line)

@parameterized.expand(
[
(
"TEST12345 IFailedTooLong Ltd - Registered address",
"BIGMAM MANOR",
"NEW TESCO LANE",
"HARROW",
"MIDDLESEX",
"3\\trader\\\\GB123456789000\\20200602\\20220602\\Advanced Firearms Limited\\TEST12345 IFailedTooLong Ltd -\\Registered address\\NEW TESCO LANE\\HARROW\\MIDDLESEX\\GU40 2LX",
),
(
"this is short address",
"BIGMAM MANOR",
"NEW TESCO LANE",
"HARROW",
"MIDDLESEX",
"3\\trader\\\\GB123456789000\\20200602\\20220602\\Advanced Firearms Limited\\this is short address\\BIGMAM MANOR\\NEW TESCO LANE\\HARROW\\MIDDLESEX\\GU40 2LX",
),
]
)
def test_trader_address_sanitize(
self, address_line_1, address_line_2, address_line_3, address_line_4, address_line_5, expected_trader_line
):
lp = LicencePayload.objects.get()
lp.is_processed = True
lp.save()
payload = self.licence_payload_json.copy()
payload["licence"]["organisation"]["name"] = "Advanced Firearms Limited"
payload["licence"]["organisation"]["address"]["line_1"] = address_line_1
payload["licence"]["organisation"]["address"]["line_2"] = address_line_2
payload["licence"]["organisation"]["address"]["line_3"] = address_line_3
payload["licence"]["organisation"]["address"]["line_4"] = address_line_4
payload["licence"]["organisation"]["address"]["line_5"] = address_line_5
LicencePayload.objects.create(
reference="GBSIEL/2021/0000001/P",
data=payload["licence"],
action=LicenceActionEnum.INSERT,
lite_id="00000000-0000-0000-0000-9792333e8cc8",
)
licences = LicencePayload.objects.filter(is_processed=False)

edifact_file = licences_to_edifact(licences, 1234, "FOO")
trader_line = edifact_file.split("\n")[2]
self.assertEqual(trader_line, expected_trader_line)


class GenerateLinesForLicenceTest(LiteHMRCTestClient):
def test_open_licence_with_country_group(self):
data = {
"start_date": "1",
"end_date": "2",
"organisation": {
"address": {},
"address": {"line_1": "Required line 1 address"},
},
"address": {},
"type": "oiel", # One of the OPEN_LICENCES.
Expand All @@ -202,7 +247,7 @@ def test_open_licence_with_multiple_countries(self):
"start_date": "1",
"end_date": "2",
"organisation": {
"address": {},
"address": {"line_1": "Required line 1 address"},
},
"address": {},
"type": "oiel", # One of the OPEN_LICENCES.
Expand Down

0 comments on commit 37e6195

Please sign in to comment.