-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from uchicago-cs/users/admin-user-tests
Admin user and regular user view tests
- Loading branch information
Showing
4 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from chigame.users.forms import UserAdminChangeForm | ||
from chigame.users.models import User | ||
from chigame.users.tests.factories import UserFactory | ||
from chigame.users.views import UserRedirectView, UserUpdateView, user_detail_view | ||
from chigame.users.views import UserRedirectView, UserUpdateView, user_detail_view, user_list | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
@@ -94,3 +94,27 @@ def test_not_authenticated(self, user: User, rf: RequestFactory): | |
assert isinstance(response, HttpResponseRedirect) | ||
assert response.status_code == 302 | ||
assert response.url == f"{login_url}?next=/fake-url/" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_admin_user_list_view(client, rf: RequestFactory): | ||
request = rf.get("user-list") | ||
|
||
request.user = User.objects.create_user(is_staff=True, name="testuser", password="testpass", email="[email protected]") | ||
client.login(email="[email protected]", password="testpass") | ||
|
||
response = user_list(request) | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_nonadmin_user_list_view(client, rf: RequestFactory): | ||
request = rf.get("user-list") | ||
|
||
request.user = User.objects.create_user(name="testuser", password="testpass", email="[email protected]") | ||
client.login(email="[email protected]", password="testpass") | ||
|
||
response = user_list(request) | ||
|
||
assert response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters