6
6
from django .contrib .sessions .backends .base import CreateError
7
7
from django .utils .timezone import now
8
8
9
+ from qsessions import IP_SESSION_KEY , USER_AGENT_SESSION_KEY
9
10
from qsessions .models import Session
10
11
11
12
SessionStore = Session .get_session_store_class ()
@@ -19,6 +20,17 @@ def setup_store():
19
20
def test_untouched_init (store ):
20
21
assert store .modified is False
21
22
assert store .accessed is False
23
+ assert store .get ('cat' ) is None
24
+
25
+
26
+ def test_store (store ):
27
+ store ['cat' ] = 'dog'
28
+ assert store .accessed is True
29
+ assert store .modified is True
30
+ assert 'cat' in store
31
+ assert store .pop ('cat' ) == 'dog'
32
+ assert 'cat' not in store
33
+ assert store .get ('cat' ) is None
22
34
23
35
24
36
def test_auth_session_key (store ):
@@ -56,8 +68,8 @@ def test_load_unmodified(store, django_user_model):
56
68
store2 = SessionStore (session_key = store .session_key ,
57
69
user_agent = 'TestUA/1.1' , ip = '127.0.0.1' )
58
70
store2 .load ()
59
- assert store2 .user_agent == 'TestUA/1.1'
60
- assert store2 .ip == '127.0.0.1'
71
+ assert store2 .get ( USER_AGENT_SESSION_KEY ) == 'TestUA/1.1'
72
+ assert store2 .get ( IP_SESSION_KEY ) == '127.0.0.1'
61
73
assert store2 .get (auth .SESSION_KEY ) == 1
62
74
assert store2 .modified is False
63
75
@@ -69,13 +81,18 @@ def test_load_modified(store, django_user_model):
69
81
store [auth .SESSION_KEY ] = 1
70
82
store .save ()
71
83
store2 = SessionStore (session_key = store .session_key ,
72
- user_agent = 'TestUA/1.1' , ip = '8.8.8.8' )
84
+ user_agent = 'TestUA/1.1-changed ' , ip = '8.8.8.8' )
73
85
store2 .load ()
74
- assert store2 .user_agent == 'TestUA/1.1'
75
- assert store2 .ip == '8.8.8.8 '
86
+ assert store2 .get ( USER_AGENT_SESSION_KEY ) == 'TestUA/1.1'
87
+ assert store2 .get ( IP_SESSION_KEY ) == '127.0.0.1 '
76
88
assert store2 .get (auth .SESSION_KEY ) == 1
77
89
assert store2 .modified is True
78
90
91
+ store2 .save ()
92
+
93
+ assert store2 .get (USER_AGENT_SESSION_KEY ) == 'TestUA/1.1-changed'
94
+ assert store2 .get (IP_SESSION_KEY ) == '8.8.8.8'
95
+
79
96
80
97
@pytest .mark .django_db
81
98
def test_duplicate_create ():
0 commit comments