Exemplo n.º 1
0
class TestContactGroup(TestCase):
    def setUp(self):
        self.contact_group = ContactGroup(
            name="contact group", contacts=[Contact(name="contact", email="*****@*****.**")]
        )

    def test_contact_group_default_values(self):
        self.assertNotEqual(self.contact_group.id, None)
        self.assertEqual(type(self.contact_group.contacts), set)
        self.assertNotEqual(len(self.contact_group.contacts), 0)
        self.assertEqual(self.contact_group.enabled, True)

    def test_contact_groups_are_equal(self):
        self.assertEqual(
            self.contact_group,
            ContactGroup(name="contact group", contacts=[Contact(name="contact", email="*****@*****.**")]),
        )

    def test_contact_groups_are_not_equal(self):
        contact = Contact(name="contact", email="*****@*****.**")
        another_contact = Contact(name="another contact", email="*****@*****.**")
        self.assertNotEqual(
            ContactGroup(name="contact group 1", contacts=[contact]),
            ContactGroup(name="contact group 2", contacts=[another_contact]),
        )

    def test_contact_groups_set(self):
        contact = Contact(name="contact", email="*****@*****.**")
        another_contact = Contact(name="another contact", email="*****@*****.**")
        self.assertEqual(
            len(
                set(
                    [
                        ContactGroup(name="contact group 1", contacts=[contact, another_contact]),
                        ContactGroup(name="contact group 1", contacts=[contact, another_contact]),
                    ]
                )
            ),
            1,
        )
        self.assertEqual(
            len(
                set(
                    [
                        ContactGroup(name="contact group 1", contacts=[contact]),
                        ContactGroup(name="contact group 2", contacts=[another_contact]),
                    ]
                )
            ),
            2,
        )

    def test_to_dict(self):
        d = self.contact_group.to_dict()
        keys = ["id", "name", "contacts", "enabled"]
        self.assertTrue(all([k in d for k in keys]))
Exemplo n.º 2
0
 def setUp(self):
     self.contact_group = ContactGroup(
         name="contact group", contacts=[Contact(name="contact", email="*****@*****.**")]
     )