data: Metadata.human_name() treats _ like -.

This commit is contained in:
Brett Smith 2021-03-06 12:11:16 -05:00
parent b599ddee5d
commit a5ebc04f5d
2 changed files with 4 additions and 1 deletions

View file

@ -412,6 +412,7 @@ class Metadata(MutableMapping[MetaKey, MetaValue]):
'paypal-id': 'PayPal ID', 'paypal-id': 'PayPal ID',
'rt-id': 'Ticket', 'rt-id': 'Ticket',
} }
_HUMAN_TRANSLATIONS = str.maketrans('-_', ' ')
def __init__(self, source: MutableMapping[MetaKey, MetaValue]) -> None: def __init__(self, source: MutableMapping[MetaKey, MetaValue]) -> None:
self.meta = source self.meta = source
@ -479,7 +480,7 @@ class Metadata(MutableMapping[MetaKey, MetaValue]):
try: try:
retval = cls._HUMAN_NAMES[key] retval = cls._HUMAN_NAMES[key]
except KeyError: except KeyError:
retval = key.replace('-', ' ').title() retval = key.translate(cls._HUMAN_TRANSLATIONS).title()
retval = re.sub(r'\bId$', 'ID', retval) retval = re.sub(r'\bId$', 'ID', retval)
cls._HUMAN_NAMES[key] = retval cls._HUMAN_NAMES[key] = retval
return retval return retval

View file

@ -107,6 +107,8 @@ def test_first_link_bad_type_default(simple_txn, meta_value):
('receipt', 'Receipt'), ('receipt', 'Receipt'),
('rt-id', 'Ticket'), ('rt-id', 'Ticket'),
('tax-statement', 'Tax Statement'), ('tax-statement', 'Tax Statement'),
('meta_key', 'Meta Key'),
('meta_id', 'Meta ID'),
]) ])
def test_human_name(meta_name, expected): def test_human_name(meta_name, expected):
assert data.Metadata.human_name(meta_name) == expected assert data.Metadata.human_name(meta_name) == expected