Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
markj0hnst0n committed Jul 3, 2024
1 parent e306fb6 commit 3cbf462
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mail/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -213,6 +214,7 @@ class LegacyUnitCodeMapping(enum.Enum):
MIR = 74 # millilitre
MCR = 110 # microlitre


class MailReadStatuses(TextChoices):
READ = "READ"
UNREAD = "UNREAD"
Expand Down
4 changes: 3 additions & 1 deletion mail/libraries/lite_to_edifact_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions mail/tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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]
Expand All @@ -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)

0 comments on commit 3cbf462

Please sign in to comment.