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)
def ListShowAndAct(this_list, statement, file_name, hide_email=True): print(len(this_list), statement) if len(this_list) > 0: action = PrintToScreenFileOrNeither('Print list to screen or file') if action == "y": for this_person in this_list: if hide_email: this_person.Print() else: this_person.PrintWithEmail() elif action == "f": import_file_tools.CreateFileFromPeople(this_list, file_name)
def action_2_1(self): ## ## run the action teacher_without_email, no_account_without_email, teacher_with_no_account, no_account_with_email, without_email_map, with_email_map = \ actions.FindAdultsWithoutAccounts([self.directory, self.hub_map]) ## ## print some of the counts to the screen for the user to review message = 'Directory contains:\n' message += ' People without accounts or email:\n' message += ' - ' + str( len(teacher_without_email)) + ' work for the school\n' message += ' - ' + str( len(no_account_without_email)) + ' student\'s parents\n' message += ' People without accounts but with email:\n' message += ' - ' + str( len(teacher_with_no_account)) + ' work for the school\n' message += ' - ' + str( len(no_account_with_email)) + ' student\'s parents\n' message += '\nThe results will be shown on the screen. Would you like to save them in a file as well?' message += '\n\n(Click "Cancel" to do neither)' ## ## prompt user whether to show on screen action = messagebox.askyesnocancel(title='Next Steps', message=message) if action is None: print('Not showing or storing results') else: print('NO ACCOUNT, NO EMAIL, WORK FOR SCHOOL') for this_person in teacher_without_email: this_person.Print() print( '\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n' ) print('NO ACCOUNT, NO EMAIL, STUDENT PARENT') for this_person in no_account_without_email: this_person.Print() print( '\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n' ) print('EMAIL, BUT NO ACCOUNT, WORK FOR SCHOOL') for this_person in teacher_with_no_account: this_person.PrintWithEmail() print( '\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n' ) print('EMAIL, BUT NO ACCOUNT, STUDENT PARENT') for this_person in no_account_with_email: this_person.PrintWithEmail() print( '\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n' ) if action == True: import_file_tools.CreateFileFromPeople( teacher_without_email, 'teachers_without_email') import_file_tools.CreateByHubFile(without_email_map, self.hub_map, 'no_account_without_email') import_file_tools.CreateFileFromPeople( teacher_with_no_account, 'teachers_without_account') import_file_tools.CreateByHubFile(with_email_map, self.hub_map, 'no_account_with_email')