Skip to content

Commit

Permalink
Implicit value for not set cookie is None
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Jan 23, 2024
1 parent 6d3a194 commit c245ccc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions poorwsgi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion poorwsgi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def req_session():

class TestSession:
"""Test PoorSession configuration options."""

def test_default(self):
session = PoorSession(SECRET_KEY)
headers = session.header()
Expand Down Expand Up @@ -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()
Expand All @@ -123,6 +125,7 @@ def test_strict(self):

class TestErrors:
"""Test exceptions"""

def test_no_secret_key(self):
with raises(SessionError):
PoorSession(Empty)
Expand All @@ -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 == {}
Expand Down

0 comments on commit c245ccc

Please sign in to comment.