Exemplo n.º 1
0
class PageTextTest(TestCase):
    value_template_with_key_as_string = Template(
        "{% load content_tags %}{% pagetext page 'value' 'key' 'widget' %}HelloWorld{% endpagetext %}"
    )

    value_template_with_key_as_value = Template(
        "{% load content_tags %}{% pagetext page 'value' key_as_value 'widget' %}HelloWorld{% endpagetext %}"
    )

    meta_template = Template(
        "{% load content_tags %}{% pagetext page 'meta' 'key' 'widget' %}HelloWorld{% endpagetext %}"
    )

    @classmethod
    def setUpTestData(cls):
        fake = Faker()
        cls.lambda_user = User.objects.create_user(username=fake.name(),
                                                   email=fake.email(),
                                                   password=fake.name())

        cls.staff_user = User.objects.create_user(username=fake.name(),
                                                  email=fake.email(),
                                                  password=fake.name(),
                                                  is_staff=True)
        cls.request_factory = RequestFactory()
        cls.connected_request = cls.request_factory.get(path='/')
        cls.connected_request.user = cls.lambda_user
        cls.staff_request = cls.request_factory.get(path='/')
        cls.staff_request.user = cls.staff_user
        cls.anonymous_request = cls.request_factory.get(path='/')
        cls.anonymous_request.user = AnonymousUser()

    @data(
        ('connected_request', compile_template('HelloWorld')),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('HelloWorld')),
    )
    def test_basic_value_creation_with_key_as_string(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        rendered = self.value_template_with_key_as_string.render(
            Context({
                'page': page,
                'request': getattr(self, request_string)
            }))
        self.assertEqual(page.contents.count(), 1)
        self.assertIn('key', page.values.keys(), page.values)
        self.assertEqual(
            rendered,
            output.render({
                'id': page.values.get('key').pk,
                'key': 'key',
                'value': page.values.get('key').value,
                'widget': 'widget'
            }))

    @data(
        ('connected_request', compile_template('HelloWorld')),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('HelloWorld')),
    )
    def test_basic_content_type_update(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        self.meta_template.render(
            Context({
                'page': page,
                'request': self.anonymous_request
            }))
        rendered = self.value_template_with_key_as_string.render(
            Context({
                'page': page,
                'request': getattr(self, request_string)
            }))
        self.assertEqual(page.contents.count(), 1)
        self.assertIn('key', page.values.keys(), page.metas)
        self.assertEqual(
            rendered,
            output.render({
                'id': page.values.get('key').pk,
                'key': 'key',
                'value': page.values.get('key').value,
                'widget': 'widget'
            }))

    @data(
        ('connected_request', compile_template('OKAY')),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('OKAY')),
    )
    def test_content_modification(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        self.meta_template.render(
            Context({
                'page': page,
                'request': self.anonymous_request
            }))
        self.value_template_with_key_as_string.render(
            Context({
                'page': page,
                'request': getattr(self, request_string)
            }))
        page.values.get('key').value = "OKAY"
        page.values.get('key').save()
        rendered = self.value_template_with_key_as_string.render(
            Context({
                'page': page,
                'request': getattr(self, request_string)
            }))

        self.assertEqual(
            rendered,
            output.render({
                'id': page.values.get('key').pk,
                'key': 'key',
                'value': page.values.get('key').value,
                'widget': 'widget'
            }), rendered)
Exemplo n.º 2
0
class PageLinkTest(TestCase):
    value_template_with_key_as_string = Template(
        "{% load content_tags %}{% pagelink page 'value' 'key' 'Hello World!' %}"
    )

    value_template_with_key_as_value = Template(
        "{% load content_tags %}{% pagelink page 'value' key_as_value 'Hello World!' %}"
    )

    meta_template = Template(
        "{% load content_tags %}{% pagelink page 'meta' 'key' 'Hello World!' %}"
    )

    @classmethod
    def setUpTestData(cls):
        fake = Faker()
        cls.lambda_user = User.objects.create_user(username=fake.name(),
                                                   email=fake.email(),
                                                   password=fake.name())

        cls.staff_user = User.objects.create_user(
            username=fake.name(),
            email=fake.email(),
            password=fake.name(),
            is_staff=True,
        )
        cls.request_factory = RequestFactory()
        cls.connected_request = cls.request_factory.get(path="/")
        cls.connected_request.user = cls.lambda_user
        cls.staff_request = cls.request_factory.get(path="/")
        cls.staff_request.user = cls.staff_user
        cls.anonymous_request = cls.request_factory.get(path="/")
        cls.anonymous_request.user = AnonymousUser()

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_value_creation_with_key_as_string(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        rendered = self.value_template_with_key_as_string.render(
            Context({
                "page": page,
                "request": getattr(self, request_string)
            }))
        self.assertEqual(page.contents.count(), 1)
        self.assertIn("key", page.values.keys(), page.metas)
        # TODO Check content

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_value_creation_with_key_as_value(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        rendered = self.value_template_with_key_as_value.render(
            Context({
                "page": page,
                "request": getattr(self, request_string),
                "key_as_value": "hello"
            }))
        self.assertEqual(page.contents.count(), 1)
        self.assertIn("hello", page.values.keys(), page.metas)
        # TODO Check content

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_content_type_update(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        self.meta_template.render(
            Context({
                "page": page,
                "request": self.anonymous_request
            }))
        rendered = self.value_template_with_key_as_string.render(
            Context({
                "page": page,
                "request": getattr(self, request_string)
            }))
        self.assertEqual(page.contents.count(), 1)
        self.assertIn("key", page.values.keys(), page.metas)
        # TODO Check content

    @data(
        ("connected_request", compile_template("OKAY")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("OKAY")),
    )
    def test_content_modification(self, data):
        request_string, output = data
        page = Page.objects.create(title="My Title")
        self.meta_template.render(
            Context({
                "page": page,
                "request": self.anonymous_request
            }))
        self.value_template_with_key_as_string.render(
            Context({
                "page": page,
                "request": getattr(self, request_string)
            }))
        new_page = Page.objects.create(title="OKAY")
        page.values.get("key").value = new_page
        page.values.get("key").save()
        rendered = self.value_template_with_key_as_string.render(
            Context({
                "page": new_page,
                "request": getattr(self, request_string)
            }))
class TemplateImageTest(TestCase):
    @classmethod
    def setUpTestData(cls):
        fake = Faker()
        cls.lambda_user = User.objects.create_user(username=fake.name(),
                                                   email=fake.email(),
                                                   password=fake.name())

        cls.staff_user = User.objects.create_user(
            username=fake.name(),
            email=fake.email(),
            password=fake.name(),
            is_staff=True,
        )

    @classmethod
    def setUp(cls):
        cls.request_factory = RequestFactory()
        cls.connected_request = cls.request_factory.get(path="/")
        cls.connected_request.user = cls.lambda_user
        cls.staff_request = cls.request_factory.get(path="/")
        cls.staff_request.user = cls.staff_user
        cls.anonymous_request = cls.request_factory.get(path="/")
        cls.anonymous_request.user = AnonymousUser()

    @property
    def value_template_with_key_as_string(self):
        return Template(
            "{% load content_tags %}{% templateimage 'test' 'value' 'key' '200x300' '255,91,0' %}"
        )

    @property
    def value_template_with_key_as_value(self):
        return Template(
            "{% load content_tags %}{% templateimage 'test' 'value' key_as_value '200x300' '255,91,0' %}"
        )

    @property
    def meta_template(self):
        return Template(
            "{% load content_tags %}{% templateimage 'test' 'meta' 'key' '200x300' '255,91,0' %}"
        )

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_value_creation_with_key_as_string(self, data):
        request_string, output = data
        rendered = self.value_template_with_key_as_string.render(
            Context({"request": getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")
        self.assertEqual(template.contents.count(), 1)
        self.assertIn("key", template.values.keys(), template.values)

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_value_creation_with_key_as_value(self, data):
        request_string, output = data
        rendered = self.value_template_with_key_as_value.render(
            Context({
                "request": getattr(self, request_string),
                "key_as_value": "hello"
            }))
        template = TemplateModel.objects.get(path="test")
        self.assertEqual(template.contents.count(), 1)
        self.assertIn("hello", template.values.keys(), template.values)

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ("staff_request", get_template("stack_it/editable.html")),
        ("anonymous_request", compile_template("HelloWorld")),
    )
    def test_basic_content_type_update(self, data):
        request_string, output = data
        self.meta_template.render(Context({"request": self.anonymous_request}))
        rendered = self.value_template_with_key_as_string.render(
            Context({"request": getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")

        self.assertEqual(template.contents.count(), 1)
        self.assertIn("key", template.values.keys(), template.metas)
class TemplageTextTest(TestCase):
    @classmethod
    def setUpTestData(cls):
        fake = Faker()
        cls.lambda_user = User.objects.create_user(username=fake.name(),
                                                   email=fake.email(),
                                                   password=fake.name())

        cls.staff_user = User.objects.create_user(
            username=fake.name(),
            email=fake.email(),
            password=fake.name(),
            is_staff=True,
        )

    @classmethod
    def setUp(cls):
        cls.request_factory = RequestFactory()
        cls.connected_request = cls.request_factory.get(path="/")
        cls.connected_request.user = cls.lambda_user
        cls.staff_request = cls.request_factory.get(path="/")
        cls.staff_request.user = cls.staff_user
        cls.anonymous_request = cls.request_factory.get(path="/")
        cls.anonymous_request.user = AnonymousUser()

    @property
    def value_template(self):
        return Template(
            "{% load content_tags %}{% templatetext 'test' 'value' 'key' 'widget' %}HelloWorld{% endtemplatetext %}"
        )

    @property
    def meta_template(self):
        return Template(
            "{% load content_tags %}{% templatetext 'test' 'meta'  'key' 'widget' %}HelloWorld{% endtemplatetext %}"
        )

    @data(
        ('connected_request', compile_template('HelloWorld')),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('HelloWorld')),
    )
    def test_basic_value_creation(self, data):
        request_string, output = data
        rendered = self.value_template.render(
            Context({'request': getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")
        self.assertEqual(template.contents.count(), 1)
        self.assertIn('key', template.values.keys(), template.values)
        self.assertEqual(
            rendered,
            output.render({
                'id': template.values.get('key').pk,
                'key': 'key',
                'value': template.values.get('key').value,
                'widget': 'widget'
            }))

    @data(
        ("connected_request", compile_template("HelloWorld")),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('HelloWorld')),
    )
    def test_basic_content_type_update(self, data):
        request_string, output = data
        self.meta_template.render(
            Context({"request": getattr(self, request_string)}))
        rendered = self.value_template.render(
            Context({"request": getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")
        self.assertEqual(template.contents.count(), 1)
        self.assertIn('key', template.values.keys(), template.metas)
        self.assertEqual(
            rendered,
            output.render({
                'id': template.values.get('key').pk,
                'key': 'key',
                'value': template.values.get('key').value,
                'widget': 'widget'
            }))

    @data(
        ('connected_request', compile_template('OKAY')),
        ('staff_request', get_template('stack_it/editable.html')),
        ('anonymous_request', compile_template('OKAY')),
    )
    def test_content_modification(self, data):
        request_string, output = data
        self.meta_template.render(
            Context({'request': getattr(self, request_string)}))
        self.value_template.render(
            Context({'request': getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")
        template.values.get('key').value = "OKAY"
        template.values.get('key').save()
        del getattr(self, request_string).templates
        rendered = self.value_template.render(
            Context({'request': getattr(self, request_string)}))
        template = TemplateModel.objects.get(path="test")
        self.assertEqual(
            rendered,
            output.render({
                'id': template.values.get('key').pk,
                'key': 'key',
                'value': template.values.get('key').value,
                'widget': 'widget'
            }), rendered)