def test_contact_from_json_requires_tags_key(self): with self.assertRaises(ValueError): Contact.from_json({"wrongkey": [], "name": "Asriel"})
def test_contact_from_json_requires_dict(self): with self.assertRaises(TypeError): Contact.from_json("some string")
def test_contact_from_json_requires_name_key(self): with self.assertRaises(ValueError): Contact.from_json({"wrongkey": "Lord Asriel", "tags": []})
def test_can_make_contact_from_json(self): json = {"name": "Lord Asriel", "tags": ["aaa", "ddd", "zzz"]} contact = Contact.from_json(json) self.assertIsInstance(contact, Contact) self.assertEqual(contact._name, "Lord Asriel") self.assertEqual(contact._tags, set(["aaa", "ddd", "zzz"]))