MCPcopy
hub / github.com/django/django / test_max_cookie_length

Method test_max_cookie_length

tests/messages_tests/test_cookie.py:124–153  ·  view source on GitHub ↗

If the data exceeds what is allowed in a cookie, older messages are removed before saving (and returned by the ``update`` method).

(self)

Source from the content-addressed store, hash-verified

122 self.assertEqual(list(storage), [])
123
124 def test_max_cookie_length(self):
125 """
126 If the data exceeds what is allowed in a cookie, older messages are
127 removed before saving (and returned by the ``update`` method).
128 """
129 storage = self.get_storage()
130 response = self.get_response()
131
132 # When storing as a cookie, the cookie has constant overhead of approx
133 # 54 chars, and each message has a constant overhead of about 37 chars
134 # and a variable overhead of zero in the best case. We aim for a
135 # message size which will fit 4 messages into the cookie, but not 5.
136 # See also FallbackTest.test_session_fallback
137 msg_size = int((CookieStorage.max_cookie_size - 54) / 4.5 - 37)
138 first_msg = None
139 # Generate the same (tested) content every time that does not get run
140 # through zlib compression.
141 random.seed(42)
142 for i in range(5):
143 msg = get_random_string(msg_size)
144 storage.add(constants.INFO, msg)
145 if i == 0:
146 first_msg = msg
147 unstored_messages = storage.update(response)
148
149 cookie_storing = self.stored_messages_count(storage, response)
150 self.assertEqual(cookie_storing, 4)
151
152 self.assertEqual(len(unstored_messages), 1)
153 self.assertEqual(unstored_messages[0].message, first_msg)
154
155 def test_message_rfc6265(self):
156 non_compliant_chars = ["\\", ",", ";", '"']

Callers

nothing calls this directly

Calls 6

stored_messages_countMethod · 0.95
get_random_stringFunction · 0.90
get_storageMethod · 0.45
get_responseMethod · 0.45
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected