If the data exceeds what is allowed in a cookie, older messages are removed before saving (and returned by the ``update`` method).
(self)
| 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 = ["\\", ",", ";", '"'] |
nothing calls this directly
no test coverage detected