Example #1
0
    def test_set_delete_cookie(self):
        local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values())
        store = SessionStore(handler)

        store.set_cookie('foo', 'bar')
        store.set_cookie('baz', 'ding')

        response = Response()
        store.save(response)

        headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}
        request = Request.from_values('/', headers=headers)

        self.assertEqual(request.cookies.get('foo'), 'bar')
        self.assertEqual(request.cookies.get('baz'), 'ding')

        store.delete_cookie('foo')
        store.save(response)

        headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}
        request = Request.from_values('/', headers=headers)

        self.assertEqual(request.cookies.get('foo', None), '')
        self.assertEqual(request.cookies['baz'], 'ding')
Example #2
0
    def test_set_delete_cookie(self):
        local.current_handler = handler = RequestHandler(self._get_app(), Request.from_values())
        store = SessionStore(handler)

        store.set_cookie('foo', 'bar')
        store.set_cookie('baz', 'ding')

        response = Response()
        store.save(response)

        headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}
        request = Request.from_values('/', headers=headers)

        self.assertEqual(request.cookies.get('foo'), 'bar')
        self.assertEqual(request.cookies.get('baz'), 'ding')

        store.delete_cookie('foo')
        store.save(response)

        headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))}
        request = Request.from_values('/', headers=headers)

        self.assertEqual(request.cookies.get('foo', None), '')
        self.assertEqual(request.cookies['baz'], 'ding')