I'm building a function that's applying an additional tag to an aws instance based on a dict of tags that are passed in.
Expected behavior:
When more than one TEST_CUSTOMER_ID is are passed in, the function should return the following dictionary of tags:
{'foo': 'bar', 'Account': 'shared'}
The current behavior of the unit test function is only returning:
{'foo': 'bar', 'Account': [['test_customer_id1', 'test_customer_id2']]}
How can I fix this?
def get_acct_value(tags, customer_id, ceid):
customer_id = [customer_id]
if "Account" in tags:
if tags["Account"] == customer_id:
pass
else:
if len(customer_id) > 1:
tags["Account"] = "shared"
elif len(customer_id) == 1:
tags["Account"] = customer_id
else:
raise exceptions.CustomerNotFoundError(f"No customer(s) found on {ceid}")
else:
if len(customer_id) > 1:
tags["Account"] = "shared"
elif len(customer_id) == 1:
tags["Account"] = customer_id
else:
raise exceptions.CustomerNotFoundError(f"No customer(s) found on {ceid}")
return tags
Unit test:
TAGS_NO_VALUE = {'foo': 'bar'}
TEST_CUSTOMER_ID_LIST = ["test_customer_id1", "test_customer_id2"]
TEST_CEID = "test_ceid"
def test_get_account_value_customer_list():
response = tagging.get_acct_value(TAGS_NO_VALUE, TEST_CUSTOMER_ID_LIST, TEST_CEID)
print(response)
Other unit tests:
All three tests should return: {'Account': customer_id, 'foo': 'bar'}
TEST_CUSTOMER_ID = "test_customer_id"
TAGS_UNEXPECTED_VALUE = {'Account': '', 'foo': 'bar'}
TAGS_EXPECTED_VALUE = {'Account': customer_id, 'foo': 'bar'}
def test_get_acct_value_no_value():
response = tagging.get_acct_value(TAGS_NO_VALUE,
TEST_CUSTOMER_ID, TEST_CEID)
print(response)
def test_get_acct_value_unexpected_value():
response = tagging.get_acct_value(TAGS_UNEXPECTED_VALUE, TEST_CUSTOMER_ID, TEST_CEID)
print(response)
def test_get_acct_value_expected_value():
response = tagging.get_acct_value(TAGS_EXPECTED_VALUE, TEST_CUSTOMER_ID, TEST_CEID)
print(response)