# Path: pyroutes/settings.py
# BUILTIN_TEMPLATES_DIR = os.path.join(
#     os.path.dirname(__file__),
#     'default_templates'
# )
# BUILTIN_BASE_TEMPLATE = 'base.xml'
# DEBUG = False
# DEFAULT_CONTENT_TYPE = 'text/html; charset=utf-8'
# SECRET_KEY = None
# TEMPLATE_DIR = None # /foo/bar/templates/
# MIDDLEWARE = (
#     'pyroutes.middleware.errors.NotFoundMiddleware',
#     #'pyroutes.middleware.appendslash.AppendSlashes',
#     'pyroutes.middleware.responsify.Responsify',
#     'pyroutes.middleware.errors.ErrorHandlerMiddleware',
# )


import unittest
import hmac
    import sha as sha1
        import datetime
        import datetime
    from hashlib import sha1
from pyroutes.http.cookies import *
from pyroutes import settings
    def test_get_non_existing_unsigned_cookie(self):
        self.assertEqual(self.cookie_request_handler.get_unsigned_cookie('test'), None)

    def test_get_cookie_without_key_setting(self):
        reload(settings)
        self.assertRaises(CookieKeyMissing, self.cookie_request_handler.get_cookie, 'foo')
        settings.SECRET_KEY = 'asdfnaj2308sydfahli37flas36al9gaiufw'

class TestResponseCookieHandler(unittest.TestCase):

    def setUp(self):
        settings.SECRET_KEY = 'asdfnaj2308sydfahli37flas36al9gaiufw'
        settings.SITE_ROOT = ''
        self.cookies = ResponseCookieHandler()

    def test_add_cookie(self):
        self.cookies.add_cookie('foo', 'bar')
        cookie_hash = hmac.HMAC(settings.SECRET_KEY, 'foobar', sha1).hexdigest()
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar; path=/'))
        self.assertEqual(self.cookies.cookie_headers[1], ('Set-Cookie', 'foo_hash=%s; path=/' % cookie_hash))

    def test_add_unsigned_cookie(self):
        self.cookies.add_unsigned_cookie('foo', 'bar')
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar; path=/'))

    def test_add_cookie_without_path(self):
        self.cookies.add_unsigned_cookie('foo', 'bar', path=False)
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar'))

    def test_add_cookie_default_path(self):

# Path: pyroutes/settings.py
# BUILTIN_TEMPLATES_DIR = os.path.join(
#     os.path.dirname(__file__),
#     'default_templates'
# )
# BUILTIN_BASE_TEMPLATE = 'base.xml'
# DEBUG = False
# DEFAULT_CONTENT_TYPE = 'text/html; charset=utf-8'
# SECRET_KEY = None
# TEMPLATE_DIR = None # /foo/bar/templates/
# MIDDLEWARE = (
#     'pyroutes.middleware.errors.NotFoundMiddleware',
#     #'pyroutes.middleware.appendslash.AppendSlashes',
#     'pyroutes.middleware.responsify.Responsify',
#     'pyroutes.middleware.errors.ErrorHandlerMiddleware',
# )


# Path: tests/cookie_test.py
import unittest
import hmac
    import sha as sha1
        import datetime
        import datetime
    from hashlib import sha1
from pyroutes.http.cookies import *
from pyroutes import settings

    def test_get_non_existing_unsigned_cookie(self):
        self.assertEqual(self.cookie_request_handler.get_unsigned_cookie('test'), None)

    def test_get_cookie_without_key_setting(self):
        reload(settings)
        self.assertRaises(CookieKeyMissing, self.cookie_request_handler.get_cookie, 'foo')
        settings.SECRET_KEY = 'asdfnaj2308sydfahli37flas36al9gaiufw'

class TestResponseCookieHandler(unittest.TestCase):

    def setUp(self):
        settings.SECRET_KEY = 'asdfnaj2308sydfahli37flas36al9gaiufw'
        settings.SITE_ROOT = ''
        self.cookies = ResponseCookieHandler()

    def test_add_cookie(self):
        self.cookies.add_cookie('foo', 'bar')
        cookie_hash = hmac.HMAC(settings.SECRET_KEY, 'foobar', sha1).hexdigest()
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar; path=/'))
        self.assertEqual(self.cookies.cookie_headers[1], ('Set-Cookie', 'foo_hash=%s; path=/' % cookie_hash))

    def test_add_unsigned_cookie(self):
        self.cookies.add_unsigned_cookie('foo', 'bar')
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar; path=/'))

    def test_add_cookie_without_path(self):
        self.cookies.add_unsigned_cookie('foo', 'bar', path=False)
        self.assertEqual(self.cookies.cookie_headers[0], ('Set-Cookie', 'foo=bar'))

    def test_add_cookie_default_path(self):

        settings.SITE_ROOT = '/baz/'