Example #1
0
    def test_it_acts_like_a_foreignkey(self):
        x = HasAWidgy()
        x.widgy = Layout.add_root(widgy_site).node
        x.save()

        x = HasAWidgy.objects.get(pk=x.pk)
        self.assertIsInstance(x.widgy.content, Layout)
Example #2
0
    def test_it_acts_like_a_foreignkey(self):
        x = HasAWidgy()
        x.widgy = Layout.add_root(widgy_site).node
        x.save()

        x = HasAWidgy.objects.get(pk=x.pk)
        self.assertIsInstance(x.widgy.content, Layout)
Example #3
0
    def test_add_root(self):
        instance = HasAWidgy()
        instance.widgy = ContentType.objects.get_for_model(Layout)
        root_node = HasAWidgy._meta.get_field('widgy').add_root(instance, {
            'pk': 1337,
        })

        self.assertEqual(root_node.content.pk, 1337)
Example #4
0
    def test_add_root(self):
        instance = HasAWidgy()
        instance.widgy = ContentType.objects.get_for_model(Layout)
        root_node = HasAWidgy._meta.get_field('widgy').add_root(
            instance, {
                'pk': 1337,
            })

        self.assertEqual(root_node.content.pk, 1337)
Example #5
0
    def setUp(self):
        self.widgied = HasAWidgy()
        self.widgied.widgy = Layout.add_root(widgy_site).node
        self.widgied.save()
        self.widgied.widgy.get_children()[1].content.add_child(widgy_site,
                                                               RawTextWidget,
                                                               text='asdf')

        self.widgy_field = HasAWidgy._meta.get_field_by_name('widgy')[0]
Example #6
0
    def setUp(self):
        self.widgied = HasAWidgy()
        self.widgied.widgy = Layout.add_root(widgy_site).node
        self.widgied.save()
        self.widgied.widgy.get_children()[1].content.add_child(widgy_site, RawTextWidget, text='asdf')

        self.widgy_field = HasAWidgy._meta.get_field_by_name('widgy')[0]
Example #7
0
class TestRender(TestCase):
    def setUp(self):
        self.widgied = HasAWidgy()
        self.widgied.widgy = Layout.add_root(widgy_site).node
        self.widgied.save()
        self.widgied.widgy.get_children()[1].content.add_child(widgy_site, RawTextWidget, text='asdf')

        self.widgy_field = HasAWidgy._meta.get_field_by_name('widgy')[0]

    def test_simple(self):
        rendered = self.widgy_field.render(self.widgied)
        self.assertIn('asdf', rendered)

    def test_widgy_env(self):
        with mock.patch.object(Layout, 'render') as patched_render:
            patched_render = copy_call_args(patched_render)
            self.widgy_field.render(self.widgied)

        args, kwargs = patched_render.call_args
        context = args[0]
        widgy = context['widgy']
        self.assertEqual(widgy['site'], widgy_site)
        self.assertEqual(widgy['owner'], self.widgied)

    def test_parent(self):
        parent_widgy = object()
        context = Context({'widgy': parent_widgy})
        with mock.patch.object(Layout, 'render') as patched_render:
            patched_render = copy_call_args(patched_render)
            self.widgy_field.render(self.widgied, context)

        args, kwargs = patched_render.call_args
        context = args[0]
        widgy = context['widgy']
        self.assertIs(widgy['parent'], parent_widgy)

    def test_null(self):
        """
        Rendering a NULL WidgyField
        """
        self.widgied.widgy = None
        self.widgied.save()
        # doesn't matter what happens as long as it doesn't throw an exception
        self.widgy_field.render(self.widgied)

    def test_null_versioned(self):
        """
        Rendering a NULL VersionedWidgyField
        """
        page = VersionedPage.objects.create()
        field = VersionedPage._meta.get_field_by_name('version_tracker')[0]
        # doesn't matter what happens as long as it doesn't throw an exception
        field.render(page)

    def test_no_commits(self):
        """
        Rendering a VersionedWidgyField without any commits
        """
        page = VersionedPage.objects.create(
            version_tracker=VersionTracker.objects.create(
                working_copy=Layout.add_root(widgy_site).node,
            )
        )
        field = VersionedPage._meta.get_field_by_name('version_tracker')[0]
        # doesn't matter what happens as long as it doesn't throw an exception
        field.render(page)
Example #8
0
class TestRender(TestCase):
    def setUp(self):
        self.widgied = HasAWidgy()
        self.widgied.widgy = Layout.add_root(widgy_site).node
        self.widgied.save()
        self.widgied.widgy.get_children()[1].content.add_child(widgy_site,
                                                               RawTextWidget,
                                                               text='asdf')

        self.widgy_field = HasAWidgy._meta.get_field_by_name('widgy')[0]

    def test_simple(self):
        rendered = self.widgy_field.render(self.widgied)
        self.assertIn('asdf', rendered)

    def test_widgy_env(self):
        with mock.patch.object(Layout, 'render') as patched_render:
            patched_render = copy_call_args(patched_render)
            self.widgy_field.render(self.widgied)

        args, kwargs = patched_render.call_args
        context = args[0]
        widgy = context['widgy']
        self.assertEqual(widgy['site'], widgy_site)
        self.assertEqual(widgy['owner'], self.widgied)

    def test_parent(self):
        parent_widgy = object()
        context = Context({'widgy': parent_widgy})
        with mock.patch.object(Layout, 'render') as patched_render:
            patched_render = copy_call_args(patched_render)
            self.widgy_field.render(self.widgied, context)

        args, kwargs = patched_render.call_args
        context = args[0]
        widgy = context['widgy']
        self.assertIs(widgy['parent'], parent_widgy)

    def test_null(self):
        """
        Rendering a NULL WidgyField
        """
        self.widgied.widgy = None
        self.widgied.save()
        # doesn't matter what happens as long as it doesn't throw an exception
        self.widgy_field.render(self.widgied)

    def test_null_versioned(self):
        """
        Rendering a NULL VersionedWidgyField
        """
        page = VersionedPage.objects.create()
        field = VersionedPage._meta.get_field_by_name('version_tracker')[0]
        # doesn't matter what happens as long as it doesn't throw an exception
        field.render(page)

    def test_no_commits(self):
        """
        Rendering a VersionedWidgyField without any commits
        """
        page = VersionedPage.objects.create(
            version_tracker=VersionTracker.objects.create(
                working_copy=Layout.add_root(widgy_site).node, ))
        field = VersionedPage._meta.get_field_by_name('version_tracker')[0]
        # doesn't matter what happens as long as it doesn't throw an exception
        field.render(page)