From c245ccc878ade130e78802cbc1dc07da40c9ff55 Mon Sep 17 00:00:00 2001 From: Ondrej Tuma Date: Tue, 23 Jan 2024 12:45:53 +0100 Subject: [PATCH] Implicit value for not set cookie is None --- doc/ChangeLog | 1 + poorwsgi/request.py | 4 ++-- poorwsgi/session.py | 2 +- tests/test_header.py | 6 ++++-- tests/test_session.py | 4 ++++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 40e9a2c..b7c8ed8 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,6 @@ ==== 2.7.0dev0 ==== * HTTPException has status_code property + * Implicit value for not set cookie is None ==== 2.6.1 ==== * Fix OpenAPI Core wrappers diff --git a/poorwsgi/request.py b/poorwsgi/request.py index 2451617..d507d57 100644 --- a/poorwsgi/request.py +++ b/poorwsgi/request.py @@ -467,7 +467,7 @@ def __init__(self, environ, app): self.__cookies = SimpleCookie() self.__cookies.load(self.__headers['Cookie']) else: - self.__cookies = tuple() + self.__cookies = None # variables for user use self.__user = None @@ -655,7 +655,7 @@ def cookies(self): """SimpleCookie iterable object of all cookies from Cookie header. This property was set if Application.auto_cookies is set to true, - which is default. Otherwise cookies was empty tuple. + which is default. Otherwise cookies is None. """ return self.__cookies diff --git a/poorwsgi/session.py b/poorwsgi/session.py index 99ffddc..8351084 100644 --- a/poorwsgi/session.py +++ b/poorwsgi/session.py @@ -237,7 +237,7 @@ def __init__(self, secret_key: Union[Request, str, bytes], if not isinstance(secret_key, (str, bytes)): # backwards compatibility self.load(secret_key.cookies) - def load(self, cookies: Union[SimpleCookie, tuple]): + def load(self, cookies: Optional[SimpleCookie]): """Load session from request's cookie""" if not isinstance(cookies, SimpleCookie) or self.__sid not in cookies: return diff --git a/tests/test_header.py b/tests/test_header.py index e98c7b9..1e31e45 100644 --- a/tests/test_header.py +++ b/tests/test_header.py @@ -5,15 +5,17 @@ from poorwsgi.request import Headers # pylint: disable=missing-function-docstring +# pylint: disable=no-self-use class TestSetValues(TestCase): """Adding headers and or setting header values.""" + def test_constructor_empty(self): Headers() - Headers([]) # list + Headers([]) # list Headers(tuple()) - Headers({}) # dict + Headers({}) # dict Headers(set()) def test_constructor_tuples(self): diff --git a/tests/test_session.py b/tests/test_session.py index 3140129..07f79fa 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -46,6 +46,7 @@ def req_session(): class TestSession: """Test PoorSession configuration options.""" + def test_default(self): session = PoorSession(SECRET_KEY) headers = session.header() @@ -100,6 +101,7 @@ def test_https(self): reason="SameSite is supported from Python 3.8") class TestSameSite: """Test for PoorSession same_site option.""" + def test_default(self): session = PoorSession(SECRET_KEY) headers = session.header() @@ -123,6 +125,7 @@ def test_strict(self): class TestErrors: """Test exceptions""" + def test_no_secret_key(self): with raises(SessionError): PoorSession(Empty) @@ -145,6 +148,7 @@ def test_bad_session_compatibility(self, req): class TestLoadWrite: """Tests of load and write methods.""" + def test_compatibility_empty(self, req): session = PoorSession(req) assert session.data == {}