From 3cbf46248faff45f45679e07ea9e0cda053d2fe7 Mon Sep 17 00:00:00 2001 From: "mark.j0hnst0n" Date: Wed, 3 Jul 2024 12:33:00 +0100 Subject: [PATCH] linting --- mail/enums.py | 2 ++ mail/libraries/lite_to_edifact_converter.py | 4 +++- mail/tests/test_enums.py | 7 +++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mail/enums.py b/mail/enums.py index 17c84c97..66cf87c4 100644 --- a/mail/enums.py +++ b/mail/enums.py @@ -205,6 +205,7 @@ def serializer_choices(cls): # Used by the API serializer for validation. return list(cls.__members__.keys()) + class LegacyUnitCodeMapping(enum.Enum): # These units below are the old values that are not used going forward # They are kept here for backwards compatibility @@ -213,6 +214,7 @@ class LegacyUnitCodeMapping(enum.Enum): MIR = 74 # millilitre MCR = 110 # microlitre + class MailReadStatuses(TextChoices): READ = "READ" UNREAD = "UNREAD" diff --git a/mail/libraries/lite_to_edifact_converter.py b/mail/libraries/lite_to_edifact_converter.py index f75d7b2b..ee74ea1e 100644 --- a/mail/libraries/lite_to_edifact_converter.py +++ b/mail/libraries/lite_to_edifact_converter.py @@ -31,9 +31,11 @@ class EdifactValidationError(Exception): pass + def get_class_attributes(cls): return [str(attr) for attr in dir(cls)] + def generate_lines_for_licence(licence: LicencePayload) -> Iterable[chieftypes._Record]: """Yield line tuples for a single licence, to use in a CHIEF message. @@ -138,7 +140,7 @@ def generate_lines_for_licence(licence: LicencePayload) -> Iterable[chieftypes._ ) controlled_by = "Q" # usage is controlled by quantity only quantity = commodity.get("quantity") - + if commodity["unit"] in get_class_attributes(LegacyUnitCodeMapping): qunit = LegacyUnitCodeMapping[commodity["unit"]] else: diff --git a/mail/tests/test_enums.py b/mail/tests/test_enums.py index 2dc0378e..86ebbfd6 100644 --- a/mail/tests/test_enums.py +++ b/mail/tests/test_enums.py @@ -24,7 +24,7 @@ def test_convert_code(self): for code, value in data: with self.subTest(code=code, value=value): self.assertEqual(value, UnitMapping[code].value) - + def test_convert_legacy_code(self): data = [ ("MIM", 111), @@ -40,7 +40,7 @@ def test_convert_legacy_code(self): def test_convert_none(self): with self.assertRaises(KeyError): UnitMapping[None] - + def test_convert_none_old(self): with self.assertRaises(KeyError): LegacyUnitCodeMapping[None] @@ -50,10 +50,9 @@ def test_serializer_choices(self): expected = ["NAR", "GRM", "KGM", "MTK", "MTR", "LTR", "MTQ", "MLT", "ITG", "MGM", "TON", "MCG", "MCL"] self.assertEqual(choices, expected) - + def test_serializer_choices_old(self): choices = list(LegacyUnitCodeMapping.__members__.keys()) expected = ["MIM", "MCM", "MIR", "MCR"] self.assertEqual(choices, expected) -