# Path: isomorphic/template/backend.py
# class JsTemplate(object):
#     def __init__(self, template_path):
#         self.template_path = template_path
# 
#     def render(self, context=None, request=None):
#         context = context.copy()
#         request_data = {}
# 
#         if request is not None:
#             context['csrf_token'] = get_token(request)
# 
#             request_data['path'] = request.path
#             request_data['absolute_uri'] = request.build_absolute_uri()
# 
#         client = TemplateClient()
#         return client.render_template(self.template_path, context, request_data)
# 
# Path: isomorphic/template/loaders.py
# class JsLoader(Loader):
#     def load_template_source(self, template_name, template_dirs=None):
#         tried = []
#         for filepath in self.get_template_sources(template_name, template_dirs):
#             if exists(filepath):
#                 return filepath, None
#             else:
#                 tried.append(filepath)
# 
#         if tried:
#             error_msg = "Tried %s" % tried
#         else:
#             error_msg = ("Your template directories configuration is empty. "
#                          "Change it to point to at least one template directory.")
#         raise TemplateDoesNotExist(error_msg)
# 
#     def load_template(self, template_name, template_dirs=None):
#         """
#         Only the file path is returned
#         """
#         filepath, display_name = self.load_template_source(template_name, template_dirs)
#         return filepath, template_name


from django.test import TestCase
from django.conf import settings
from isomorphic.template.backend import JsTemplate
from isomorphic.template.loaders import JsLoader


class FakeRequest():
    def __init__(self):
        self.META = {}

    @property
    def path(self):
        return '/'

    def build_absolute_uri(self):
        return 'http://localhost:8000/'


class TestJsTemplate(TestCase):
    def test_render_template_without_request(self):
        """
        Render a template
        """
        loader = JsLoader(engine=None)
        template_path = loader.load_template('test-component.js', template_dirs=[settings.TEMPLATE_DIR])[0]
        template = JsTemplate(template_path)
        result = template.render({})
        expected = '<span>Test component</span>'
        self.assertEqual(result, expected)

    def test_render_template_with_request(self):
        """
        Render a template with a (fake) request
        """

# Path: isomorphic/template/backend.py
# class JsTemplate(object):
#     def __init__(self, template_path):
#         self.template_path = template_path
# 
#     def render(self, context=None, request=None):
#         context = context.copy()
#         request_data = {}
# 
#         if request is not None:
#             context['csrf_token'] = get_token(request)
# 
#             request_data['path'] = request.path
#             request_data['absolute_uri'] = request.build_absolute_uri()
# 
#         client = TemplateClient()
#         return client.render_template(self.template_path, context, request_data)
# 
# Path: isomorphic/template/loaders.py
# class JsLoader(Loader):
#     def load_template_source(self, template_name, template_dirs=None):
#         tried = []
#         for filepath in self.get_template_sources(template_name, template_dirs):
#             if exists(filepath):
#                 return filepath, None
#             else:
#                 tried.append(filepath)
# 
#         if tried:
#             error_msg = "Tried %s" % tried
#         else:
#             error_msg = ("Your template directories configuration is empty. "
#                          "Change it to point to at least one template directory.")
#         raise TemplateDoesNotExist(error_msg)
# 
#     def load_template(self, template_name, template_dirs=None):
#         """
#         Only the file path is returned
#         """
#         filepath, display_name = self.load_template_source(template_name, template_dirs)
#         return filepath, template_name


# Path: tests/test_template.py
from django.test import TestCase
from django.conf import settings
from isomorphic.template.backend import JsTemplate
from isomorphic.template.loaders import JsLoader



class FakeRequest():
    def __init__(self):
        self.META = {}

    @property
    def path(self):
        return '/'

    def build_absolute_uri(self):
        return 'http://localhost:8000/'


class TestJsTemplate(TestCase):
    def test_render_template_without_request(self):
        """
        Render a template
        """
        loader = JsLoader(engine=None)
        template_path = loader.load_template('test-component.js', template_dirs=[settings.TEMPLATE_DIR])[0]
        template = JsTemplate(template_path)
        result = template.render({})
        expected = '<span>Test component</span>'
        self.assertEqual(result, expected)

    def test_render_template_with_request(self):
        """
        Render a template with a (fake) request
        """

        loader = JsLoader(engine=None)