Skip to content

Commit

Permalink
Merge pull request #120 from uktrade/ltd-2187-Consider-updated-refere…
Browse files Browse the repository at this point in the history
…nce-naming

LTD-2187: Update licence reference extraction to consider new naming scheme
  • Loading branch information
saruniitr authored Apr 7, 2022
2 parents 646149b + 5e81257 commit 1c4b371
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions mail/libraries/lite_to_edifact_converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import logging
import textwrap

Expand Down Expand Up @@ -216,8 +217,14 @@ def licences_to_edifact(licences: QuerySet, run_number: int) -> str:


def get_transaction_reference(licence_reference: str) -> str:
licence_reference = licence_reference.split("/", 1)[1]
return licence_reference.replace("/", "")
if licence_reference.startswith("GB"):
licence_reference = licence_reference.split("/", 1)[1]
return licence_reference.replace("/", "")
else:
match_first_digit = re.search(r"\d", licence_reference)
if not match_first_digit:
raise ValueError("Invalid Licence reference")
return licence_reference[match_first_digit.start() :].replace("-", "")


def sanitize_foreign_trader_address(trader):
Expand Down
14 changes: 12 additions & 2 deletions mail/tests/test_licence_to_edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ def test_licence_is_marked_as_processed_after_sending(self, send):
self.single_siel_licence_payload.refresh_from_db()
self.assertEqual(self.single_siel_licence_payload.is_processed, True)

def test_ref(self):
self.assertEqual(get_transaction_reference("GBSIEL/2020/0000001/P"), "20200000001P")
@parameterized.expand(
[
("GBSIEL/2020/0000001/P", "20200000001P"),
("SIE22-0000025-01", "22000002501"),
]
)
def test_extract_reference(self, licence_reference, expected_reference):
self.assertEqual(get_transaction_reference(licence_reference), expected_reference)

def test_invalid_licence_reference_raises_value_error(self):
with self.assertRaises(ValueError):
get_transaction_reference("SIE-INVALID-REF")

def test_update_edifact_file(self):
lp = LicencePayload.objects.get()
Expand Down

0 comments on commit 1c4b371

Please sign in to comment.