Skip to content

Commit 9eda7ed

Browse files
committed
add test for format_address
1 parent 29b6242 commit 9eda7ed

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/tests/test_mailchimp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,34 @@ def test_format_birthday(self):
666666
# ValueError raised when not a date
667667
with self.assertRaises(ValueError):
668668
self.test_client.format_birthday("not a date, obviously")
669+
670+
def test_format_address(self):
671+
"""Test format_address returns the correct values"""
672+
# when input val is not a dict
673+
with self.assertRaises(ValueError):
674+
self.test_client.format_address("not a dict, obviously")
675+
676+
# create a dict to test the normalize_string function nested in format_address
677+
function_address_valid = self.test_client.format_address(
678+
{
679+
"addr1": "999 Dolly Ave",
680+
"addr2": " Apt 3 ",
681+
"city": "Delaware",
682+
"state": "PA",
683+
"zip": 90210,
684+
"country": "USA ",
685+
}
686+
)
687+
688+
# check if one req element exists
689+
self.assertIn("addr1", function_address_valid)
690+
# check formatted val of addr1
691+
self.assertEqual(function_address_valid["addr1"], "999 Dolly Ave")
692+
# check that a numeric val is now string
693+
self.assertEqual(function_address_valid["zip"], "90210")
694+
# coverage on the string trimming
695+
self.assertEqual(function_address_valid["addr2"], "Apt 3")
696+
697+
# creating an invalid req
698+
with self.assertRaises(ValueError):
699+
self.test_client.format_address({"addr2": "999 Dolly Ave "})

0 commit comments

Comments
 (0)