Fix tests for server.util.*
Weren't properly included in test suite, and those for the flask utility also had some errors due to buggy test implementation.
This commit is contained in:
parent
41e9d96815
commit
7828ab0bf9
2 changed files with 18 additions and 7 deletions
|
|
@ -567,11 +567,11 @@ class OctoPrintFlaskResponseTest(unittest.TestCase):
|
|||
request = OctoPrintFlaskRequest(environ)
|
||||
|
||||
if path:
|
||||
expected_path = path
|
||||
expected_path_set = expected_path_delete = path
|
||||
else:
|
||||
expected_path = "/"
|
||||
expected_path_set = expected_path_delete = "/"
|
||||
if scriptroot:
|
||||
expected_path = scriptroot + expected_path
|
||||
expected_path_set = scriptroot + expected_path_set
|
||||
|
||||
if path is not None:
|
||||
kwargs = dict(path=path)
|
||||
|
|
@ -584,9 +584,20 @@ class OctoPrintFlaskResponseTest(unittest.TestCase):
|
|||
# test set_cookie
|
||||
with mock.patch("flask.Response.set_cookie") as set_cookie_mock:
|
||||
response.set_cookie("some_key", "some_value", **kwargs)
|
||||
set_cookie_mock.assert_called_once_with(response, "some_key_P5000", "some_value", path=expected_path)
|
||||
|
||||
# set_cookie should have key and path values adjusted
|
||||
set_cookie_mock.assert_called_once_with(response, "some_key_P5000", "some_value", path=expected_path_set)
|
||||
|
||||
# test delete_cookie
|
||||
with mock.patch("flask.Response.delete_cookie") as delete_cookie_mock:
|
||||
response.delete_cookie("some_key", "some_value", **kwargs)
|
||||
delete_cookie_mock.assert_called_once_with(response, "some_key_P5000", "some_value", path=expected_path)
|
||||
with mock.patch("flask.Response.set_cookie") as set_cookie_mock:
|
||||
with mock.patch("flask.Response.delete_cookie") as delete_cookie_mock:
|
||||
response.delete_cookie("some_key", **kwargs)
|
||||
|
||||
# delete_cookie internally calls set_cookie - so our delete_cookie call still uses the non modified
|
||||
# key and path values, set_cookie will translate those (as tested above)
|
||||
delete_cookie_mock.assert_called_once_with(response, "some_key", path=expected_path_delete, domain=None)
|
||||
|
||||
# we also test if an additional set_cookie call for the non modified versions happens, as
|
||||
# implemented to ensure any old cookies from before introduction of the suffixes and path handling
|
||||
# are deleted as well
|
||||
set_cookie_mock.assert_called_once_with(response, "some_key", expires=0, max_age=0, path=expected_path_delete, domain=None)
|
||||
Loading…
Reference in a new issue