Beispiel #1
0
def test_get_auth_token__success(db, api_client):
    password = faker.password()
    user = UserFactory.build()
    user.set_password(password)
    user.save()

    with pytest.raises(Token.DoesNotExist):
        Token.objects.get(user_id=user.id)

    # first create
    response = api_client.post(
        reverse('auth-token'),
        data={
            'username': user.username,
            'password': password
        }
    )
    token = Token.objects.get(user_id=user.id)
    assert response.status_code == 200
    assert response.data['token'] == token.key

    # get exists
    response = api_client.post(
        reverse('auth-token'),
        data={
            'username': user.username,
            'password': password
        }
    )
    assert response.status_code == 200
    assert response.data['token'] == token.key
Beispiel #2
0
def test_authenticate(db):
    user = UserFactory.build()
    password = faker.password()
    user.set_password(password)
    user.save()

    assert authenticate(username=user.username, password=password) == user
    assert authenticate(username=user.username) == None
    assert authenticate(password=password) == None
    assert authenticate(username=faker.user_name(), password=password) == None

    assert authenticate(username=user.email, password=password) == user
    assert authenticate(username=user.email) == None
    assert authenticate(username=faker.email(), password=password) == None