示例#1
0
    def test_match_bridge_account(self):
        # 500 error
        uw_acc = set_uw_account("error500")
        loader = GwsBridgeLoader(BridgeWorker())
        self.assertRaises(DataFailureException, loader.match_bridge_account,
                          uw_acc)

        # account not exist
        uw_acc = set_uw_account("affiemp")
        loader = GwsBridgeLoader(BridgeWorker())
        bri_acc = loader.match_bridge_account(uw_acc)
        self.assertIsNone(bri_acc)

        # account is deleted
        uw_acc = set_uw_account("staff")
        bri_acc = loader.match_bridge_account(uw_acc)
        self.assertIsNone(bri_acc)

        # exists an account with a prior netid
        uw_acc = set_uw_account("faculty")
        uw_acc.prev_netid = 'tyler'
        bri_acc = loader.match_bridge_account(uw_acc)
        self.assertEqual(bri_acc.netid, 'tyler')

        # exists two accounts (one with Lreaning History one without),
        # pick the one with LH
        uw_acc = set_uw_account("retiree")
        uw_acc.bridge_id = 204
        uw_acc.prev_netid = "ellen"
        uw_acc1 = set_uw_account("ellen")
        bri_acc = loader.match_bridge_account(uw_acc)
        self.assertEqual(bri_acc.netid, 'ellen')
        self.assertEqual(bri_acc.bridge_id, 194)
示例#2
0
 def test_update_custom_field(self):
     worker = BridgeWorker()
     bridge_account = worker.bridge.get_user_by_uwnetid('tyler')
     cf = bridge_account.get_custom_field(
         BridgeCustomField.POS1_BUDGET_CODE)
     value = "12345"
     worker.update_custom_field(bridge_account,
                                BridgeCustomField.POS1_BUDGET_CODE, value)
     self.assertEqual(cf.value, value)
示例#3
0
 def test_load_abort(self):
     with self.settings(ERRORS_TO_ABORT_LOADER=[500],
                        BRIDGE_USER_WORK_POSITIONS=2,
                        BRIDGE_GWS_CACHE='/tmp/gwsuser3'):
         set_db_err_records()
         loader = GwsBridgeLoader(BridgeWorker())
         self.assertRaises(DataFailureException, loader.load)
 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_termination(self):
        # normal case
        uw_acc = set_uw_account("leftuw")
        uw_acc.set_bridge_id(200)
        loader = ActiveWkrLoader(BridgeWorker())
        loader.process_termination(uw_acc)
        self.assertEqual(loader.get_deleted_count(), 0)
        uw_acc1 = UwAccount.get("leftuw")
        self.assertTrue(uw_acc1.has_terminate_date())
        self.assertFalse(uw_acc1.disabled)

        uw_acc.terminate_at = get_now() - timedelta(days=(GRACE_PERIOD + 1))
        loader.process_termination(uw_acc)
        self.assertEqual(loader.get_deleted_count(), 1)
        uw_acc1 = UwAccount.get("leftuw")
        self.assertTrue(uw_acc.disabled)

        # Having unmatched uwnetid
        uw_acc = set_uw_account("alumni")
        uw_acc.set_bridge_id(199)
        loader.terminate_uw_account(uw_acc)
        self.assertEqual(loader.get_deleted_count(), 1)
        self.assertFalse(UwAccount.get("alumni").disabled)

        # Already deleted in Bridge
        uw_acc = set_uw_account("staff")
        uw_acc.set_bridge_id(196)
        loader.terminate_uw_account(uw_acc)
        self.assertEqual(loader.get_deleted_count(), 1)
        self.assertTrue(UwAccount.get("staff").disabled)
    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())
示例#7
0
    def test_del_bridge_account(self):
        loader = GwsBridgeLoader(BridgeWorker())
        ellen = loader.get_bridge().get_user_by_uwnetid('ellen')
        self.assertFalse(loader.del_bridge_account(ellen))

        retiree = loader.get_bridge().get_user_by_uwnetid('retiree')
        self.assertTrue(loader.del_bridge_account(retiree))
        self.assertEqual(loader.get_deleted_count(), 1)
 def test_to_check(self):
     loader = ActiveWkrLoader(BridgeWorker())
     person = get_person("affiemp")
     self.assertTrue(loader.to_check(person))
     person = get_person("leftuw")
     self.assertFalse(loader.to_check(person))
     person = get_person("alumni")
     self.assertFalse(loader.to_check(person))
示例#9
0
 def test_fetch_users(self):
     with self.settings(BRIDGE_GWS_CACHE='/tmp/gwsuser1'):
         loader = GwsBridgeLoader(BridgeWorker())
         user_list = loader.fetch_users()
         self.assertEqual(len(user_list), 7)
         self.assertEqual(sorted(user_list), [
             'affiemp', 'error500', 'faculty', 'javerage', 'not_in_pws',
             'retiree', 'staff'
         ])
示例#10
0
    def test_add_new_user(self):
        worker = BridgeWorker()
        person = get_person('affiemp')
        uw_acc = set_uw_account('affiemp')
        worker.add_new_user(uw_acc, person, get_worker(person))
        self.assertEqual(worker.get_new_user_count(), 1)

        person = get_person('javerage')
        uw_acc = set_uw_account('javerage')
        worker.add_new_user(uw_acc, person, get_worker(person))
        self.assertTrue(worker.has_err())
示例#11
0
 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_errors(self):
     set_db_err_records()
     loader = ActiveWkrLoader(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_total_count(), 2)
     self.assertFalse(loader.has_error())
     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)
示例#14
0
    def test_update_user_with_uid_change(self):
        worker = BridgeWorker()
        uw_acc = set_uw_account('faculty')
        uw_acc.prev_netid = 'tyler'
        uw_acc.set_bridge_id(198)
        self.assertTrue(uw_acc.netid_changed())
        person = get_person('faculty')
        bri_acc = worker.bridge.get_user_by_uwnetid('tyler')
        worker.update_user(bri_acc, uw_acc, person, get_worker(person))
        self.assertEqual(worker.get_netid_changed_count(), 1)
        self.assertEqual(worker.get_updated_count(), 1)

        uw_acc = set_uw_account('retiree')
        uw_acc.prev_netid = 'ellen'
        uw_acc.set_bridge_id(194)
        self.assertTrue(uw_acc.netid_changed())
        person = get_person('retiree')
        bri_acc = worker.bridge.get_user_by_uwnetid('ellen')
        worker.update_user(bri_acc, uw_acc, person, get_worker(person))
        self.assertEqual(worker.get_netid_changed_count(), 2)
        self.assertEqual(worker.get_updated_count(), 2)
    def handle(self, *args, **options):
        bridge_id = options['bridge_id']
        netid = options['netid']
        old_netid = options['old_netid']

        if bridge_id:
            try:
                user = get_user_by_bridgeid(bridge_id)
            except UwBridgeUser.DoesNotExist:
                print "%s not found in DB" % bridge_id
                return
            print "Find Bridge user by bridge_id: %s" % user
            if user.netid != netid:
                print "Netid not match: %s %s" % (user.netid, netid)
                return
            if user.has_prev_netid() and\
               user.prev_netid == old_netid:
                pass
            else:
                user.set_prev_netid(old_netid)

            worker = BridgeWorker()
            print "Work.update %s" % user
            worker.update_uid(user)

            print "Changed netid: %d" % worker.get_netid_changed_count()
            if worker.has_error():
                print "Errors: %s" % worker.get_error_report()
示例#16
0
 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())
示例#17
0
 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())
示例#18
0
    def test_delete_user(self):
        worker = BridgeWorker()
        bri_acc = worker.bridge.get_user_by_uwnetid('retiree')
        self.assertTrue(worker.delete_user(bri_acc))
        self.assertEqual(worker.get_deleted_count(), 1)

        bri_acc.bridge_id = 0
        self.assertFalse(worker.delete_user(bri_acc))
        self.assertTrue(worker.has_err())
    def test__update_user(self):
        uw_user, person = mock_uw_bridge_user('javerage')
        uw_user.regid = "0136CCB8F66711D5BE060004AC494FFE"
        uw_user.set_action_update()
        # regid not change, other attributes changed
        worker = BridgeWorker()
        worker._update_user(uw_user)
        self.assertEqual(worker.get_loaded_count(), 1)
        self.assertEqual(worker.get_regid_changed_count(), 0)

        user = UwBridgeUser.objects.get(netid='javerage')
        self.assertTrue(user.no_action())

        worker = BridgeWorker()
        worker._update_user(self.get_not_exist_user())
        self.assertEqual(worker.get_loaded_count(), 0)
        try:
            user = UwBridgeUser.objects.get(netid='notexist')
        except UwBridgeUser.DoesNotExist:
            pass
示例#20
0
    def test_is_priority_change(self):
        loader = GwsBridgeLoader(BridgeWorker())
        uw_acc = UwAccount.objects.create(netid="affiemp")
        self.assertTrue(loader.is_priority_change(uw_acc))

        uw_acc = set_uw_account("faculty")
        uw_acc.prev_netid = "tyler"
        self.assertTrue(loader.is_priority_change(uw_acc))

        uw_acc = set_uw_account("leftuw")
        uw_acc.terminate_at = get_now()
        self.assertTrue(loader.is_priority_change(uw_acc))

        uw_acc = set_uw_account("staff")
        uw_acc.disabled = True
        self.assertTrue(loader.is_priority_change(uw_acc))
示例#21
0
    def test_restore_user(self):
        uw_acc = set_uw_account('staff')
        uw_acc.set_bridge_id(196)
        worker = BridgeWorker()
        bri_acc = worker.restore_user(uw_acc)
        self.assertIsNotNone(bri_acc)
        self.assertFalse(uw_acc.disabled)
        self.assertEqual(worker.get_restored_count(), 1)

        self.assertIsNone(worker.restore_user(set_uw_account('javerage')))
        self.assertTrue(worker.has_err())
示例#22
0
    def test_update_uid(self):
        worker = BridgeWorker()
        uw_acc = set_uw_account('faculty')
        uw_acc.prev_netid = 'tyler'
        uw_acc.set_bridge_id(198)
        self.assertTrue(uw_acc.netid_changed())
        worker.update_uid(uw_acc)
        self.assertEqual(worker.get_netid_changed_count(), 1)
        self.assertFalse(worker.has_err())

        self.assertRaises(DataFailureException, worker.update_uid,
                          set_uw_account('javerage'))
示例#23
0
    def handle(self, *args, **options):
        timer = Timer()
        logger.info("Start at {0}".format(datetime.now()))

        source = options['data-source']
        workr = BridgeWorker()
        if source == 'gws':
            loader = GwsBridgeLoader(workr)
        elif source == 'db-emp':
            loader = ActiveWkrLoader(workr)
        elif source == 'db-other':
            loader = OtherUserLoader(workr)
        elif source == 'bridge':
            loader = BridgeChecker(workr)
        elif source == 'pws':
            loader = PwsBridgeLoader(workr)
        elif source == 'hrp':
            loader = HrpBridgeLoader(workr)
        else:
            logger.info("Invalid data source, abort!")
            return
        try:
            loader.load()
        except Exception as ex:
            logger.error(str(ex))

        log_resp_time(logger, "Load users", timer)

        logger.info("Checked {0:d} users, source: {1}\n".format(
            loader.get_total_checked_users(), source))

        logger.info("{0:d} new users added\n".format(
            loader.get_new_user_count()))
        logger.info("{0:d} users changed netid\n".format(
            loader.get_netid_changed_count()))
        logger.info("{0:d} users deleted\n".format(
            loader.get_deleted_count()))
        logger.info("{0:d} users restored\n".format(
            loader.get_restored_count()))
        logger.info("{0:d} users updated\n".format(
            loader.get_updated_count()))

        if loader.has_error():
            logger.error("Errors: {0}".format(loader.get_error_report()))
    def test_add_new_user(self):
        worker = BridgeWorker()
        # exists
        uw_user, person = mock_uw_bridge_user('staff')

        uw_user.set_action_new()
        worker.add_new_user(uw_user)
        self.assertEqual(worker.get_new_user_count(), 0)
        self.assertEqual(worker.get_loaded_count(), 0)

        user = UwBridgeUser.objects.get(netid='staff')
        self.assertTrue(user.no_action())
        self.assertEqual(user.bridge_id, 196)

        # new
        uw_user, person = mock_uw_bridge_user('faculty')
        uw_user.set_action_new()
        worker.add_new_user(uw_user)
        self.assertEqual(worker.get_new_user_count(), 1)
        self.assertEqual(worker.get_loaded_count(), 1)

        user = UwBridgeUser.objects.get(netid='faculty')
        self.assertTrue(user.no_action())
        self.assertEqual(user.bridge_id, 201)
示例#25
0
    def test_field_not_changed(self):
        with self.settings(BRIDGE_USER_WORK_POSITIONS=2):
            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.regid_not_changed(bridge_account, person))
            self.assertTrue(loader.eid_not_changed(bridge_account, person))
            self.assertTrue(loader.sid_not_changed(bridge_account, person))
            self.assertTrue(
                loader.pos_data_not_changed(bridge_account, hrp_wkr))

            person = get_person('faculty')
            hrp_wkr = get_worker(person)
            bridge_account = loader.get_bridge().get_user_by_uwnetid('tyler')
            self.assertFalse(loader.regid_not_changed(bridge_account, person))
            self.assertFalse(loader.eid_not_changed(bridge_account, person))
            self.assertFalse(loader.sid_not_changed(bridge_account, person))
            self.assertFalse(
                loader.pos_data_not_changed(bridge_account, hrp_wkr))
示例#26
0
    def test_apply_change_to_bridge(self):
        loader = GwsBridgeLoader(BridgeWorker())

        # add new account
        uw_acc = set_uw_account("affiemp")
        affiemp = get_person("affiemp")
        loader.apply_change_to_bridge(uw_acc, affiemp)
        self.assertEqual(loader.get_new_user_count(), 1)
        self.assertEqual(loader.get_updated_count(), 0)

        # restore
        uw_acc = set_uw_account("staff")
        uw_acc.set_bridge_id(196)
        uw_acc.set_disable()
        staff = get_person("staff")
        loader.apply_change_to_bridge(uw_acc, staff)
        self.assertEqual(loader.get_restored_count(), 1)
        self.assertEqual(loader.get_updated_count(), 1)

        # change uid and update
        uw_acc = set_uw_account('faculty')
        uw_acc.prev_netid = 'tyler'
        uw_acc.set_bridge_id(198)
        faculty = get_person("faculty")
        loader.apply_change_to_bridge(uw_acc, faculty)
        self.assertEqual(loader.get_netid_changed_count(), 1)
        self.assertEqual(loader.get_updated_count(), 2)

        # change uid and update
        uw_acc = set_uw_account("retiree")
        uw_acc.bridge_id = 204
        uw_acc.prev_netid = "ellen"
        retiree = get_person("retiree")
        loader.apply_change_to_bridge(uw_acc, retiree)
        self.assertEqual(loader.get_netid_changed_count(), 2)
        self.assertEqual(loader.get_updated_count(), 3)
 def test_errors(self):
     set_db_err_records()
     loader = OtherUserLoader(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_total_checked_users(), 1)
     self.assertTrue(loader.has_error())
示例#28
0
    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(self):
     set_db_records()
     set_db_err_records()
     loader = AuthorChecker(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_updated_count(), 2)
示例#30
0
    def test_update_user_wo_uid_change(self):
        worker = BridgeWorker()
        uw_acc = set_uw_account('staff')
        uw_acc.set_bridge_id(196)
        person = get_person('staff')
        bri_acc = worker.restore_user(uw_acc)
        worker.update_user(bri_acc, uw_acc, person, get_worker(person))
        self.assertEqual(worker.get_netid_changed_count(), 0)
        self.assertEqual(worker.get_updated_count(), 1)

        worker = BridgeWorker()
        bridge_account = worker.bridge.get_user_by_uwnetid('retiree')
        person = get_person('retiree')
        worker.update_user(bridge_account, set_uw_account('retiree'), person,
                           get_worker(person))
        self.assertEqual(worker.get_updated_count(), 0)
        self.assertTrue(worker.has_err())
示例#31
0
 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_to_check(self):
     loader = OtherUserLoader(BridgeWorker())
     person = get_person("retiree")
     self.assertFalse(loader.to_check(person))
     person = get_person("leftuw")
     self.assertTrue(loader.to_check(person))
示例#33
0
 def test_update_user_role(self):
     worker = BridgeWorker()
     bridge_account = worker.bridge.get_user_by_uwnetid('tyler')
     worker.update_user_role(bridge_account)
     self.assertTrue(worker.has_err())
    def handle(self, *args, **options):
        total_new = 0
        total_del = 0
        total_restore = 0
        total_update = 0
        total_change_netid = 0
        worker = BridgeWorker()

        for uw_bridge_user in fetch_users_from_db(logger):

            if uw_bridge_user.is_restore():
                total_restore += 1
                try:
                    worker.restore_user(uw_bridge_user)
                except Exception as ex:
                    logger.error("Restore %s ==>%s", uw_bridge_user, ex)

            elif uw_bridge_user.is_new():
                total_new += 1
                try:
                    worker.add_new_user(uw_bridge_user)
                except Exception as ex:
                    logger.error("Add %s ==>%s", uw_bridge_user, ex)

            elif uw_bridge_user.passed_terminate_date():
                if not uw_bridge_user.disabled:
                    total_del += 1
                    worker.delete_user(uw_bridge_user)

            elif uw_bridge_user.netid_changed():
                total_change_netid += 1
                try:
                    if worker.update_uid(uw_bridge_user):
                        worker._update_user(uw_bridge_user)
                except Exception as ex:
                    logger.error("Update UID %s ==>%s", uw_bridge_user, ex)

            elif (uw_bridge_user.regid_changed() or
                  uw_bridge_user.is_update()):
                total_update += 1
                try:
                    worker._update_user(uw_bridge_user)
                except Exception as ex:
                    logger.error("Update %s ==>%s", uw_bridge_user, ex)

        print "Total %d users to add" % total_new
        print "Added %d users" % worker.get_new_user_count()

        print "Total %d users to delete" % total_del
        print "Deleted %d users" % worker.get_deleted_count()

        print "Total %d users to restore" % total_restore
        print "Restored %d users" % worker.get_restored_count()

        print "Total %d changed netid" % total_change_netid
        print "NetId changed: %d" % worker.get_netid_changed_count()
        print "RegId changed: %d" % worker.get_regid_changed_count()

        print "Loaded: %d" % worker.get_loaded_count()
    def test_restore_user(self):
        # normal case
        worker = BridgeWorker()
        uw_user, person = mock_uw_bridge_user('botgrad')
        uw_user.bridge_id = 203
        uw_user.disabled = True
        uw_user.set_action_restore()
        worker.restore_user(uw_user)
        self.assertEqual(worker.get_restored_count(), 1)

        user = UwBridgeUser.objects.get(netid='botgrad')
        self.assertFalse(user.disabled)

        # restored user netid and regid not match
        uw_user = UwBridgeUser(netid='javerage',
                               bridge_id=195,
                               regid="9136CCB8F66711D5BE060004AC494FFE",
                               last_visited_at=get_now(),
                               disabled=True,
                               first_name="James",
                               last_name="Student",
                               email="*****@*****.**")
        uw_user.set_action_restore()
        worker.restore_user(uw_user)
        self.assertEqual(worker.get_restored_count(), 2)

        user = UwBridgeUser.objects.get(netid='javerage')
        self.assertFalse(user.disabled)
        self.assertTrue(user.no_action())

        worker = BridgeWorker()
        worker.restore_user(self.get_not_exist_user())
        self.assertFalse(worker.has_err())
        self.assertEqual(worker.get_restored_count(), 0)
        try:
            user = UwBridgeUser.objects.get(netid='notexist')
        except UwBridgeUser.DoesNotExist:
            pass
    def test_netid_change_user(self):
        worker = BridgeWorker()
        uw_user, person = mock_uw_bridge_user('javerage')
        uw_user.prev_netid = 'changed'
        self.assertTrue(worker.update_uid(uw_user))
        self.assertFalse(uw_user.netid_changed())
        self.assertEqual(worker.get_netid_changed_count(), 1)
        self.assertEqual(worker.get_loaded_count(), 0)

        user = UwBridgeUser.objects.get(netid='javerage')
        self.assertTrue(user.no_action())
        self.assertIsNone(user.prev_netid)
        self.assertEqual(user.bridge_id, 195)

        worker = BridgeWorker()
        uw_user, person = mock_uw_bridge_user('javerage')
        uw_user.prev_netid = 'changed'
        uw_user.set_action_update()
        worker.update_user(uw_user)
        self.assertFalse(worker.has_err())
        self.assertEqual(worker.get_netid_changed_count(), 1)
        self.assertEqual(worker.get_loaded_count(), 1)

        user = UwBridgeUser.objects.get(netid='javerage')
        self.assertTrue(user.no_action())
        self.assertIsNone(user.prev_netid)
        self.assertEqual(user.bridge_id, 195)

        uw_user, person = mock_uw_bridge_user('staff')
        uw_user.prev_netid = 'changed'
        self.assertFalse(worker.update_uid(uw_user))
        self.assertTrue(worker.has_err())

        worker = BridgeWorker()
        worker.update_uid(self.get_not_exist_user())
        self.assertEqual(worker.get_netid_changed_count(), 0)
        self.assertEqual(worker.get_loaded_count(), 0)
        try:
            user = UwBridgeUser.objects.get(netid='notexist')
        except UwBridgeUser.DoesNotExist:
            pass
    def test_delete_user(self):
        uw_user, person = mock_uw_bridge_user('javerage')
        worker = BridgeWorker()
        worker.delete_user(uw_user, is_merge=True)
        self.assertEqual(worker.get_deleted_count(), 0)

        uw_user.bridge_id = 195
        worker.delete_user(uw_user, is_merge=True)
        self.assertEqual(worker.get_deleted_count(), 0)

        uw_user, person = mock_uw_bridge_user('leftuw')
        uw_user.bridge_id = 200
        worker.delete_user(uw_user, is_merge=False)
        self.assertEqual(worker.get_deleted_count(), 1)

        user = UwBridgeUser.objects.get(netid='leftuw')
        self.assertTrue(user.no_action())
        self.assertTrue(user.disabled)

        user = UwBridgeUser.objects.get(netid='leftuw')
        self.assertTrue(user.no_action())
        self.assertTrue(user.disabled)

        worker.delete_user(self.get_not_exist_user(), is_merge=False)
        try:
            user = UwBridgeUser.objects.get(netid='notexist')
        except UwBridgeUser.DoesNotExist:
            pass
    def test_update_user(self):
        worker = BridgeWorker()
        uw_user, person = mock_uw_bridge_user('staff')
        uw_user.set_action_update()
        worker.update_user(uw_user)
        # no change, skipped
        self.assertEqual(worker.get_netid_changed_count(), 0)
        self.assertEqual(worker.get_regid_changed_count(), 0)
        self.assertEqual(worker.get_loaded_count(), 0)

        uw_user, person = mock_uw_bridge_user('javerage')
        uw_user.set_action_regid_changed()
        worker.update_user(uw_user)
        self.assertEqual(worker.get_netid_changed_count(), 0)
        self.assertEqual(worker.get_regid_changed_count(), 1)
        self.assertEqual(worker.get_loaded_count(), 1)

        uw_user.bridge_id = 195
        uw_user.set_action_regid_changed()
        worker.update_user(uw_user)
        self.assertEqual(worker.get_netid_changed_count(), 0)
        self.assertEqual(worker.get_regid_changed_count(), 2)
        self.assertEqual(worker.get_loaded_count(), 2)

        user = UwBridgeUser.objects.get(netid='javerage')
        self.assertTrue(user.no_action())