# Path: isomorphic/client/template_client.py
# BUFFER_SIZE = 8192
# def _make_none(obj):
# def clean_context(context):
#     def render_template(self, file_path, context=None, request_data=None):
#     def connect(self):
#     def receive(self, sock):
# class JsTemplateException(Exception):
# class TemplateClient():


from django.test import TestCase
from isomorphic.client import template_client
from django.conf import settings
from os.path import join


class TestTemplateClient(TestCase):
    def test_make_none(self):
        """
        Test JSON conversion doesn't fail when object can't be serialized
        """
        class Foo():
            def __str__(self):
                return 'foo'

        foo = Foo()
        is_none = template_client._make_none(foo)
        self.assertIsNone(is_none)

    def test_render_template(self):
        """
        Test render a standard template
        """
        client = template_client.TemplateClient()
        template_path = join(settings.TEMPLATE_DIR, 'test-component.js')
        actual = client.render_template(template_path, {}, {})
        expected = '<span>Test component</span>'
        self.assertEqual(actual, expected)

    def test_clean_context(self):
        """
        Make sure reserved items are removed, like the request object
        """
        context = {'request': 'remove this', 'foo': 'bar'}

# Path: isomorphic/client/template_client.py
# BUFFER_SIZE = 8192
# def _make_none(obj):
# def clean_context(context):
#     def render_template(self, file_path, context=None, request_data=None):
#     def connect(self):
#     def receive(self, sock):
# class JsTemplateException(Exception):
# class TemplateClient():


# Path: tests/test_template_client.py
from django.test import TestCase
from isomorphic.client import template_client
from django.conf import settings
from os.path import join



class TestTemplateClient(TestCase):
    def test_make_none(self):
        """
        Test JSON conversion doesn't fail when object can't be serialized
        """
        class Foo():
            def __str__(self):
                return 'foo'

        foo = Foo()
        is_none = template_client._make_none(foo)
        self.assertIsNone(is_none)

    def test_render_template(self):
        """
        Test render a standard template
        """
        client = template_client.TemplateClient()
        template_path = join(settings.TEMPLATE_DIR, 'test-component.js')
        actual = client.render_template(template_path, {}, {})
        expected = '<span>Test component</span>'
        self.assertEqual(actual, expected)

    def test_clean_context(self):
        """
        Make sure reserved items are removed, like the request object
        """
        context = {'request': 'remove this', 'foo': 'bar'}

        template_client.clean_context(context)