From 7828ab0bf957fe1f53fd95c97761e4f52b0d5b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 7 Apr 2017 08:27:30 +0200 Subject: [PATCH] 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. --- tests/server/util/{flask.py => test_flask.py} | 25 +++++++++++++------ .../util/{tornado.py => test_tornado.py} | 0 2 files changed, 18 insertions(+), 7 deletions(-) rename tests/server/util/{flask.py => test_flask.py} (92%) rename tests/server/util/{tornado.py => test_tornado.py} (100%) diff --git a/tests/server/util/flask.py b/tests/server/util/test_flask.py similarity index 92% rename from tests/server/util/flask.py rename to tests/server/util/test_flask.py index cfd6e19d..8efa4987 100644 --- a/tests/server/util/flask.py +++ b/tests/server/util/test_flask.py @@ -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) diff --git a/tests/server/util/tornado.py b/tests/server/util/test_tornado.py similarity index 100% rename from tests/server/util/tornado.py rename to tests/server/util/test_tornado.py