Пример #1
0
 def test_tags_json_is_ordered(self):
     contact = Contact("Lord Asriel")
     contact._tags = set(["ddd", "zzz", "aaa"])
     json = contact.to_json()
     self.assertEqual(json, {
      "name": "Lord Asriel", "tags": ["aaa", "ddd", "zzz"]
     })
Пример #2
0
 def test_can_make_tags_json_from_contact(self):
     contact = Contact("Lord Asriel")
     contact._tags = set(["aaa"])
     json = contact.to_json()
     self.assertEqual(json, {
      "name": "Lord Asriel", "tags": ["aaa"]
     })
Пример #3
0
 def test_can_get_tags(self):
     contact = Contact("Marvin Goodwright")
     contact._tags = set(["aaa", "bbb"])
     self.assertEqual(contact._tags, contact.tags())
     self.assertIsNot(contact._tags, contact.tags())
Пример #4
0
 def test_can_only_set_contact_name_to_str(self):
     contact = Contact("Marvin Goodwright")
     with self.assertRaises(TypeError):
         contact.name(123)
Пример #5
0
 def test_can_modify_contact_name(self):
     contact = Contact("Marvin Goodwright")
     contact.name("Albus Dumbledore")
     self.assertEqual(contact._name, "Albus Dumbledore")
Пример #6
0
 def test_contact_name_property(self):
     contact = Contact("Marvin Goodwright")
     self.assertIs(contact._name, contact.name())
Пример #7
0
 def test_contacts_repr(self):
     contact = Contact("Marvin Goodwright")
     self.assertEqual(str(contact), "<Contact: Marvin Goodwright>")
Пример #8
0
 def test_can_create_contact(self):
     contact = Contact("Marvin Goodwright")
     self.assertEqual(contact._name, "Marvin Goodwright")
     self.assertEqual(contact._tags, set())
Пример #9
0
 def test_contact_name_must_be_str(self):
     with self.assertRaises(TypeError):
         Contact(111)
Пример #10
0
 def test_contact_from_json_requires_name_key(self):
     with self.assertRaises(ValueError):
         Contact.from_json({"wrongkey": "Lord Asriel", "tags": []})
Пример #11
0
 def test_contact_from_json_requires_dict(self):
     with self.assertRaises(TypeError):
         Contact.from_json("some string")
Пример #12
0
 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"]))
Пример #13
0
 def test_creating_contact_updates_registry(self):
     while Contact.all_contacts: Contact.all_contacts = set()
     contact1 = Contact("Marvin Goodwright")
     self.assertEqual(Contact.all_contacts, set([contact1]))
     contact2 = Contact("Marvin Goodwright II")
     self.assertEqual(Contact.all_contacts, set([contact1, contact2]))
Пример #14
0
 def test_can_add_tags(self):
     contact = Contact("Marvin Goodwright")
     contact.add_tag("111")
     self.assertEqual(contact._tags, set(["111"]))
     contact.add_tag("222")
     self.assertEqual(contact._tags, set(["111", "222"]))
Пример #15
0
 def test_contact_from_json_requires_tags_key(self):
     with self.assertRaises(ValueError):
         Contact.from_json({"wrongkey": [], "name": "Asriel"})
Пример #16
0
 def test_tags_must_be_str(self):
     contact = Contact("Marvin Goodwright")
     with self.assertRaises(TypeError):
         contact.add_tag(100)
Пример #17
0
 def test_can_remove_tags(self):
     contact = Contact("Marvin Goodwright")
     contact._tags = set(["aaa", "bbb"])
     contact.remove_tag("aaa")
     self.assertEqual(contact._tags, set(["bbb"]))