mirror of
https://github.com/craigerl/aprsd.git
synced 2025-03-07 03:48:31 -05:00
Fixed email shortcut lookup
This patch fixes the email.get_email_from_shortcut. It ensures that if the lookup isn't found in the shortcut list, it simply returns the original value. This patch also adds a unit test to specifically test this function to always return the correct value.
This commit is contained in:
parent
f976a1c320
commit
9f4cc27a11
@ -112,9 +112,11 @@ def validate_shortcuts(config):
|
||||
LOG.info("Available shortcuts: {}".format(config["shortcuts"]))
|
||||
|
||||
|
||||
def get_email_from_shortcut(shortcut):
|
||||
if shortcut in CONFIG.get("shortcuts", None):
|
||||
return CONFIG["shortcuts"].get(shortcut, None)
|
||||
def get_email_from_shortcut(addr):
|
||||
if CONFIG.get("shortcuts", False):
|
||||
return CONFIG["shortcuts"].get(addr, addr)
|
||||
else:
|
||||
return addr
|
||||
|
||||
|
||||
def validate_email_config(config, disable_validation=False):
|
||||
|
25
tests/test_email.py
Normal file
25
tests/test_email.py
Normal file
@ -0,0 +1,25 @@
|
||||
import unittest
|
||||
|
||||
from aprsd import email
|
||||
|
||||
|
||||
class TestEmail(unittest.TestCase):
|
||||
def test_get_email_from_shortcut(self):
|
||||
email.CONFIG = {"shortcuts": {}}
|
||||
email_address = "something@something.com"
|
||||
addr = "-{}".format(email_address)
|
||||
actual = email.get_email_from_shortcut(addr)
|
||||
self.assertEqual(addr, actual)
|
||||
|
||||
email.CONFIG = {"nothing": "nothing"}
|
||||
actual = email.get_email_from_shortcut(addr)
|
||||
self.assertEqual(addr, actual)
|
||||
|
||||
email.CONFIG = {"shortcuts": {"not_used": "empty"}}
|
||||
actual = email.get_email_from_shortcut(addr)
|
||||
self.assertEqual(addr, actual)
|
||||
|
||||
email.CONFIG = {"shortcuts": {"-wb": email_address}}
|
||||
short = "-wb"
|
||||
actual = email.get_email_from_shortcut(short)
|
||||
self.assertEqual(email_address, actual)
|
Loading…
Reference in New Issue
Block a user