diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
commit | eeaddb27560d723ca7d61359744ceb2709fccd2d (patch) | |
tree | 04ddbc49ae7b73d5f5a9e1716d7227aecd3b9f85 /pyblackbird_cc/users/tests/test_admin.py | |
parent | 7a3044c859043837e6c7c95bb4894d04e9b2cbc2 (diff) |
Renamed from pyblackbird_cc to alphabetlearning - everywhere
Diffstat (limited to 'pyblackbird_cc/users/tests/test_admin.py')
-rw-r--r-- | pyblackbird_cc/users/tests/test_admin.py | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/pyblackbird_cc/users/tests/test_admin.py b/pyblackbird_cc/users/tests/test_admin.py deleted file mode 100644 index 5132d21..0000000 --- a/pyblackbird_cc/users/tests/test_admin.py +++ /dev/null @@ -1,65 +0,0 @@ -import contextlib -from http import HTTPStatus -from importlib import reload - -import pytest -from django.contrib import admin -from django.contrib.auth.models import AnonymousUser -from django.urls import reverse -from pytest_django.asserts import assertRedirects - -from pyblackbird_cc.users.models import User - - -class TestUserAdmin: - def test_changelist(self, admin_client): - url = reverse("admin:users_user_changelist") - response = admin_client.get(url) - assert response.status_code == HTTPStatus.OK - - def test_search(self, admin_client): - url = reverse("admin:users_user_changelist") - response = admin_client.get(url, data={"q": "test"}) - assert response.status_code == HTTPStatus.OK - - def test_add(self, admin_client): - url = reverse("admin:users_user_add") - response = admin_client.get(url) - assert response.status_code == HTTPStatus.OK - - response = admin_client.post( - url, - data={ - "email": "new-admin@example.com", - "password1": "My_R@ndom-P@ssw0rd", - "password2": "My_R@ndom-P@ssw0rd", - }, - ) - assert response.status_code == HTTPStatus.FOUND - assert User.objects.filter(email="new-admin@example.com").exists() - - def test_view_user(self, admin_client): - user = User.objects.get(email="admin@example.com") - url = reverse("admin:users_user_change", kwargs={"object_id": user.pk}) - response = admin_client.get(url) - assert response.status_code == HTTPStatus.OK - - @pytest.fixture() - def _force_allauth(self, settings): - settings.DJANGO_ADMIN_FORCE_ALLAUTH = True - # Reload the admin module to apply the setting change - import pyblackbird_cc.users.admin as users_admin - - with contextlib.suppress(admin.sites.AlreadyRegistered): - reload(users_admin) - - @pytest.mark.django_db() - @pytest.mark.usefixtures("_force_allauth") - def test_allauth_login(self, rf, settings): - request = rf.get("/fake-url") - request.user = AnonymousUser() - response = admin.site.login(request) - - # The `admin` login view should redirect to the `allauth` login view - target_url = reverse(settings.LOGIN_URL) + "?next=" + request.path - assertRedirects(response, target_url, fetch_redirect_response=False) |