def test_is_username_retired_is_retired():
    """
    Check functionality of is_username_retired when username is retired
    """
    user = UserFactory()
    original_username = user.username
    retired_username = get_retired_username_by_username(user.username)

    # Fake username retirement.
    user.username = retired_username
    user.save()

    assert is_username_retired(original_username)
def test_is_username_retired_is_retired():
    """
    Check functionality of is_username_retired when username is retired
    """
    user = UserFactory()
    original_username = user.username
    retired_username = get_retired_username_by_username(user.username)

    # Fake username retirement.
    user.username = retired_username
    user.save()

    assert is_username_retired(original_username)
Beispiel #3
0
    def test_retired_username(self):
        """
        Ensure that a retired username cannot be registered again.
        """
        user = UserFactory()
        orig_username = user.username

        # Fake retirement of the username.
        user.username = get_retired_username_by_username(orig_username)
        user.save()

        # Attempt to create another account with the same username that's been retired.
        self.url_params['username'] = orig_username
        response = self.client.post(self.url, self.url_params)
        self._validate_exiting_username_response(orig_username, response)
    def test_retired_username(self):
        """
        Ensure that a retired username cannot be registered again.
        """
        user = UserFactory()
        orig_username = user.username

        # Fake retirement of the username.
        user.username = get_retired_username_by_username(orig_username)
        user.save()

        # Attempt to create another account with the same username that's been retired.
        self.url_params['username'] = orig_username
        response = self.client.post(self.url, self.url_params)
        self._validate_exiting_username_response(orig_username, response, self.INVALID_ERR_MSG[0], self.INVALID_ERR_MSG[1])
Beispiel #5
0
def test_get_potentially_retired_user_hashed_match():
    """
    Check that we can pass in a hashed username and get the
    user-to-be-retired back.
    """
    user = UserFactory()
    orig_username = user.username
    hashed_username = get_retired_username_by_username(orig_username)

    # Fake username retirement.
    user.username = hashed_username
    user.save()

    # Check to find the user by original username should fail,
    # 2nd check by hashed username should succeed.
    assert get_potentially_retired_user_by_username_and_hash(orig_username, hashed_username) == user
def _setup_users():
    """
    Creates and returns test users in the different states of needing rehash:
    - Skipped: has not yet been retired
    - Faked: has been fake-retired, but the retired username does not require updating
    - Needing rehash: has been fake-retired and name changed so it triggers a hash update
    """
    # When we loop through creating users, take additional action on these
    user_indexes_to_be_fake_retired = (2, 4, 6, 8, 10)
    user_indexes_to_be_rehashed = (4, 6)

    users_skipped = []
    users_faked = []
    users_needing_rehash = []
    retirements = {}

    # Create some test users with retirements
    for i in range(1, 11):
        user = UserFactory()
        retirement = UserRetirementStatus.create_retirement(user)
        retirements[user.id] = retirement

        if i in user_indexes_to_be_fake_retired:
            fake_completed_retirement(user)

            if i in user_indexes_to_be_rehashed:
                # In order to need a rehash user.username must be the same as
                # retirement.retired_username and NOT the same as the hash
                # generated when the script is run. So we force that here.
                retirement.retired_username = retirement.retired_username.upper(
                )
                user.username = retirement.retired_username
                retirement.save()
                user.save()
                users_needing_rehash.append(user)
            else:
                users_faked.append(user)
        else:
            users_skipped.append(user)
    return users_skipped, users_faked, users_needing_rehash, retirements