Source code for search.tests.test_param_persistence

"""Tests related to the persistence of search parameters in a cookie."""

from unittest import TestCase, mock
import json
from search.factory import create_ui_web_app
from search.routes import ui


[docs]class TestParameterPersistence(TestCase): """Some search parameters should be saved in a cookie."""
[docs] def setUp(self): """Instantiate the UI application.""" self.app = create_ui_web_app() self.client = self.app.test_client()
[docs] def test_request_includes_params(self): """A request is made with parameters indicated for persistence.""" ui.PARAMS_TO_PERSIST = ['foo', 'baz'] ui.PARAMS_COOKIE_NAME = 'foo-cookie' response = self.client.get('/?foo=bar&baz=bat') self.assertIn('Set-Cookie', response.headers, "Should set a cookie") expected = 'foo-cookie="{\\"foo\\": \\"bar\\"\\054 \\"baz\\": \\"bat\\"}"; Path=/' self.assertEqual(response.headers['Set-Cookie'], expected, "Cookie should contain request params")
[docs] def test_request_does_not_include_params(self): """The request does not include persistable params.""" ui.PARAMS_TO_PERSIST = ['foo', 'baz'] ui.PARAMS_COOKIE_NAME = 'foo-cookie' response = self.client.get('/?nope=nope') self.assertIn('Set-Cookie', response.headers, "Should set a cookie") self.assertEqual(response.headers['Set-Cookie'], 'foo-cookie="{}"; Path=/', "Cookie should not contain request params")