# Path: webtools/template/handlers.py
# class ResponseHandlerMixin(object):
#     def get_template(self, template_name):
#         return self.application.jinja_env.get_template(template_name)
# 
#     def get_template_from_string(self, data):
#         return self.application.jinja_env.from_string(data)
# 
#     def render(self, template, context={}):
#         if not isinstance(template, jinja2.Template):
#             template = self.get_template(template)
#         context = self._populate_context_form_ctxprocessors(context)
# 
#         for chuck in template.generate(context):
#             self.write(chuck)
# 
#     def render_to_string(self, template, context={}):
#         if not isinstance(template, jinja2.Template):
#             template = self.get_template(template)
#         context = self._populate_context_form_ctxprocessors(context)
#         return template.render(context)
# 
#     def _populate_context_form_ctxprocessors(self, context):
#         ctx = {}
#         ctx.update(context)
# 
#         for ctx_processor in self.application.context_processors:
#             ctx.update(ctx_processor(self))
# 
#         ctx.update({
#             "handler": self,
#             "application": self.application.conf,
#             "config": self.application.conf,
#         })
# 
#         return ctx
# 
# Path: webtools/handlers/i18n.py
# class TimezoneMixin(object):
#     @property
#     def timezone(self):
#         if not hasattr(self, "_timezone"):
#             self._timezone = self.get_user_timezone()
#         return self._timezone
# 
#     def get_user_timezone(self):
#         if "webtools_timezone" in self.session:
#             return get_timezone(self.session["webtools_timezone"])
#         return get_timezone(self.application.conf.DEFAULT_TZ)
# 
#     def activate_timezone(self, timezone_name):
#         self.session["webtools_timezone"] = timezone_name
#         self._timezone = get_timezone(timezone_name)
# 
# class I18nMixin(object):
#     def get_browser_locale(self, default=None):
#         """
#         Overwrite default behavior with correct
#         setting the default language.
#         """
#         if default is None:
#             default = self.conf.I18N_DEFAULT_LANG
#         return super(I18nMixin, self).get_browser_locale(default=default)
# 
#     def get_user_locale(self):
#         if "webtools_locale" in self.session:
#             return locale.get(self.session["webtools_locale"])
#         return None
# 
#     def _(self, message, plural_message=None, count=None):
#         return self.locale.translate(message, plural_message=plural_message, count=count)
# 
#     def activate_locale(self, locale_name):
#         """
#         Activate a specific locale for current user.
#         """
#         self.session["webtools_locale"] = locale_name
#         self._locale = locale.get(locale_name)
# 
# Path: webtools/handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     @property
#     def db(self):
#         return self.application.db
# 
#     @property
#     def session(self):
#         return self.application.session_engine
# 
#     def on_finish(self):
#         if self.session and self.session.is_modified:
#             self.session.save()
# 
#         super(BaseHandler, self).on_finish()
# 
# Path: webtools/database.py

# 
# Path: webtools/utils/timezone.py
# def get_default_timezone_name(application=None):
# def get_default_timezone(application):
# def as_localtime(value, timezone):
# def get_timezone(name):
# def make_aware(value, timezone):
# def make_naive(value, timezone):
# 
# Path: tests/settings.py
# class TestOverwriteSettings(Settings):
#     SQLALCHEMY_ENGINE_URL = "sqlite://"
#     AUTHENTICATION_BACKENDS = ["webtools.auth.backends.DatabaseAuthenticationBackend"]
# 
#     JINJA2_TEMPLATE_DIRS = [
#         os.path.join(CURRENT_PATH, "template")
#     ]
#     INSTALLED_MODULES = [
#         "tests",
#     ]
# 
#     COMMANDS = [
#         "webtools.management.commands.runserver.RunserverCommand",
#     ]
# 
#     I18N = True
# 
#     I18N_DIRECTORIES = [
#         os.path.join(CURRENT_PATH, "locale"),
#     ]


from webtools.template.handlers import ResponseHandlerMixin
from webtools.handlers.i18n import TimezoneMixin, I18nMixin
from webtools.handlers.base import BaseHandler
from webtools.database import Base
from webtools.utils import timezone
from ..settings import TestOverwriteSettings
from unittest import TestCase
        from webtools.application import Application
        from webtools.application import Application
        from webtools.application import Application
import os.path, io
import unittest
import datetime
import pytz

    def write(self, chuck):
        self.buffer.write(chuck)

    def get_current_user(self):
        return None


class DefaultTemplateTests(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.app = Application(TestOverwriteSettings())

    def setUp(self):
        self.handler = ResponseMock()
        self.handler.application = self.app

    def test_render(self):
        self.handler.render("test.html", {"name":"foo"})
        result = self.handler.buffer.getvalue()
        self.assertEqual(result, "Hello foo")

    def test_render_to_string(self):
        result = self.handler.render_to_string("test.html", {"name": "foo"})
        self.assertEqual(result, "Hello foo")


class TimezoneModuleTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):

# Path: webtools/template/handlers.py
# class ResponseHandlerMixin(object):
#     def get_template(self, template_name):
#         return self.application.jinja_env.get_template(template_name)
# 
#     def get_template_from_string(self, data):
#         return self.application.jinja_env.from_string(data)
# 
#     def render(self, template, context={}):
#         if not isinstance(template, jinja2.Template):
#             template = self.get_template(template)
#         context = self._populate_context_form_ctxprocessors(context)
# 
#         for chuck in template.generate(context):
#             self.write(chuck)
# 
#     def render_to_string(self, template, context={}):
#         if not isinstance(template, jinja2.Template):
#             template = self.get_template(template)
#         context = self._populate_context_form_ctxprocessors(context)
#         return template.render(context)
# 
#     def _populate_context_form_ctxprocessors(self, context):
#         ctx = {}
#         ctx.update(context)
# 
#         for ctx_processor in self.application.context_processors:
#             ctx.update(ctx_processor(self))
# 
#         ctx.update({
#             "handler": self,
#             "application": self.application.conf,
#             "config": self.application.conf,
#         })
# 
#         return ctx
# 
# Path: webtools/handlers/i18n.py
# class TimezoneMixin(object):
#     @property
#     def timezone(self):
#         if not hasattr(self, "_timezone"):
#             self._timezone = self.get_user_timezone()
#         return self._timezone
# 
#     def get_user_timezone(self):
#         if "webtools_timezone" in self.session:
#             return get_timezone(self.session["webtools_timezone"])
#         return get_timezone(self.application.conf.DEFAULT_TZ)
# 
#     def activate_timezone(self, timezone_name):
#         self.session["webtools_timezone"] = timezone_name
#         self._timezone = get_timezone(timezone_name)
# 
# class I18nMixin(object):
#     def get_browser_locale(self, default=None):
#         """
#         Overwrite default behavior with correct
#         setting the default language.
#         """
#         if default is None:
#             default = self.conf.I18N_DEFAULT_LANG
#         return super(I18nMixin, self).get_browser_locale(default=default)
# 
#     def get_user_locale(self):
#         if "webtools_locale" in self.session:
#             return locale.get(self.session["webtools_locale"])
#         return None
# 
#     def _(self, message, plural_message=None, count=None):
#         return self.locale.translate(message, plural_message=plural_message, count=count)
# 
#     def activate_locale(self, locale_name):
#         """
#         Activate a specific locale for current user.
#         """
#         self.session["webtools_locale"] = locale_name
#         self._locale = locale.get(locale_name)
# 
# Path: webtools/handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     @property
#     def db(self):
#         return self.application.db
# 
#     @property
#     def session(self):
#         return self.application.session_engine
# 
#     def on_finish(self):
#         if self.session and self.session.is_modified:
#             self.session.save()
# 
#         super(BaseHandler, self).on_finish()
# 
# Path: webtools/database.py

# 
# Path: webtools/utils/timezone.py
# def get_default_timezone_name(application=None):
# def get_default_timezone(application):
# def as_localtime(value, timezone):
# def get_timezone(name):
# def make_aware(value, timezone):
# def make_naive(value, timezone):
# 
# Path: tests/settings.py
# class TestOverwriteSettings(Settings):
#     SQLALCHEMY_ENGINE_URL = "sqlite://"
#     AUTHENTICATION_BACKENDS = ["webtools.auth.backends.DatabaseAuthenticationBackend"]
# 
#     JINJA2_TEMPLATE_DIRS = [
#         os.path.join(CURRENT_PATH, "template")
#     ]
#     INSTALLED_MODULES = [
#         "tests",
#     ]
# 
#     COMMANDS = [
#         "webtools.management.commands.runserver.RunserverCommand",
#     ]
# 
#     I18N = True
# 
#     I18N_DIRECTORIES = [
#         os.path.join(CURRENT_PATH, "locale"),
#     ]


# Path: tests/template/test_template.py
from webtools.template.handlers import ResponseHandlerMixin
from webtools.handlers.i18n import TimezoneMixin, I18nMixin
from webtools.handlers.base import BaseHandler
from webtools.database import Base
from webtools.utils import timezone
from ..settings import TestOverwriteSettings
from unittest import TestCase
        from webtools.application import Application
        from webtools.application import Application
        from webtools.application import Application
import os.path, io
import unittest
import datetime
import pytz


    def write(self, chuck):
        self.buffer.write(chuck)

    def get_current_user(self):
        return None


class DefaultTemplateTests(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.app = Application(TestOverwriteSettings())

    def setUp(self):
        self.handler = ResponseMock()
        self.handler.application = self.app

    def test_render(self):
        self.handler.render("test.html", {"name":"foo"})
        result = self.handler.buffer.getvalue()
        self.assertEqual(result, "Hello foo")

    def test_render_to_string(self):
        result = self.handler.render_to_string("test.html", {"name": "foo"})
        self.assertEqual(result, "Hello foo")


class TimezoneModuleTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):

        cls.app = Application(TestOverwriteSettings())