示例#1
0
 def test_02_2_valid_people(self, mock_localtime):
     test_people = [person.DirectoryPerson(last_name       ='B',
                                           first_name      ='A',
                                           family_relation ='Adult',
                                           hub_name_list   =['Foo'],
                                           hub_map         ={'Foo':'1111'},
                                           email           ='[email protected]',
                                           person_id       ='1234'),
                    person.DirectoryPerson(last_name       ='D',
                                           first_name      ='C',
                                           family_relation ='Child',
                                           hub_name_list   =['Foo'],
                                           hub_map         ={'Foo':'1111'},
                                           person_id       ='2345')]
     mock_localtime.return_value = time.strptime('2020-01-01-00-00-00',"%Y-%m-%d-%H-%M-%S")
     mocker = mock_open()
     with patch('builtins.open', mocker):
         import_file_tools.CreateFileFromPeople(people      = test_people,
                                                file_prefix = 'test')
         mocker.assert_called_with(os.path.abspath('.')+'/test_2020-01-01-00-00-00.csv','w')
         handle = mocker()
         write_calls = [call('First Name'), call(',Last Name'), call(',Affiliated Hub(s)'), call(',Email'), call('\n'),
                        call('A'), call(',B'), call(',[\'1111\']'), call(',[email protected]'), call('\n'),
                        call('C'), call(',D'), call(',[\'1111\']'), call(',None'), call('\n')]
         handle.write.assert_has_calls(calls=write_calls, any_order=False)
示例#2
0
    def AddToFamily(self, person_id, last_name, first_name, middle_name,
                    suffix, email, family_id, family_relation, hub_name_list,
                    account_created, account_updated, hub_map):

        if family_relation[:5].lower() == 'adult':
            new_adult = person.DirectoryPerson(person_id=person_id,
                                               last_name=last_name,
                                               first_name=first_name,
                                               middle_name=middle_name,
                                               suffix=suffix,
                                               email=email,
                                               family_id=family_id,
                                               family_relation=family_relation,
                                               hub_name_list=hub_name_list,
                                               account_created=account_created,
                                               account_updated=account_updated,
                                               hub_map=hub_map)

            self.adults.append(new_adult)

        elif family_relation[:5].lower() == 'child':
            new_child = person.DirectoryPerson(person_id=person_id,
                                               last_name=last_name,
                                               first_name=first_name,
                                               middle_name=middle_name,
                                               suffix=suffix,
                                               email=email,
                                               family_id=family_id,
                                               family_relation=family_relation,
                                               hub_name_list=hub_name_list,
                                               account_created=account_created,
                                               account_updated=account_updated,
                                               hub_map=hub_map)
            self.children.append(new_child)

        else:
            print(
                "Attempting to add person from Directory to family with unrecognized family relation:",
                family_relation)
示例#3
0
 def test_04_valid_directory_person(self):
     test_person = person.DirectoryPerson(last_name       ='B',
                                          first_name      ='A',
                                          family_relation ='Adult',
                                          hub_name_list   =['Foo'],
                                          hub_map         ={'Foo':'1111'},
                                          person_id       ='1111')
     mocker = mock_open()
     with patch('builtins.open', mocker):
         with open('testfile', 'w') as open_file:
             import_file_tools.WriteNewMemberPerson(open_file  = open_file,
                                                    new_person = test_person)
             handle = mocker()
             write_calls = [call('Adult'), call(',A'), call(',B'), call(',1111'), call('\n')]
             handle.write.assert_has_calls(calls=write_calls, any_order=False)
示例#4
0
 def test_06_null_directory_person(self):
     test_person = person.DirectoryPerson(last_name       =None,
                                          first_name      =None,
                                          family_relation =None,
                                          hub_name_list   =[],
                                          hub_map         ={},
                                          person_id       =None)
     mocker = mock_open()
     with patch('builtins.open', mocker):
         with open('testfile', 'w') as open_file:
             import_file_tools.WriteNewMemberPerson(open_file  = open_file,
                                                    new_person = test_person)
             handle = mocker()
             write_calls = [call('None'), call(',None'), call(',None'), call(',None'), call('\n')]
             handle.write.assert_has_calls(calls=write_calls, any_order=False)
示例#5
0
 def test_06_set_other_relation(self):
     result = person.DirectoryPerson(person_id       = '1234',
                                     last_name       = 'C',
                                     first_name      = 'A',
                                     middle_name     = '',
                                     suffix          = '',
                                     email           = 'email',
                                     family_id       = '5678',
                                     family_relation = 'Other',
                                     hub_name_list   = 'Kinder (Room 0)'.split(';'),
                                     account_created = '',
                                     account_updated = '',
                                     hub_map         = common_hub_map)
     self.assertIsNone(result.last_name)
     self.assertIsNone(result.first_name)
     self.assertIsNone(result.family_relation)
     self.assertEqual([], result.hubs)
示例#6
0
 def test_02_set_multiple_hubs(self):
     result = person.DirectoryPerson(person_id       = '1234',
                                     last_name       = 'C',
                                     first_name      = 'A',
                                     middle_name     = '',
                                     suffix          = '',
                                     email           = 'email',
                                     family_id       = '5678',
                                     family_relation = 'Child',
                                     hub_name_list   = 'Kinder (Room 0);First (Room 1)'.split(';'),
                                     account_created = '',
                                     account_updated = '',
                                     hub_map         = common_hub_map)
     self.assertEqual('A', result.first_name)
     self.assertEqual('C', result.last_name)
     self.assertEqual('1234', result.person_id)
     self.assertEqual('5678', result.family_id)
     self.assertEqual('Child',result.family_relation)
     self.assertEqual('email',result.email)
     self.assertEqual(['0000','1111'],result.hubs)
示例#7
0
 def test_01_1_valid_people(self, mock_localtime):
     test_people = [person.DirectoryPerson(last_name       ='B',
                                           first_name      ='A',
                                           family_relation ='Adult',
                                           hub_name_list   =['Foo'],
                                           hub_map         ={'Foo':'1111'},
                                           person_id       ='1234')]
     mock_localtime.return_value = time.strptime('2020-01-01-00-00-00',"%Y-%m-%d-%H-%M-%S")
     mocker = mock_open()
     with patch('builtins.open', mocker):
         import_file_tools.CreateByHubFile(map_d       = {'1111':test_people},
                                           hub_map     = {'Foo':'1111'},
                                           file_prefix = 'test')
         mocker.assert_called_with(os.path.abspath('.')+'/test_2020-01-01-00-00-00.txt','w')
         handle = mocker()
         write_calls = [call('-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n'),
                        call('Hub ID: 1111\n'),
                        call('\t\t--> Possible Hub Name: Foo\n'),
                        call('1 people without emails found in this hub\n\n'),
                        call('1'), call(', B'), call(', A'), call('\n'), call('\n')]
         handle.write.assert_has_calls(calls=write_calls, any_order=False)