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)
Exemple #2
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())
Exemple #3
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())
Exemple #4
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'))
Exemple #5
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))
Exemple #6
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())
Exemple #7
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)
Exemple #8
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)
 def test_load(self):
     set_uw_account("javerage")
     set_uw_account("staff")
     set_uw_account("tyler")
     self.assertEqual(load(),
                      "Updated employee_ids for 3 out of 3 users")
     self.assertEqual(get_by_employee_id("123456789").netid, "javerage")
     self.assertEqual(get_by_employee_id("100000001").netid, "staff")
     self.assertEqual(get_by_employee_id("000000005").netid, "tyler")
Exemple #10
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 set_db_records():
    affiemp = set_uw_account("affiemp")

    javerage = set_uw_account("javerage")

    ellen = set_uw_account("ellen")

    staff = set_uw_account("staff")
    staff.set_disable()

    retiree = set_uw_account("retiree")

    tyler = set_uw_account("faculty")

    leftuw = set_uw_account("leftuw")
    leftuw.set_terminate_date()

    testid = set_uw_account("testid")