Skip to content

Commit

Permalink
Limited test perspective.
Browse files Browse the repository at this point in the history
only check 'a thread local was set a valid value'
  • Loading branch information
RyoheiTaima committed Feb 27, 2022
1 parent bce50a5 commit 2465e39
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/testapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from hamcrest import assert_that, instance_of, equal_to, is_, empty, has_length

from django_currentuser.middleware import (
get_current_user, _set_current_user, get_current_authenticated_user)
SetCurrentUser,
get_current_user,
_set_current_user,
get_current_authenticated_user
)
from django_currentuser.db.models import CurrentUserField

from .sixmock import patch
Expand Down Expand Up @@ -43,15 +47,16 @@ def login_and_update(self, username, password, pk):

class TestSetUserToThread(TestUserBase):

@patch.object(SetCurrentUser, "__exit__", lambda *args, **kwargs: None)
def test__local_thread_var_is_set_to_logged_in_user(self):
_set_current_user(None)
self.assertIsNone(get_current_user())

self.login_and_go_to_homepage(username="user1", password="pw1")
self.login_and_create(username="user1", password="pw1")
self.assertEqual(self.user1, get_current_user())
self.client.logout()

self.login_and_go_to_homepage(username="user2", password="pw2")
self.login_and_create(username="user2", password="pw2")
self.assertEqual(self.user2, get_current_user())
self.client.logout()

Expand Down

0 comments on commit 2465e39

Please sign in to comment.