def test_contains(self): self.book.add(models.Person("name1", "name1")) self.book.add(models.Person("name2", "name2")) self.book.add(models.Group("name1")) self.book.add(models.Group("name2")) obj = models.Person("first", "last") self.book.add(obj) self.assertTrue(obj in self.book)
def test_discard(self): self.book.add(models.Person("name1", "name1")) self.book.add(models.Person("name2", "name2")) self.book.add(models.Group("name1")) self.book.add(models.Group("name2")) obj = models.Person("first", "last") self.book.add(obj) self.assertTrue(obj in self.book) self.book.discard(obj) self.assertFalse(obj in self.book)
def test_get_persons_in_group(self): family_group = models.Group('Family') friends_group = models.Group('Firends') brother = models.Person('Sam', 'Albert') sister = models.Person('Susan', 'Albert') friend_1 = models.Person('Kenneth', 'Boyce') friend_2 = models.Person('Brandon', 'Crawley') family_group.add_member(brother) family_group.add_member(sister) friends_group.add_member(friend_1) friends_group.add_member(friend_2) self.assertEqual(family_group.members, set([brother, sister])) self.assertEqual(friends_group.members, set([friend_1, friend_2]))
def test_iter(self): values = [ models.Person("name1", "name1"), models.Person("name2", "name2"), models.Group("name1"), models.Group("name2") ] list(map(self.book.add, values)) count = 0 for obj in self.book: count += 1 self.assertTrue(obj in values) values.remove(obj) self.assertEqual(count, 4)
def test_get_groups_perosn_belongs_to(self): family_group = models.Group('Family') close_family_group = models.Group('Close Family') friends_group = models.Group('Firends') close_friends_group = models.Group('Firends') brother = models.Person('Sam', 'Albert') best_friend = models.Person('Kenneth', 'Boyce') family_group.add_member(brother) close_family_group.add_member(brother) friends_group.add_member(best_friend) close_friends_group.add_member(best_friend) self.assertEqual(brother.in_groups, set([family_group, close_family_group])) self.assertEqual(best_friend.in_groups, set([friends_group, close_friends_group])) def test_str(self): self.assertEqual('Dummy Person', self.person.__str__())
def test_add_and_delete_person_with_groups(self): person = models.Person("first", "last") groups = [ models.Group("group1"), models.Group("group2"), models.Group("group3"), ] list(map(person.groups.add, groups)) self.book.add(person) self.assertEqual(len(self.book), 4) for group in groups: self.assertTrue(group in self.book) self.assertTrue(person in group.persons) self.book.discard(person) self.assertEqual(len(self.book), 0) self.assertFalse(person in self.book) for group in groups: self.assertFalse(group in self.book) self.assertFalse(person in group.persons)
def test_add_and_delete_group_with_persons(self): group = models.Group('group') persons = [ models.Person("name1", "name1"), models.Person("name2", "name2"), models.Person("name3", "name3"), ] list(map(group.persons.add, persons)) self.book.add(group) self.assertEqual(len(self.book), 4) for person in persons: self.assertTrue(person in self.book) self.assertTrue(group in person.groups) self.book.discard(group) self.assertEqual(len(self.book), 3) self.assertFalse(group in self.book) for person in persons: self.assertTrue(person in self.book) self.assertFalse(group in person.groups)
def setUp(self): self.address_book = models.AddressBook() self.person = models.Person('Dummy', 'Person') self.person.add_email('*****@*****.**') self.family_group = models.Group('Family')
def test_initialize_group(self): group_name = 'Family' group = models.Group(group_name) self.assertIsNotNone(group) self.assertEqual(group.name, group_name) self.assertIsInstance(group, models.Group)
def setUp(self): self.group = models.Group('Group')
def test_len_with_elements(self): self.book.add(models.Person("name1", "name1")) self.book.add(models.Person("name2", "name2")) self.book.add(models.Group("name1")) self.book.add(models.Group("name2")) self.assertEqual(len(self.book), 4)