'Login a user. A valid credential is used when is_valid_username is True,
otherwise it will use a random string to make a failed login.'

def _login(self, is_valid_username=False, is_valid_password=False, user_agent='test-browser'):

    try:
        admin_login = reverse('admin:login')
    except NoReverseMatch:
        admin_login = reverse('admin:index')
    if is_valid_username:
        username = self.VALID_USERNAME
    else:
        chars = (string.ascii_uppercase + string.digits)
        username = ''.join((random.choice(chars) for x in range(10)))
    if is_valid_password:
        password = self.VALID_PASSWORD
    else:
        password = 'invalid-password'
    response = self.client.post(admin_login, {'username': username, 'password': password, 'this_is_the_login_form': 1}, HTTP_USER_AGENT=user_agent)
    return response
