Exemplo n.º 1
0
def test_users_create_through_standard_api(client):
    user = f.UserFactory.create(is_superuser=True)

    url = reverse('users-list')
    data = {}

    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")
    assert response.status_code == 401

    client.login(user)

    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")
    assert response.status_code == 405
Exemplo n.º 2
0
def test_cancel_self_user_with_invalid_token(client):
    user = f.UserFactory.create()
    url = reverse('users-cancel')
    data = {"cancel_token": "invalid_cancel_token"}
    client.login(user)
    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")

    assert response.status_code == 400
Exemplo n.º 3
0
def test_validate_requested_email_change_without_token(client):
    user = f.UserFactory.create(email_token="change_email_token",
                                new_email="*****@*****.**")
    url = reverse('users-change-email')
    data = {}

    client.login(user)
    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")
    assert response.status_code == 400
Exemplo n.º 4
0
def test_cancel_self_user_with_valid_token(client):
    user = f.UserFactory.create()
    url = reverse('users-cancel')
    cancel_token = get_token_for_user(user, "cancel_account")
    data = {"cancel_token": cancel_token}
    client.login(user)
    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")

    assert response.status_code == 204
    user = models.User.objects.get(pk=user.id)
    assert user.full_name == "Deleted user"
Exemplo n.º 5
0
def test_update_user_with_invalid_email(client):
    user = f.UserFactory.create(email="*****@*****.**")
    url = reverse('users-detail', kwargs={"pk": user.pk})
    data = {"email": "my@email"}

    client.login(user)
    response = client.patch(url,
                            json.dumps(data),
                            content_type="application/json")

    assert response.status_code == 400
    assert response.data['_error_message'] == 'Not valid email'

    user.refresh_from_db()
    assert user.email == "*****@*****.**"
Exemplo n.º 6
0
def test_update_user_with_valid_email(client):
    user = f.UserFactory.create(email="*****@*****.**")
    url = reverse('users-detail', kwargs={"pk": user.pk})
    data = {"email": "*****@*****.**"}

    client.login(user)
    response = client.patch(url,
                            json.dumps(data),
                            content_type="application/json")

    assert response.status_code == 200
    user.refresh_from_db()
    assert user.email == "*****@*****.**"
    assert user.email_token is not None
    assert user.new_email == "*****@*****.**"
Exemplo n.º 7
0
def test_update_user_with_unallowed_domain_email(client, settings):
    settings.USER_EMAIL_ALLOWED_DOMAINS = ['email.com']
    user = f.UserFactory.create(email="*****@*****.**")
    url = reverse('users-detail', kwargs={"pk": user.pk})
    data = {"email": "*****@*****.**"}

    client.login(user)
    response = client.patch(url,
                            json.dumps(data),
                            content_type="application/json")

    assert response.status_code == 400
    assert response.data['_error_message'] == 'Not valid email'

    user.refresh_from_db()
    assert user.email == "*****@*****.**"
Exemplo n.º 8
0
def test_validate_requested_email_change_for_anonymous_user(client):
    user = f.UserFactory.create(email="*****@*****.**",
                                email_token="change_email_token",
                                new_email="*****@*****.**")
    url = reverse('users-change-email')
    data = {"email_token": "change_email_token"}

    client.login(user)
    response = client.post(url,
                           json.dumps(data),
                           content_type="application/json")

    assert response.status_code == 204
    user.refresh_from_db()
    assert user.email_token is None
    assert user.new_email is None
    assert user.email == "*****@*****.**"
Exemplo n.º 9
0
def test_update_user_with_allowed_domain_email(client, settings):
    settings.USER_EMAIL_ALLOWED_DOMAINS = ['email.com']

    user = f.UserFactory.create(email="*****@*****.**")
    url = reverse('users-detail', kwargs={"pk": user.pk})
    data = {"email": "*****@*****.**"}

    client.login(user)
    response = client.patch(url,
                            json.dumps(data),
                            content_type="application/json")

    assert response.status_code == 200

    user.refresh_from_db()
    assert user.email == "*****@*****.**"
    assert user.email_token is not None
    assert user.new_email == "*****@*****.**"