Skip to content

Commit

Permalink
Add tests for issue #323
Browse files Browse the repository at this point in the history
  • Loading branch information
lucc committed Sep 6, 2023
1 parent e5d147a commit 971e341
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@ def test_empty_strings_produce_empty_values(self):
result = helpers.convert_to_yaml("Note", "", 0, 5, True)
self.assertListEqual(result, ["Note : "])

def test_preparing_multiple_addresses_with_same_label_for_yaml_conversion_returns_all_entries(self):
input = {'home': [{'street': 'street 1',
'city': 'city1',
'code': 'zip1',
'country': ''},
{'street': 'street 2',
'city': 'city2',
'code': 'zip2',
'country': ''}]}
expected = [{'Street': 'street 1',
'City': 'city1',
'Code': 'zip1',
'Country': None},
{'Street': 'street 2',
'City': 'city2',
'Code': 'zip2',
'Country': None}]
actual = helpers.yaml_addresses(input, ["Street", "Code", "City",
"Country"])
self.assertEqual(expected, actual["home"])

def test_preparing_single_addresse_for_yaml_conversion_returns_dict_not_list(self):
input = {'home': [{'street': 'street', 'city': 'city', 'code': 'zip',
'country': ''}]}
expected = {'Street': 'street', 'City': 'city', 'Code': 'zip',
'Country': None}
actual = helpers.yaml_addresses(input, ["Street", "Code", "City",
"Country"])
self.assertEqual(expected, actual["home"])


if __name__ == "__main__":
unittest.main()
27 changes: 27 additions & 0 deletions test/test_yaml_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ def test_yaml_quoted_special_characters(self):
yaml_dump = yaml_editable.to_yaml()
self.assertIn("'@khard'", yaml_dump)

def test_dumping_multiple_home_addresses_to_yaml(self):
yaml_editable = TestYAMLEditable()
yaml_editable._add_post_address("home", "", "", "street 1", "zip1",
"city1", "", "")
yaml_editable._add_post_address("home", "", "", "street 2", "zip2",
"city2", "", "")
yaml_dump = yaml_editable.to_yaml()
self.assertIn("zip1", yaml_dump)
self.assertIn("zip2", yaml_dump)

def test_dumping_multiple_home_phone_number_to_yaml(self):
yaml_editable = TestYAMLEditable()
yaml_editable._add_phone_number("home", "1234567890")
yaml_editable._add_phone_number("home", "0987654321")
yaml_dump = yaml_editable.to_yaml()
self.assertIn("1234567890", yaml_dump)
self.assertIn("0987654321", yaml_dump)

def test_dumping_multiple_home_email_addresses_to_yaml(self):
yaml_editable = TestYAMLEditable()
yaml_editable.add_email("home", "home1@example.org")
yaml_editable.add_email("home", "home2@example.org")
yaml_dump = yaml_editable.to_yaml()
self.assertIn("home1", yaml_dump)
self.assertIn("home2", yaml_dump)



class ExceptionHandling(unittest.TestCase):

Expand Down

0 comments on commit 971e341

Please sign in to comment.