def test_get_attr_list_withhrp(self): set_db_records() person = get_person('faculty') worker = get_worker(person) user_attr_list = get_attr_list(person, worker) self.assertEqual(len(user_attr_list), 25) self.assertEqual(user_attr_list[0], "*****@*****.**") self.assertEqual(user_attr_list[1], "*****@*****.**") self.assertEqual(user_attr_list[2], "William E Faculty") self.assertEqual(user_attr_list[3], "William E") self.assertEqual(user_attr_list[4], "Faculty") self.assertEqual(user_attr_list[5], "10000000000000000000000000000005") self.assertEqual(user_attr_list[6], "000000005") self.assertEqual(user_attr_list[7], "0000005") self.assertEqual(user_attr_list[8], "Clinical Associate Professor") self.assertEqual(user_attr_list[9], 196) self.assertEqual(user_attr_list[10], "Family Medicine") self.assertEqual(user_attr_list[11], "3040111000") self.assertEqual(user_attr_list[12], "Academic Personnel") self.assertEqual(user_attr_list[13], "21184") self.assertEqual(user_attr_list[14], "Seattle Campus") self.assertEqual(user_attr_list[15], "SOM:") self.assertEqual(user_attr_list[16], "Family Medicine: Volunteer JM Academic") self.assertEqual(user_attr_list[17], "00753") self.assertIsNone(user_attr_list[18]) self.assertIsNone(user_attr_list[19]) self.assertIsNone(user_attr_list[20]) self.assertIsNone(user_attr_list[21]) self.assertIsNone(user_attr_list[22]) self.assertIsNone(user_attr_list[23]) self.assertIsNone(user_attr_list[24])
def test_get_supervisor_bridge_id(self): set_db_records() person = get_person('javerage') hrp_wkr = get_worker(person) self.assertEqual(get_supervisor_bridge_id(hrp_wkr), 196) # hrp_wkr is None self.assertEqual(get_supervisor_bridge_id(None), 0) # manager employee_id is None hrp_wkr = Worker(netid="x", regid="111", employee_id="1") self.assertEqual(get_supervisor_bridge_id(hrp_wkr), 0) # manager employee_id is the same as the employee's hrp_wkr = Worker(netid="x", regid="111", employee_id="1", primary_manager_id="1") self.assertEqual(get_supervisor_bridge_id(hrp_wkr), 0) # manager employee_id not in local DB hrp_wkr = Worker(netid="javerage", regid="111111111111111111111111111111", employee_id="1", primary_manager_id="11") self.assertEqual(get_supervisor_bridge_id(hrp_wkr), 0) # manager's uw account is the same the user's hrp_wkr = Worker(netid="javerage", regid="111111111111111111111111111111", employee_id="1", primary_manager_id="123456789") self.assertEqual(get_supervisor_bridge_id(hrp_wkr), 0)
def test_remove_author_role(self): set_db_records() loader = AuthorChecker(BridgeWorker()) retiree = loader.get_bridge().get_user_by_uwnetid('retiree') loader.remove_author_role(retiree) self.assertEqual(loader.get_updated_count(), 1) self.assertFalse(loader.has_error())
def test_account_not_changed(self): with self.settings(BRIDGE_USER_WORK_POSITIONS=2): set_db_records() loader = GwsBridgeLoader(BridgeWorker()) person = get_person('javerage') hrp_wkr = get_worker(person) bridge_account = loader.get_bridge().get_user_by_uwnetid( 'javerage') self.assertTrue( loader.account_not_changed(bridge_account, person, hrp_wkr))
def test_update(self): set_db_records() loader = OtherUserLoader(BridgeWorker()) loader.load() self.assertEqual(loader.get_total_checked_users(), 1) self.assertEqual(loader.get_new_user_count(), 0) self.assertEqual(loader.get_netid_changed_count(), 0) self.assertEqual(loader.get_deleted_count(), 0) self.assertEqual(loader.get_restored_count(), 0) self.assertEqual(loader.get_updated_count(), 0) self.assertFalse(loader.has_error())
def test_make_import_user_csv_files(self): with self.settings(BRIDGE_IMPORT_USER_FILENAME="blah", BRIDGE_IMPORT_USER_FILE_SIZE=1): file_path = "/tmp" user_number = make_import_user_csv_files(None, file_path) self.assertEqual(user_number, 0) set_db_records() user_number = make_import_user_csv_files(get_all_uw_accounts(), file_path) self.assertEqual(user_number, 2) self.verify_file_content("/tmp/blah1.csv", "Library") self.verify_file_content("/tmp/blah2.csv", "UW Benefits Office")
def test_load_hrp(self): with self.settings(ERRORS_TO_ABORT_LOADER=[], BRIDGE_PERSON_CHANGE_WINDOW=10): set_db_records() loader = HrpBridgeLoader(BridgeWorker()) loader.users_to_process = get_worker_updates("2019") loader.process_users() self.assertEqual(loader.get_total_count(), 2) self.assertEqual(loader.get_total_checked_users(), 1) self.assertEqual(loader.get_new_user_count(), 0) self.assertEqual(loader.get_restored_count(), 0) self.assertEqual(loader.get_netid_changed_count(), 1) self.assertEqual(loader.get_updated_count(), 1) self.assertFalse(loader.has_error())
def test_load_gws(self): with self.settings(ERRORS_TO_ABORT_LOADER=[], BRIDGE_USER_WORK_POSITIONS=2, BRIDGE_GWS_CACHE='/tmp/gwsuser2'): set_db_records() loader = GwsBridgeLoader(BridgeWorker()) loader.load() self.assertEqual(loader.get_total_count(), 7) self.assertEqual(loader.get_total_checked_users(), 6) self.assertEqual(loader.get_new_user_count(), 1) self.assertEqual(loader.get_restored_count(), 1) self.assertEqual(loader.get_netid_changed_count(), 2) self.assertEqual(loader.get_updated_count(), 3) self.assertTrue(loader.has_error())
def test_load_from_gws_to_bridge(self): set_db_records() # existing user call_command('disable_user', "retiree") uw_acc = get_by_netid("retiree") self.assertTrue(uw_acc.disabled) # error when deleting call_command('disable_user', "ellen") # changed uwnetid call_command('disable_user', "faculty") # already disabled call_command('disable_user', "staff")
def test_get_by_ids(self): set_db_records() self.assertIsNone(get_by_bridgeid(201)) self.assertEqual(get_by_bridgeid(196).netid, 'staff') self.assertEqual(get_by_employee_id("123456789").netid, "javerage") # multiple records self.assertIsNone(get_by_employee_id("000000006")) self.assertEqual(get_by_netid('staff').bridge_id, 196) delete_uw_account('staff') self.assertIsNone(get_by_netid('staff')) self.assertIsNone(get_by_bridgeid(0)) self.assertIsNone(get_by_employee_id(None)) self.assertIsNone(get_by_netid('none'))
def test_add_author_role(self): set_db_records() loader = AuthorChecker(BridgeWorker()) loader.add_author_role("javerage") self.assertEqual(loader.get_updated_count(), 1) self.assertFalse(loader.has_error()) # 500 Error set_db_err_records() loader.add_author_role("error500") self.assertTrue(loader.has_error()) # not in PWS loader = AuthorChecker(BridgeWorker()) loader.add_author_role("not_in_pws") self.assertFalse(loader.has_error())
def test_load_from_gws_to_bridge(self): set_db_records() set_db_err_records() call_command('sync_authors')
def test_load(self): set_db_records() set_db_err_records() loader = AuthorChecker(BridgeWorker()) loader.load() self.assertEqual(loader.get_updated_count(), 2)
def test_load_from_gws_to_bridge(self): set_db_records() call_command('sync_eid')
def test_load_from_gws_to_bridge(self): with self.settings(BRIDGE_GWS_CACHE='/tmp/gwsusermc'): set_db_records() call_command('sync_accounts', 'gws')
def test_load_from_dbother_to_bridge(self): time.sleep(1) set_db_records() call_command('sync_accounts', 'db-other')
def test_load_bridge_to_db(self): time.sleep(2) set_db_records() call_command('sync_accounts', 'bridge')
def test_get_bridge_user_to_add(self): set_db_records() # self.maxDiff = None worker = BridgeWorker() person = get_person('faculty') user = worker.get_bridge_user_to_add(person, get_worker(person)) self.assertEqual( user.to_json_post(), { 'users': [{ 'uid': '*****@*****.**', 'full_name': 'William E Faculty', 'email': '*****@*****.**', 'custom_field_values': [{ 'custom_field_id': '5', 'value': '10000000000000000000000000000005' }, { 'custom_field_id': '6', 'value': '000000005' }, { 'custom_field_id': '7', 'value': '0000005' }, { 'custom_field_id': '11', 'value': '3040111000' }, { 'custom_field_id': '13', 'value': 'Academic Personnel' }, { 'custom_field_id': '12', 'value': '21184' }, { 'custom_field_id': '17', 'value': 'Seattle Campus' }, { 'custom_field_id': '14', 'value': 'SOM:' }, { 'custom_field_id': '15', 'value': 'Family Medicine: Volunteer JM Academic' }, { 'custom_field_id': '16', 'value': '00753' }, { 'custom_field_id': '21', 'value': None }, { 'custom_field_id': '23', 'value': None }, { 'custom_field_id': '22', 'value': None }, { 'custom_field_id': '27', 'value': None }, { 'custom_field_id': '24', 'value': None }, { 'custom_field_id': '25', 'value': None }, { 'custom_field_id': '26', 'value': None }], 'first_name': 'William E', 'last_name': 'Faculty', 'sortable_name': 'Faculty, William E', 'manager_id': 196, 'job_title': 'Clinical Associate Professor' }] })
def test_set_bridge_user_to_update(self): set_db_records() person = get_person('faculty') worker = BridgeWorker() user = worker.bridge.get_user_by_uwnetid('tyler') worker.set_bridge_user_to_update(person, get_worker(person), user) # self.maxDiff = None self.assertEqual( user.to_json_patch(), { 'user': { 'id': 198, 'uid': '*****@*****.**', 'full_name': 'William E Faculty', 'email': '*****@*****.**', 'first_name': 'William E', 'last_name': 'Faculty', 'sortable_name': 'Faculty, William E', 'job_title': 'Clinical Associate Professor', 'manager_id': 196, 'custom_field_values': [{ 'custom_field_id': '5', 'value': '10000000000000000000000000000005', 'id': '1' }, { 'custom_field_id': '7', 'id': '3', 'value': '0000005' }, { 'custom_field_id': '11', 'value': '3040111000', 'id': '4' }, { 'custom_field_id': '13', 'value': 'Academic Personnel', 'id': '5' }, { 'custom_field_id': '12', 'value': '21184', 'id': '6' }, { 'custom_field_id': '17', 'value': 'Seattle Campus', 'id': '7' }, { 'custom_field_id': '14', 'value': 'SOM:', 'id': '8' }, { 'custom_field_id': '15', 'value': 'Family Medicine: Volunteer JM Academic', 'id': '9' }, { 'custom_field_id': '16', 'value': '00753', 'id': '10' }, { 'custom_field_id': '21', 'value': None, 'id': '24' }, { 'custom_field_id': '23', 'value': None, 'id': '25' }, { 'custom_field_id': '22', 'value': None, 'id': '26' }, { 'custom_field_id': '27', 'value': None, 'id': '27' }, { 'custom_field_id': '24', 'value': None, 'id': '28' }, { 'custom_field_id': '25', 'value': None, 'id': '29' }, { 'custom_field_id': '26', 'value': None, 'id': '30' }, { 'custom_field_id': '6', 'value': '000000005' }] } }) worker = BridgeWorker() user = worker.bridge.get_user_by_uwnetid('ellen') person = get_person('retiree') worker.set_bridge_user_to_update(person, get_worker(person), user) # self.maxDiff = None self.assertEqual( user.to_json_patch(), { 'user': { 'uid': '*****@*****.**', 'full_name': 'Ellen Louise Retiree', 'email': '*****@*****.**', 'id': 194, 'first_name': 'Ellen L', 'last_name': 'Retiree', 'sortable_name': 'Retiree, Ellen L', 'manager_id': None, 'custom_field_values': [{ 'custom_field_id': '5', 'value': '10000000000000000000000000000006', 'id': '1' }, { 'custom_field_id': '6', 'value': '000000006', 'id': '2' }, { 'custom_field_id': '7', 'value': '0000006', 'id': '3' }, { 'custom_field_id': '11', 'value': None, 'id': '4' }, { 'custom_field_id': '13', 'value': None, 'id': '5' }, { 'custom_field_id': '12', 'value': None, 'id': '6' }, { 'custom_field_id': '17', 'value': None, 'id': '7' }, { 'custom_field_id': '14', 'value': None, 'id': '8' }, { 'custom_field_id': '15', 'value': None, 'id': '9' }, { 'custom_field_id': '16', 'value': None, 'id': '10' }, { 'custom_field_id': '21', 'value': None, 'id': '24' }, { 'custom_field_id': '23', 'value': None, 'id': '25' }, { 'custom_field_id': '22', 'value': None, 'id': '26' }, { 'custom_field_id': '27', 'value': None, 'id': '27' }, { 'custom_field_id': '24', 'value': None, 'id': '28' }, { 'custom_field_id': '25', 'value': None, 'id': '29' }, { 'custom_field_id': '26', 'value': None, 'id': '30' }] } })
def test_load_hrp_bridge(self): time.sleep(2) set_db_records() call_command('sync_accounts', 'hrp')