コード例 #1
0
 def test_add_email(self):
     basic_email = ['*****@*****.**']
     person = Person('John', 'Doe', [
         'Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'
     ], ['+79834772053'], copy(basic_email))
     person.add_email('*****@*****.**')
     self.assertEqual(person.emails, basic_email + ['*****@*****.**'])
コード例 #2
0
    def test_get_group_members(self):
        book = AddressBook()
        family = Group('family')
        friends = Group('friends')
        work = Group('work')
        book.add_group(family)
        book.add_group(friends)
        book.add_group(work)

        book.add_person(Person('John', 'Doe', Address('New York'),
                               Email('*****@*****.**'),
                               PhoneNumber('88005553535'),
                               friends))
        book.add_person(Person('Jane', 'Doe', Address('Chicago'),
                               Email('*****@*****.**'),
                               PhoneNumber('2128506'),
                               [friends, work]))

        entries = book.get_group_members(work)
        self.assertEqual(len(entries), 1)

        entries = book.get_group_members(friends)
        self.assertEqual(len(entries), 2)
        self.assertEqual({entries[0].first_name, entries[1].first_name}, {'John', 'Jane'})

        entries = book.get_group_members(family)
        self.assertEqual(len(entries), 0)
コード例 #3
0
 def test_add_phone(self):
     basic_phone = ['+79237778492']
     person = Person('John', 'Doe', [
         'Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'
     ], copy(basic_phone), ['*****@*****.**'])
     person.add_phone_number('+79234478810')
     self.assertEqual(person.phone_numbers, basic_phone + ['+79234478810'])
コード例 #4
0
 def test_add_address(self):
     basic_address = [
         'Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'
     ]
     person = Person('John', 'Doe', copy(basic_address), ['+79834772053'],
                     ['*****@*****.**'])
     person.add_address('new address')
     self.assertEqual(person.addresses, basic_address + ['new address'])
コード例 #5
0
 def test_get_persons(self):
     john_person = Person('John', 'Doe', [
         'Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'
     ], ['+79834772053'], ['*****@*****.**'])
     ivan_person = Person('Ivan', 'Sidorov', [
         'Russian Federation, Kemerovo region, Belovo, Kirova street 42, apt. 13'
     ], ['+79834771122'], ['*****@*****.**'])
     group = Group('friends')
     self.assertFalse(group.persons)
     group.add_person(ivan_person)
     group.add_person(john_person)
     self.assertEqual(group.persons, [ivan_person, john_person])
     self.assertIn(group, ivan_person.groups)
     self.assertIn(group, john_person.groups)
コード例 #6
0
 def setUp(self):
     self.address_book = AddressBook()
     self.person1 = Person(first_name='p1fn',
                           last_name='p1ln',
                           emails=['p1em1@com', 'p1em2@com'])
     self.person2 = Person(first_name='p2fn',
                           last_name='p2ln',
                           emails=['p2em1@com', 'p2em2@com'])
     self.person3 = Person(first_name='p3fn',
                           last_name='p3ln',
                           emails=['p3em1@com', 'p3em2@com'])
     self.group1 = Group(name='Group1', persons=self.person1)
     self.group2 = Group(name='Group2',
                         persons=[self.person3, self.person1])
コード例 #7
0
    def test_find_by_last_name(self):
        book = AddressBook()
        book.add_person(Person('John', 'Doe', Address('New York'),
                               Email('*****@*****.**'),
                               PhoneNumber('88005553535')))
        book.add_person(Person('Jane', 'Doe', Address('Chicago'),
                               Email('*****@*****.**'),
                               PhoneNumber('2128506')))
        entries = book.find_by_name('Doe')
        self.assertEqual(len(entries), 2)
        self.assertEqual(entries[0].last_name, 'Doe')
        self.assertEqual(entries[1].last_name, 'Doe')

        self.assertEqual(len(book.find_by_name('Ivanov')), 0)
コード例 #8
0
 def test_find_person_by_email(self):
     address_book = AddressBook()
     john_person = Person(
         'John',
         'Doe',
         ['Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'],
         ['+79834772053'],
         ['*****@*****.**']
     )
     ivan_person = Person(
         'Ivan',
         'Sidorov',
         ['Russian Federation, Kemerovo region, Belovo, Kirova street 42, apt. 13'],
         ['+79834771122'],
         ['*****@*****.**']
     )
     address_book.add_person(john_person)
     address_book.add_person(ivan_person)
     found_person = address_book.find(email='*****@*****.**')
     self.assertEqual(found_person, ivan_person)
コード例 #9
0
 def test_add_person(self):
     address_book = AddressBook()
     person = Person(
         'John',
         'Doe',
         ['Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'],
         ['+79834772053'],
         ['*****@*****.**']
     )
     address_book.add_person(person)
     self.assertIn(person, address_book)
コード例 #10
0
 def test_find_person_by_full_name(self):
     address_book = AddressBook()
     ivan_popov_person = Person(
         'Ivan',
         'Popov',
         ['Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'],
         ['+79834772053'],
         ['*****@*****.**']
     )
     ivan_sidorov_person = Person(
         'Ivan',
         'Sidorov',
         ['Russian Federation, Kemerovo region, Belovo, Kirova street 42, apt. 13'],
         ['+79834771122'],
         ['*****@*****.**']
     )
     address_book.add_person(ivan_popov_person)
     address_book.add_person(ivan_sidorov_person)
     found_person = address_book.find(first_name='Ivan', last_name='Sidorov')
     self.assertEqual(found_person, ivan_sidorov_person)
コード例 #11
0
 def test_find_person_by_set_of_emails_prefix(self):
     address_book = AddressBook()
     john_person = Person(
         'John',
         'Doe',
         ['Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'],
         ['+79834772053'],
         ['*****@*****.**']
     )
     ivan_person = Person(
         'Ivan',
         'Sidorov',
         ['Russian Federation, Kemerovo region, Belovo, Kirova street 42, apt. 13'],
         ['+79834771122'],
         ['*****@*****.**']
     )
     address_book.add_person(john_person)
     address_book.add_person(ivan_person)
     found_person = address_book.find(emails=['*****@*****.**', '*****@*****.**'])
     self.assertIsNone(found_person)
     ivan_person.add_email('*****@*****.**')
     found_person = address_book.find(emails=['sn0', 'iv'])
     self.assertEqual(found_person, ivan_person)
コード例 #12
0
 def test_find_by_first_name(self):
     book = AddressBook()
     book.add_person(Person('John', 'Doe', Address('New York'),
                            Email('*****@*****.**'),
                            PhoneNumber('88005553535')))
     entries = book.find_by_name('John')
     self.assertEqual(len(entries), 1)
     entry = entries[0]
     self.assertEqual(entry.first_name, 'John')
     self.assertEqual(entry.last_name, 'Doe')
     self.assertEqual(entry.street_addresses[0].address, 'New York')
     self.assertEqual(entry.emails[0].email, '*****@*****.**')
     self.assertEqual(entry.phone_numbers[0].number, '88005553535')
     self.assertEqual(entry.groups, [])
コード例 #13
0
    def setUp(self):
        self.person_params = {
            'first_name': fake.first_name(),
            'last_name': fake.last_name(),
            'addresses': [fake.address()],
            'emails': [fake.email()],
            'phone_numbers': [fake.phone_number()],
        }
        self.person = Person(**self.person_params)

        self.group_name = fake.word()
        self.group = Group(name=self.group_name)

        self.group_name_2 = fake.word()
        self.group_2 = Group(name=self.group_name_2)
コード例 #14
0
 def test_get_groups(self):
     person = Person('John', 'Doe', [
         'Russian Federation, Kemerovo region, Kemerovo, Kirova street 23, apt. 42'
     ], ['+79834772053'], ['*****@*****.**'])
     self.assertFalse(person.groups)
     group_friends = Group('friends')
     group_family = Group('family')
     person.add_to_group(group_friends)
     person.add_to_group(group_family)
     self.assertEqual(person.groups, [group_friends, group_family])
     self.assertIn(person, group_friends.persons)
     self.assertIn(person, group_family.persons)
コード例 #15
0
class PersonTestCase(unittest.TestCase):
    def setUp(self):
        self.person_params = {
            'first_name': fake.first_name(),
            'last_name': fake.last_name(),
            'addresses': [fake.address()],
            'emails': [fake.email()],
            'phone_numbers': [fake.phone_number()],
        }
        self.person = Person(**self.person_params)

        self.group_name = fake.word()
        self.group = Group(name=self.group_name)

        self.group_name_2 = fake.word()
        self.group_2 = Group(name=self.group_name_2)

    def test_create_person(self):
        self.assertTrue(isinstance(self.person, Person))

    def test_person_attrs(self):
        self.assertEqual(self.person_params['first_name'], self.person.first_name)
        self.assertEqual(self.person_params['last_name'], self.person.last_name)
        self.assertIn(self.person_params['addresses'][0], self.person.addresses)
        self.assertIn(self.person_params['emails'][0], self.person.emails)
        self.assertIn(self.person_params['phone_numbers'][0], self.person.phone_numbers)

    def test_person_in_address_book(self):
        self.assertIn(self.person, address_book)

    def test_many_addresses(self):
        new_address = fake.address()
        self.person.addresses.add(new_address)
        self.assertIn(new_address, self.person.addresses)
        self.assertEqual(len(self.person.addresses), 2)

    def test_many_emails(self):
        new_email = fake.email()
        self.person.emails.add(new_email)
        self.assertIn(new_email, self.person.emails)
        self.assertEqual(len(self.person.emails), 2)

    def test_many_phone_numbers(self):
        new_phone = fake.phone_number()
        self.person.phone_numbers.add(new_phone)
        self.assertIn(new_phone, self.person.phone_numbers)
        self.assertEqual(len(self.person.phone_numbers), 2)

    # Test if sets do not return the same objects twice
    def test_emails_contain_no_doubles(self):
        old_email = self.person_params['emails'][0]

        # We insert existing email to person again
        self.person.emails.add(old_email)
        self.assertIn(old_email, self.person.emails)

        # Should contain only 1 email address
        self.assertEqual(len(self.person.emails), 1)

    def test_joining_groups(self):
        self.person.join_group(self.group)
        self.assertEqual(len(self.group.members), 1)
        self.assertEqual(len(self.person.groups), 1)

        self.person.join_group(self.group_2)
        self.assertEqual(len(self.group_2.members), 1)
        self.assertEqual(len(self.person.groups), 2)

    def test_joining_groups_wrong_input(self):
        with self.assertRaises(ValueError):
            self.group.add_member('group')

    def test_display_groups(self):
        self.person.join_group(self.group)
        self.person.join_group(self.group_2)

        groups = self.person.display_groups()
        self.assertIn(self.group, groups)
        self.assertIn(self.group_2, groups)
コード例 #16
0
 def test_wrong_creation(self):
     with self.assertRaises(TypeError):
         test_group = Group()
     with self.assertRaises(TypeError):
         test_person = Person()