-
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.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.urls import reverse | ||
|
||
import pytest | ||
from pytest_django.fixtures import admin_user | ||
from sessionprofile.models import SessionProfile | ||
|
||
|
||
@pytest.fixture | ||
def session_changelist_url(): | ||
return reverse("admin:sessionprofile_sessionprofile_changelist") | ||
|
||
|
||
def test_session_profile_sanity(client, admin_user, session_changelist_url): | ||
|
||
client.force_login(admin_user) | ||
response = client.get(session_changelist_url) | ||
assert response.status_code == 200 | ||
|
||
assert SessionProfile.objects.count() == 1 | ||
|
||
session = SessionProfile.objects.get() | ||
assert client.session.session_key == session.session_key | ||
|
||
|
||
admin_user2 = admin_user | ||
|
||
|
||
def test_only_session_profile_of_user_shown( | ||
client, admin_user, django_user_model, session_changelist_url | ||
): | ||
|
||
other_admin = django_user_model.objects.create_superuser("garry") | ||
|
||
client.force_login(other_admin) | ||
response = client.get(session_changelist_url) | ||
assert response.status_code == 200 | ||
|
||
client.force_login(admin_user) | ||
response = client.get(session_changelist_url) | ||
assert response.status_code == 200 | ||
|
||
# two sessions, one for each user | ||
assert SessionProfile.objects.count() == 2 | ||
|
||
# Session created after response, needs to be called again | ||
response = client.get(session_changelist_url) | ||
|
||
admin_user_session = SessionProfile.objects.get(user=admin_user) | ||
assert admin_user_session.session_key in response.content.decode() | ||
|
||
other_user_session = SessionProfile.objects.get(user=other_admin) | ||
assert other_user_session.session_key not in response.content.decode() |