예제 #1
0
 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)
예제 #2
0
 def test_not_results_of_find_by_email(self):
     first = models.Person('n1',
                           'n2',
                           emails=['*****@*****.**', '*****@*****.**'])
     second = models.Person('n2', 'n2', emails=['*****@*****.**'])
     self.repository.save(first)
     self.repository.save(second)
     result = self.repository.find_persons_by_email('*****@*****.**')
     self.assertEqual(len(result), 0)
예제 #3
0
 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)
예제 #4
0
 def test_find_by_full_email(self):
     first = models.Person('n1',
                           'n2',
                           emails=['*****@*****.**', '*****@*****.**'])
     second = models.Person('n2', 'n2', emails=['[email protected]'])
     self.repository.save(first)
     self.repository.save(second)
     result = self.repository.find_persons_by_email('*****@*****.**')
     self.assertEqual(len(result), 1)
     self.assertIn(first, result)
예제 #5
0
 def test_search_by_name(self):
     last = models.Person('first', 'last')
     second = models.Person('fi\'rst', 'second')
     one = models.Person('one', '  f irst')
     no_name = models.Person('first1', '2first')
     self.repository.save(last)
     self.repository.save(second)
     self.repository.save(one)
     self.repository.save(no_name)
     result = self.repository.find_persons_by_name('first')
     self.assertEqual(len(result), 3)
     self.assertIn(last, result)
     self.assertIn(second, result)
     self.assertIn(one, result)
예제 #6
0
    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]))
예제 #7
0
 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)
예제 #8
0
 def test_search_by_empty_email(self):
     person = models.Person('', '')
     self.repository.save(person)
     person.emails = [
         '',
     ]
     result = self.repository.find_persons_by_email('')
     self.assertEqual(len(list(result)), 0)
예제 #9
0
 def test_initialize_person(self):
     first_name = 'Emad'
     last_name = 'Mokhtar'
     person = models.Person(first_name, last_name)
     self.assertIsNotNone(person)
     self.assertEqual(person.last_name, last_name)
     self.assertEqual(person.first_name, first_name)
     self.assertIsInstance(person, models.Person)
예제 #10
0
    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__())
예제 #11
0
 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)
예제 #12
0
 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)
예제 #13
0
 def setUp(self):
     self.address_book = models.AddressBook()
     self.person = models.Person('Dummy', 'Person')
     self.person.add_email('*****@*****.**')
     self.family_group = models.Group('Family')
예제 #14
0
 def setUp(self):
     self.person = models.Person('Dummy', 'Person')
예제 #15
0
 def test_not_add_copies(self):
     obj = models.Person("first", "last")
     self.book.add(obj)
     self.book.add(obj)
     self.book.add(obj)
     self.assertEqual(len(self.book), 1)
예제 #16
0
 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)
예제 #17
0
 def test_add_person_to_group(self):
     person = models.Person('Dummy', 'Person')
     self.group.add_member(person)
     self.assertEqual(1, len(self.group.members))
예제 #18
0
 def test_add_data(self):
     obj = models.Person('', '')
     self.book.add(obj)
     self.assertTrue(obj in self.book)