Esempio n. 1
0
    def test_cookies(self):
        changer = util.MtimeChanger()
        index = os.path.join(self.app_dir, 'index.ks')
        app = Keystone(self.app_dir)

        with file(index, 'w') as fp:
            fp.write(
                'set_cookie("name", "value")\n----\n<strong>this is HTML</strong>\n'
            )

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertEqual(response.headers['Set-Cookie'], 'name=value; Path=/')

        with changer.change_times(file(index, 'w')) as fp:
            fp.write(
                'delete_cookie("name")\n----\n<strong>this is HTML</strong>\n')

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertEqual(
            response.headers['Set-Cookie'],
            'name=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/')
Esempio n. 2
0
    def test_render_keystone(self):
        changer = util.MtimeChanger()
        index = os.path.join(self.app_dir, 'index.ks')

        with file(index, 'w') as fp:
            fp.write('# this is python\n----\n<strong>this is HTML</strong>\n')

        app = Keystone(self.app_dir)
        template = app.engine.get_template(index)

        req = Request(wsgi_environ('GET', '/'))
        response = app.render_keystone(req, template)

        self.assertEqual(response.data, '<strong>this is HTML</strong>')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertTrue('Content-Length' not in response.headers)
        self.assertTrue('ETag' not in response.headers)
        self.assertTrue('Last-Modified' not in response.headers)
        self.assertTrue('Expires' not in response.headers)
        self.assertTrue('Cache-Control' not in response.headers)
        self.assertTrue('Set-Cookie' not in response.headers)

        for method in ('GET', 'POST', 'HEAD', 'OPTIONS', 'PUT', 'DELETE'):
            # none of these should raise
            req = Request(wsgi_environ(method, '/'))
            app.render_keystone(req, template)

        with changer.change_times(file(index, 'w')) as fp:
            fp.write(
                'return_response("hello, world")\n----\n<strong>this is HTML</strong>\n'
            )

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)

        self.assertEqual(response.data, 'hello, world')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertTrue('Content-Length' not in response.headers)
        self.assertTrue('ETag' not in response.headers)
        self.assertTrue('Last-Modified' not in response.headers)
        self.assertTrue('Expires' not in response.headers)
        self.assertTrue('Cache-Control' not in response.headers)
        self.assertTrue('Set-Cookie' not in response.headers)
Esempio n. 3
0
    def test_render_keystone(self):
        changer = util.MtimeChanger()
        index = os.path.join(self.app_dir, 'index.ks')

        with file(index, 'w') as fp:
            fp.write('# this is python\n----\n<strong>this is HTML</strong>\n')

        app = Keystone(self.app_dir)
        template = app.engine.get_template(index)

        req = Request(wsgi_environ('GET', '/'))
        response = app.render_keystone(req, template)

        self.assertEqual(response.data, '<strong>this is HTML</strong>')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertTrue('Content-Length' not in response.headers)
        self.assertTrue('ETag' not in response.headers)
        self.assertTrue('Last-Modified' not in response.headers)
        self.assertTrue('Expires' not in response.headers)
        self.assertTrue('Cache-Control' not in response.headers)
        self.assertTrue('Set-Cookie' not in response.headers)

        for method in ('GET', 'POST', 'HEAD', 'OPTIONS', 'PUT', 'DELETE'):
            # none of these should raise
            req = Request(wsgi_environ(method, '/'))
            app.render_keystone(req, template)


        with changer.change_times(file(index, 'w')) as fp:
            fp.write('return_response("hello, world")\n----\n<strong>this is HTML</strong>\n')

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)

        self.assertEqual(response.data, 'hello, world')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertTrue('Content-Length' not in response.headers)
        self.assertTrue('ETag' not in response.headers)
        self.assertTrue('Last-Modified' not in response.headers)
        self.assertTrue('Expires' not in response.headers)
        self.assertTrue('Cache-Control' not in response.headers)
        self.assertTrue('Set-Cookie' not in response.headers)
Esempio n. 4
0
    def test_cookies(self):
        changer = util.MtimeChanger()
        index = os.path.join(self.app_dir, 'index.ks')
        app = Keystone(self.app_dir)

        with file(index, 'w') as fp:
            fp.write('set_cookie("name", "value")\n----\n<strong>this is HTML</strong>\n')

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertEqual(response.headers['Set-Cookie'], 'name=value; Path=/')

        with changer.change_times(file(index, 'w')) as fp:
            fp.write('delete_cookie("name")\n----\n<strong>this is HTML</strong>\n')

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertEqual(response.headers['Set-Cookie'], 'name=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/')
Esempio n. 5
0
    def test_headers(self):
        index = os.path.join(self.app_dir, 'index.ks')
        app = Keystone(self.app_dir)

        with file(index, 'w') as fp:
            fp.write('headers.set("X-Key", "value")\n----\n<strong>this is HTML</strong>\n')

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertTrue('X-Key' in response.headers)
        self.assertEqual(response.headers['X-Key'], 'value')
Esempio n. 6
0
    def test_headers(self):
        index = os.path.join(self.app_dir, 'index.ks')
        app = Keystone(self.app_dir)

        with file(index, 'w') as fp:
            fp.write(
                'headers.set("X-Key", "value")\n----\n<strong>this is HTML</strong>\n'
            )

        req = Request(wsgi_environ('GET', '/'))
        template = app.engine.get_template(index)
        response = app.render_keystone(req, template)
        self.assertTrue('X-Key' in response.headers)
        self.assertEqual(response.headers['X-Key'], 'value')