Skip to content

Commit

Permalink
Adjust unit tests for script root in cookie suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Sep 28, 2017
1 parent dfe3450 commit 7fc0f48
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/server/util/test_flask.py
Expand Up @@ -530,6 +530,13 @@ def test_server_port(self):
def test_cookie_suffix(self):
request = OctoPrintFlaskRequest(standard_environ)
self.assertEquals("_P5000", request.cookie_suffix)

def test_cookie_suffix_with_root(self):
script_root_environ = dict(standard_environ)
script_root_environ["SCRIPT_NAME"] = "/path/to/octoprint"

request = OctoPrintFlaskRequest(script_root_environ)
self.assertEquals("_P5000_R|path|to|octoprint", request.cookie_suffix)

def test_cookies(self):
environ = dict(standard_environ)
Expand Down Expand Up @@ -561,8 +568,10 @@ class OctoPrintFlaskResponseTest(unittest.TestCase):
def test_cookie_set_and_delete(self, path, scriptroot):
environ = dict(standard_environ)

expected_suffix = "_P5000"
if scriptroot is not None:
environ.update(dict(SCRIPT_NAME=scriptroot))
expected_suffix += "_R" + scriptroot.replace("/", "|")

request = OctoPrintFlaskRequest(environ)

Expand All @@ -586,7 +595,7 @@ def test_cookie_set_and_delete(self, path, scriptroot):
response.set_cookie("some_key", "some_value", **kwargs)

# 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)
set_cookie_mock.assert_called_once_with(response, "some_key" + expected_suffix, "some_value", path=expected_path_set)

# test delete_cookie
with mock.patch("flask.Response.set_cookie") as set_cookie_mock:
Expand Down

0 comments on commit 7fc0f48

Please sign in to comment.