def test_get_attr_list_nohrp(self):
        user = UwBridgeUser(netid='staff',
                            regid="10000000000000000000000000000001",
                            last_visited_at=get_now(),
                            display_name="James Staff",
                            last_name="Staf")
        user_attr_list = get_attr_list(user)
        self.assertEqual(len(user_attr_list), 4)
        self.assertEqual(user_attr_list[0],
                         "*****@*****.**")

        user = UwBridgeUser(netid='faculty',
                            regid="10000000000000000000000000000005",
                            last_visited_at=get_now(),
                            first_name="James",
                            last_name="Faculty")
        user_attr_list = get_attr_list(user)
        self.assertEqual(len(user_attr_list), 4)
        self.assertEqual(user_attr_list[0],
                         "*****@*****.**")
        self.assertEqual(user_attr_list[1],
                         "James Faculty")
        self.assertEqual(user_attr_list[2],
                         "*****@*****.**")
        self.assertEqual(user_attr_list[3],
                         "10000000000000000000000000000005")
    def test_restore_bridge_user(self):
        uw_acc = UwAccount(netid='staff',
                           bridge_id=196,
                           last_updated=get_now())
        buser = TestBridge.bridge.restore_bridge_user(uw_acc)
        self.assertEqual(buser.netid, 'staff')

        uw_acc = UwAccount(netid='staff', last_updated=get_now())
        buser = TestBridge.bridge.restore_bridge_user(uw_acc)
        self.assertEqual(buser.bridge_id, 196)

        self.assertRaises(
            DataFailureException, TestBridge.bridge.restore_bridge_user,
            UwAccount(netid='none', bridge_id=300, last_updated=get_now()))
    def test_regid_change(self):
        user = UwBridgeUser(netid='retiree',
                            regid='0136CCB8F66711D5BE060004AC494FFE',
                            last_visited_at=get_now(),
                            first_name="Ellen",
                            last_name="Louise")
        user.save()
        person = get_person('retiree')
        old_user = _get_netid_changed_user([user], person)
        self.assertIsNone(old_user)
        self.assertTrue(_changed_regid([user], person))
        user_upd, user_del = save_user(person, include_hrp=False)
        self.assertIsNotNone(user_upd)
        self.assertTrue(user_upd.regid_changed())
        self.assertFalse(user_upd.netid_changed())
        self.assertIsNone(user_del)
        self.assertRaises(Exception,
                          get_user_by_regid,
                          '0136CCB8F66711D5BE060004AC494FFE')
        user_upd.delete()

        # user is disabled
        user.disabled = True
        user.save()
        user_upd, user_del = save_user(person, include_hrp=False)
        self.assertIsNotNone(user_upd)
        self.assertTrue(user_upd.is_restore())
        self.assertFalse(user_upd.netid_changed())
        self.assertIsNone(user_del)
    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_delete_user_csv_file(self):
     user = UwBridgeUser(netid='javerage',
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         bridge_id=195,
                         last_visited_at=get_now(),
                         terminate_at=get_now(),
                         last_name="Delete")
     user.save()
     user_loader = Reloader(CsvWorker())
     maker = CsvFileMaker(user_loader)
     fp = maker.get_file_path()
     number_users_wrote = maker.make_delete_user_file()
     self.assertEqual(number_users_wrote, 1)
     self.assertTrue(maker.is_file_wrote())
     os.remove(fp + "/busrs_delete.csv")
     os.rmdir(fp)
    def test_change_uwnetid(self):
        uw_user = UwBridgeUser(netid='javerage',
                               prev_netid='changed',
                               regid="9136CCB8F66711D5BE060004AC494FFE",
                               last_visited_at=get_now(),
                               display_name="James Student",
                               email="*****@*****.**")
        # normal
        buser = change_uwnetid(uw_user)
        self.assertEqual(buser.bridge_id, 195)
        self.assertEqual(buser.netid, 'javerage')

        # Skipped
        uw_user, person = mock_uw_bridge_user('staff')
        uw_user.bridge_id = 196
        buser = change_uwnetid(uw_user)
        self.assertEqual(buser.netid, 'staff')

        # on a terminated user
        user, person = mock_uw_bridge_user('botgrad')
        user.netid = 'newgrad'
        user.prev_netid = 'botgrad'
        user.bridge_id = 203
        self.assertIsNone(change_uwnetid(user))

        # not match
        user, person = mock_uw_bridge_user('leftuw')
        user.netid = 'newuw'
        user.prev_netid = 'withuw'
        user.bridge_id = 200
        self.assertIsNone(change_uwnetid(user))

        self.assertRaises(DataFailureException, change_uwnetid,
                          self.get_mock_user_unknown())
    def test_restore_bridge_user(self):
        # mornal case
        user, person = mock_uw_bridge_user('botgrad')
        user.bridge_id = 203
        buser = restore_bridge_user(user)
        self.assertEqual(buser.netid, 'botgrad')

        # netid changed
        user, person = mock_uw_bridge_user('tacgrad')
        user.bridge_id = 204
        buser = restore_bridge_user(user)
        self.assertEqual(buser.netid, 'oldgrad')

        # already exists
        uw_user = UwBridgeUser(netid='javerage',
                               regid="0136CCB8F66711D5BE060004AC494FFE",
                               last_visited_at=get_now(),
                               email='*****@*****.**',
                               display_name="James Student")
        user = restore_bridge_user(uw_user)
        self.assertEqual(user.netid, 'javerage')
        self.assertEqual(user.bridge_id, 195)

        self.assertRaises(DataFailureException, restore_bridge_user,
                          self.get_mock_user_unknown())
    def test_delete_bridge_user(self):
        # already deleted
        user, person = mock_uw_bridge_user('botgrad')
        user.bridge_id = 203
        self.assertTrue(delete_bridge_user(user, True))

        # normal case
        uw_user = UwBridgeUser(netid='leftuw',
                               regid="B814EFBC6A7C11D5A4AE0004AC494FFE",
                               bridge_id=200,
                               last_visited_at=get_now(),
                               display_name="Who LEFT",
                               first_name="WHO",
                               last_name="LEFT",
                               email="*****@*****.**")
        self.assertTrue(delete_bridge_user(uw_user, True))
        self.assertTrue(delete_bridge_user(uw_user, False))

        uw_user, person = mock_uw_bridge_user('javerage')
        uw_user.bridge_id = 195
        self.assertFalse(delete_bridge_user(uw_user, True))

        uw_user, person = mock_uw_bridge_user('staff')
        self.assertRaises(DataFailureException,
                          delete_bridge_user,
                          uw_user, False)
        uw_user.bridge_id = 196
        self.assertRaises(DataFailureException,
                          delete_bridge_user,
                          uw_user, False)

        self.assertRaises(DataFailureException, delete_bridge_user,
                          self.get_mock_user_unknown(), False)
    def test_netid_change(self):
        user = UwBridgeUser(netid='changed',
                            regid="10000000000000000000000000000006",
                            last_visited_at=get_now(),
                            first_name="Changed",
                            last_name="Netid")
        user.save()
        person = get_person('retiree')
        self.assertIsNotNone(person)
        old_user = _get_netid_changed_user([user], person)
        self.assertEqual(old_user.netid, 'changed')
        self.assertFalse(_changed_regid([user], person))

        user_upd, user_del = save_user(person, include_hrp=False)
        self.assertIsNotNone(user_upd)
        self.assertTrue(user_upd.netid_changed())
        self.assertFalse(user_upd.regid_changed())
        self.assertEqual(user_upd.prev_netid, 'changed')
        self.assertIsNone(user_del)
        user_upd.delete()

        # the case where user is disabled
        user.disabled = True
        user.save()
        user_upd, user_del = save_user(person, include_hrp=False)
        self.assertIsNotNone(user_upd)
        self.assertTrue(user_upd.netid_changed())
        self.assertEqual(user_upd.prev_netid, 'changed')
        self.assertTrue(user_upd.is_restore())
        self.assertIsNone(user_del)
    def test_set_bridge_ids_for_existing_users(self):
        self.assertEqual(set_bridge_ids(), 0)

        UwBridgeUser(netid='javerage',
                     regid='9136CCB8F66711D5BE060004AC494FFE',
                     last_visited_at=get_now(),
                     email='*****@*****.**',
                     first_name='James',
                     last_name='Average').save()

        UwBridgeUser(netid='leftuw',
                     regid="B814EFBC6A7C11D5A4AE0004AC494FFE",
                     last_visited_at=get_now(),
                     email='*****@*****.**',
                     first_name='Left',
                     last_name='UW').save()

        UwBridgeUser(netid='staff',
                     regid="10000000000000000000000000000001",
                     bridge_id=197,
                     last_visited_at=get_now(),
                     email='*****@*****.**',
                     first_name='Staff',
                     last_name='UW',
                     action_priority=1).save()

        UwBridgeUser(netid='toremove',
                     regid='10000000000000000000000000000000',
                     last_visited_at=get_now(),
                     email='*****@*****.**',
                     first_name='Not In',
                     last_name='Bridge').save()

        self.assertEqual(set_bridge_ids(), 3)

        user = get_user_by_netid('javerage')
        self.assertEqual(user.bridge_id, 195)

        user1 = get_user_by_netid('leftuw')
        self.assertEqual(user1.bridge_id, 200)

        user2 = get_user_by_netid('staff')
        self.assertEqual(user2.bridge_id, 196)
    def test_change_uwnetid(self):
        buser = TestBridge.bridge.get_user_by_bridgeid(198)
        self.assertEqual(buser.netid, 'tyler')

        uw_acc = UwAccount(netid='faculty',
                           bridge_id=198,
                           prev_netid='tyler',
                           last_updated=get_now())
        bridge_user = TestBridge.bridge.change_uwnetid(uw_acc)
        self.assertEqual(bridge_user.netid, 'faculty')
 def get_not_exist_user(self):
     user = UwBridgeUser(netid='notexist',
                         regid="0036CCB8F66711D5BE060004AC494FFE",
                         bridge_id=1200,
                         last_visited_at=get_now(),
                         first_name="Not",
                         last_name="Exist",
                         email="*****@*****.**")
     user.save()
     return user
Beispiel #13
0
    def test_uw_account(self):
        user = self.mock_uw_account('staff')
        self.assertFalse(user.has_terminate_date())

        user.set_ids(0, None)
        self.assertFalse(user.has_bridge_id())
        self.assertFalse(user.has_employee_id())

        self.assertFalse(user.has_bridge_id())
        user.set_ids(123, "100000005")
        self.assertTrue(user.has_bridge_id())
        self.assertEqual(user.bridge_id, 123)
        self.assertTrue(user.has_employee_id())
        self.assertEqual(user.employee_id, "100000005")

        qset = UwAccount.objects.filter(employee_id="100000005")
        self.assertEqual(len(qset), 1)
        self.assertEqual(qset[0].employee_id, "100000005")

        user.set_terminate_date()
        self.assertTrue(user.has_terminate_date())
        self.assertFalse(user.passed_terminate_date())
        date1 = user.terminate_at
        user.set_terminate_date()
        self.assertEqual(user.terminate_at, date1)

        user.terminate_at -= timedelta(days=GRACE_PERIOD + 1)
        self.assertTrue(user.passed_terminate_date())

        user.set_terminate_date(graceful=False)
        dtime = user.terminate_at
        self.assertTrue(get_now() < (dtime + timedelta(seconds=3)))

        user.prev_netid = 'staff0'
        self.assertTrue(user.has_prev_netid())
        self.assertTrue(user.netid_changed())
        user.prev_netid = None
        self.assertFalse(user.has_prev_netid())

        user.set_disable()
        self.assertTrue(user.disabled)
        user.set_restored()
        self.assertFalse(user.disabled)

        user.set_disable()
        user.set_terminate_date(graceful=False)
        user.prev_netid = 'staff0'

        user.set_updated()
        self.assertFalse(user.disabled)
        self.assertFalse(user.has_terminate_date())
        self.assertFalse(user.has_prev_netid())

        self.assertIsNotNone(user.json_data())
        self.assertIsNotNone(str(user))
    def test_terminate(self):
        user = UwBridgeUser(
            netid='leftuw',
            regid="B814EFBC6A7C11D5A4AE0004AC494FFE",
            last_visited_at=get_now(),
            email='*****@*****.**',
            first_name="Who",
            last_name="Left")
        user.save()
        loader = UserUpdater(CsvWorker())

        loader.load()
        db_user = get_user_by_netid('leftuw')
        self.assertIsNotNone(db_user.terminate_at)
        self.assertEqual(loader.get_deleted_count(), 0)

        user.terminate_at = get_now() - timedelta(days=(GRACE_PERIOD + 1))
        user.save()
        loader.load()
        self.assertEqual(loader.get_deleted_count(), 1)
 def test_restore(self):
     user = UwBridgeUser(netid='javerage',
                         bridge_id=195,
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         last_name="Restore")
     user.set_action_restore()
     loader = Reloader(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_restored_count(), 1)
def get_users(size=1):
    users = []
    i = 0
    while i < size:
        users.append(UwBridgeUser(regid="11111111111111111111111111111111",
                                  netid="dummy",
                                  prev_netid="prev_dummy",
                                  last_visited_at=get_now(),
                                  first_name="Al",
                                  last_name="Dummy"))
        i += 1
    return users
 def test_update_netid(self):
     user = UwBridgeUser(netid='changed',
                         bridge_id=195,
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         email="*****@*****.**",
                         last_visited_at=get_now(),
                         display_name="James Changed",
                         last_name="Changed")
     user.save()
     loader = BridgeChecker(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_netid_changed_count(), 1)
     self.assertEqual(loader.get_loaded_count(), 2)
 def test_changed_netid(self):
     user = UwBridgeUser(netid='changed',
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Student")
     user.save()
     loader = UserUpdater(BridgeWorker())
     loader.load()
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_new_user_count(), 0)
     self.assertEqual(loader.get_netid_changed_count(), 1)
     self.assertEqual(loader.get_regid_changed_count(), 0)
 def test_load_users_no_hrp(self):
     user = UwBridgeUser(netid='javerage',
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Changed")
     user.save()
     loader = GwsBridgeLoader(CsvWorker())
     loader.load()
     self.assertEqual(loader.get_total_count(), 12)
     self.assertEqual(loader.get_new_user_count(), 7)
     self.assertEqual(loader.get_loaded_count(), 8)
     self.assertEqual(loader.get_netid_changed_count(), 0)
     self.assertEqual(loader.get_regid_changed_count(), 0)
 def test_invaliduser(self):
     user = UwBridgeUser(
         netid='invaliduser',
         regid="1814EFBC6A7C11D5A4AE0004AC494FFE",
         last_visited_at=get_now() - timedelta(days=GRACE_PERIOD),
         email='*****@*****.**',
         first_name="Old",
         last_name="User")
     user.save()
     loader = UserUpdater(BridgeWorker())
     loader.load()
     self.assertRaises(UwBridgeUser.DoesNotExist,
                       get_user_by_netid,
                       'invaliduser')
     self.assertEqual(loader.get_deleted_count(), 0)
 def test_changed_regid(self):
     user = UwBridgeUser(netid='javerage',
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="Changed",
                         last_name="Regid")
     user.set_action_regid_changed()
     loader = Reloader(BridgeWorker())
     loader.load()
     bri_users = loader.get_users_to_process()
     self.assertEqual(len(bri_users), 1)
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_loaded_count(), 1)
     self.assertEqual(loader.get_netid_changed_count(), 0)
     self.assertEqual(loader.get_regid_changed_count(), 1)
def mock_uw_bridge_user(uwnetid):
    person = get_person(uwnetid)
    buser = UwBridgeUser()
    buser.netid = person.uwnetid
    buser.regid = person.uwregid
    buser.email = normalize_email(person.email1)
    buser.display_name = person.display_name
    buser.first_name = normalize_name(person.first_name)
    buser.last_name = normalize_name(person.surname)
    buser.is_alum = person.is_alum
    buser.is_employee = person.is_employee
    buser.is_faculty = person.is_faculty
    buser.is_staff = person.is_staff
    buser.is_student = person.is_student
    buser.last_visited_at = get_now()
    return buser, person
Beispiel #23
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))
 def test_restore_user_csv_file(self):
     user = UwBridgeUser(netid='javerage',
                         bridge_id=195,
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         last_name="Restore")
     user.action_priority = ACTION_RESTORE
     user.save()
     maker = CsvFileMaker(Reloader(CsvWorker(),
                                   include_hrp=False))
     fp = maker.get_file_path()
     number_users_wrote = maker.make_restore_user_file()
     self.assertEqual(number_users_wrote, 1)
     self.assertTrue(maker.is_file_wrote())
     os.remove(fp + "/busrs_restore.csv")
     os.rmdir(fp)
    def test_regid_change_user(self):
        user = UwBridgeUser(netid='javerage',
                            regid="0136CCB8F66711D5BE060004AC494FFE",
                            last_visited_at=get_now(),
                            first_name="Changed",
                            last_name="Regid")
        user.save()
        loader = GwsBridgeLoader(CsvWorker())
        loader.load()
        self.assertEqual(loader.get_regid_changed_count(), 1)

        users = loader.worker.get_users_regid_changed()
        self.assertEqual(users[0].netid, "javerage")
        self.assertEqual(users[0].regid,
                         "9136CCB8F66711D5BE060004AC494FFE")
        self.assertTrue(users[0].regid_changed())
 def test_error(self):
     loader = UserUpdater(BridgeWorker())
     user = UwBridgeUser(
         netid='renamed',
         regid="10000000000000000000000000000000",
         last_visited_at=get_now(),
         email='unknown',
         first_name="Who",
         last_name="Unknown")
     user.save()
     loader.load()
     self.assertTrue(loader.has_error())
     self.assertRaises(UwBridgeUser.DoesNotExist,
                       get_user_by_netid,
                       'unknown')
     self.assertEqual(loader.get_deleted_count(), 0)
 def test_update(self):
     user = UwBridgeUser(netid='javerage',
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Changed")
     user.save()
     loader = UserUpdater(CsvWorker())
     loader.load()
     bri_users = loader.get_users_to_process()
     self.assertEqual(len(bri_users), 1)
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_new_user_count(), 0)
     self.assertEqual(loader.get_loaded_count(), 1)
     self.assertEqual(loader.get_netid_changed_count(), 0)
     self.assertEqual(loader.get_regid_changed_count(), 0)
 def test_changed_regid(self):
     user = UwBridgeUser(netid='leftuw',
                         regid="56229F4D3B504559AF23956737A3CF9D",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="Who",
                         last_name="Left")
     user.save()
     loader = UserUpdater(CsvWorker())
     loader.load()
     bri_users = loader.get_users_to_process()
     self.assertEqual(len(bri_users), 1)
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_loaded_count(), 0)
     self.assertEqual(loader.get_new_user_count(), 0)
     self.assertEqual(loader.get_netid_changed_count(), 0)
     self.assertEqual(loader.get_regid_changed_count(), 1)
 def test_changed_regid(self):
     user = UwBridgeUser(netid='javerage',
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Changed")
     user.save()
     loader = UserUpdater(BridgeWorker())
     loader.load()
     self.assertRaises(UwBridgeUser.DoesNotExist,
                       get_user_by_regid,
                       "0136CCB8F66711D5BE060004AC494FFE")
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_new_user_count(), 0)
     self.assertEqual(loader.get_loaded_count(), 1)
     self.assertEqual(loader.get_regid_changed_count(), 1)
    def test_restore_user(self):
        user = UwBridgeUser(netid='javerage',
                            regid="9136CCB8F66711D5BE060004AC494FFE",
                            last_visited_at=get_now(),
                            disabled=True,
                            email='*****@*****.**',
                            first_name="James",
                            last_name="Changed")
        user.save()
        loader = GwsBridgeLoader(CsvWorker())
        loader.load()
        self.assertEqual(loader.get_restored_count(), 1)

        users = loader.worker.get_users_to_restore()
        self.assertEqual(users[0].netid, "javerage")
        self.assertEqual(users[0].regid,
                         "9136CCB8F66711D5BE060004AC494FFE")
        self.assertTrue(users[0].is_restore())
 def test_changed_netid(self):
     user = UwBridgeUser(netid='javerage',
                         bridge_id=195,
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         prev_netid='changed',
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Student")
     user.set_action_update()
     loader = Reloader(BridgeWorker())
     loader.load()
     bri_users = loader.get_users_to_process()
     self.assertEqual(len(bri_users), 1)
     self.assertEqual(loader.get_total_count(), 1)
     self.assertEqual(loader.get_loaded_count(), 1)
     self.assertEqual(loader.get_netid_changed_count(), 1)
     self.assertEqual(loader.get_regid_changed_count(), 0)
 def test_netid_change_user_csv_file(self):
     user = UwBridgeUser(netid='changed',
                         bridge_id=195,
                         prev_netid='javerage',
                         regid="9136CCB8F66711D5BE060004AC494FFE",
                         action_priority=ACTION_UPDATE,
                         last_visited_at=get_now(),
                         first_name="Changed",
                         last_name="Netid")
     user.save()
     maker = CsvFileMaker(Reloader(CsvWorker(),
                                   include_hrp=False))
     fp = maker.get_file_path()
     number_users_wrote = maker.make_netid_change_user_file()
     self.assertEqual(number_users_wrote, 1)
     self.assertTrue(maker.is_file_wrote())
     os.remove(fp + "/busrs_netid_changed.csv")
     os.rmdir(fp)
 def test_regid_change_csv_file(self):
     user = UwBridgeUser(netid='javerage',
                         regid="0136CCB8F66711D5BE060004AC494FFE",
                         action_priority=ACTION_CHANGE_REGID,
                         last_visited_at=get_now(),
                         email='*****@*****.**',
                         first_name="James",
                         last_name="Student")
     user.save()
     user_loader = Reloader(CsvWorker(),
                            include_hrp=False)
     maker = CsvFileMaker(user_loader)
     fp = maker.get_file_path()
     number_users_wrote = maker.make_regid_change_user_file()
     self.assertEqual(number_users_wrote, 1)
     self.assertTrue(maker.is_file_wrote())
     os.remove(fp + "/busrs_regid_changed.csv")
     os.rmdir(fp)
    def test_update(self):
        user = UwBridgeUser(netid='javerage',
                            regid="9136CCB8F66711D5BE060004AC494FFE",
                            last_visited_at=get_now(),
                            email='*****@*****.**',
                            display_name="James Changed",
                            last_name="Changed")
        user.save()
        loader = UserUpdater(BridgeWorker())

        bri_users = loader.fetch_users()
        self.assertEqual(len(bri_users), 1)
        self.assertEqual(bri_users[0].netid, 'javerage')

        loader.load()
        self.assertEqual(loader.get_total_count(), 1)
        self.assertEqual(loader.get_new_user_count(), 0)
        self.assertEqual(loader.get_loaded_count(), 1)
        self.assertEqual(loader.get_netid_changed_count(), 0)
        self.assertEqual(loader.get_regid_changed_count(), 0)
        self.assertFalse(loader.has_error())
    def test_get_bridge_user_to_upd(self):
        uw_user = UwBridgeUser(netid='javerage',
                               regid="9136CCB8F66711D5BE060004AC494FFE",
                               bridge_id=195,
                               last_visited_at=get_now(),
                               display_name="James Student",
                               first_name="James",
                               last_name="Student",
                               email="*****@*****.**")
        buser0 = get_bridge_user_object(uw_user)
        self.assertFalse(buser0.no_learning_history())
        self.assertFalse(_no_change(uw_user, buser0))
        self.assertTrue(_custom_field_no_change(uw_user, buser0))

        buser = _get_bridge_user_to_upd(uw_user, buser0)
        self.assertEqual(
            buser.to_json_patch(),
            {'user': {'id': 195,
                      'last_name': 'Student',
                      'uid': '*****@*****.**',
                      'full_name': 'James Student',
                      'email': '*****@*****.**'}})
 def __init__(self, worker, clogger=logger):
     super(BridgeChecker, self).__init__(worker, clogger)
     self.data_source = "Bridge daily users"
     self.login_window = get_login_window()
     if self.login_window > 0:
         self.check_time = get_now() - timedelta(days=self.login_window)
 def mock_uw_account(self, uwnetid):
     return UwAccount.objects.create(netid=uwnetid, last_updated=get_now())