feat: account code extraction with zero-padding
This commit is contained in:
parent
54ee01c475
commit
e938e90284
@ -14,5 +14,15 @@ def parse_options(options_str):
|
||||
return options
|
||||
|
||||
|
||||
def get_account_code(options):
|
||||
km = options.get('KmManagment', 'Default')
|
||||
if km == 'Default' or not km.startswith('MG'):
|
||||
return None
|
||||
code = km[2:]
|
||||
if not code.isdigit():
|
||||
return None
|
||||
return code.zfill(8)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
|
||||
@ -14,3 +14,26 @@ class TestParseOptions:
|
||||
|
||||
def test_flag_without_value(self):
|
||||
assert kyofilter.parse_options("SomeFlag") == {"SomeFlag": "true"}
|
||||
|
||||
|
||||
class TestGetAccountCode:
|
||||
def test_five_digit_code_zero_padded_to_eight(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "MG12345"}) == "00012345"
|
||||
|
||||
def test_one_digit_code_zero_padded(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "MG1"}) == "00000001"
|
||||
|
||||
def test_eight_digit_code_unchanged(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "MG12345678"}) == "12345678"
|
||||
|
||||
def test_default_returns_none(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "Default"}) is None
|
||||
|
||||
def test_missing_key_returns_none(self):
|
||||
assert kyofilter.get_account_code({}) is None
|
||||
|
||||
def test_no_mg_prefix_returns_none(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "12345"}) is None
|
||||
|
||||
def test_non_numeric_code_returns_none(self):
|
||||
assert kyofilter.get_account_code({"KmManagment": "MGabc45"}) is None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user