예제 #1
0
    def test_placeholder_name_space_bug(self):
        """Cache key cannot us space."""
        from pages.placeholders import PlaceholderNode

        page = self.new_page()
        placeholder = PlaceholderNode("test space", page=page)
        placeholder.save(page, "fr-ch", "fr", True)
        self.assertEqual(Content.objects.get_content(page, "fr-ch", placeholder.ctype), "fr")
 def test_placeholder_name_space_bug(self):
     """Cache key cannot us space."""
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('test space', page=page)
     placeholder.save(page, 'fr', 'fr', True)
     self.assertEqual(
         Content.objects.get_content(page, 'fr', placeholder.ctype), 'fr')
 def test_placeholder_cache_bug(self):
     """There was an bad bug caused when the page cache was filled
     the first time."""
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('test', page=page)
     placeholder.save(page, 'fr', 'fr', True)
     placeholder.save(page, 'en', 'en', True)
     self.assertEqual(Content.objects.get_content(page, 'fr', 'test'), 'fr')
예제 #4
0
 def test_placeholder_name_space_bug(self):
     """Cache key cannot us space."""
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('test space', page=page)
     placeholder.save(page, 'fr-ch', 'fr', True)
     self.assertEqual(
         Content.objects.get_content(page, 'fr-ch', 'test space'),
         'fr'
     )
예제 #5
0
    def test_placeholder_cache_bug(self):
        """There was an bad bug caused when the page cache was filled
        the first time."""
        from pages.placeholders import PlaceholderNode

        page = self.new_page()
        placeholder = PlaceholderNode("test", page=page)
        placeholder.save(page, "fr-ch", "fr", True)
        placeholder.save(page, "en-us", "en", True)
        self.assertEqual(Content.objects.get_content(page, "fr-ch", "test"), "fr")
예제 #6
0
 def test_placeholder_name_space_bug_with_template(self):
     """
     Template space test
     """
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('hello world', page=page)
     placeholder.save(page, 'fr-ch', 'hello!', True)
     context = Context({'current_page': page, 'lang':'fr-ch'})
     pl1 = """{% load pages_tags %}{% placeholder "hello world" %}"""
     template = loader.get_template_from_string(pl1)
     self.assertEqual(template.render(context), 'hello!')
예제 #7
0
 def test_placeholder_cache_bug(self):
     """There was an bad bug caused when the page cache was filled
     the first time."""
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('test', page=page)
     placeholder.save(page, 'fr-ch', 'fr', True)
     placeholder.save(page, 'en-us', 'en', True)
     self.assertEqual(
         Content.objects.get_content(page, 'fr-ch', 'test'),
         'fr'
     )
예제 #8
0
 def test_placeholder_name_space_bug_with_template(self):
     """
     Template space test
     """
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('hello world', page=page)
     placeholder.save(page, 'fr-ch', 'hello!', True)
     context = Context({'current_page': page, 'lang':'fr-ch'})
     pl1 = """{% load pages_tags %}{% placeholder "hello world" %}"""
     template = self.get_template_from_string(pl1)
     self.assertEqual(template.render(context), 'hello!')
예제 #9
0
    def test_placeholder_name_space_bug_with_template(self):
        """
        Template space test
        """
        from pages.placeholders import PlaceholderNode

        page = self.new_page()
        placeholder = PlaceholderNode("hello world", page=page)
        placeholder.save(page, "fr-ch", "hello!", True)
        context = Context({"current_page": page, "lang": "fr-ch"})
        pl1 = """{% load pages_tags %}{% placeholder "hello world" %}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(template.render(context), "hello!")
예제 #10
0
 def test_get_filename_edge_case(self):
     placeholder = PlaceholderNode("placeholdername")
     page = self.new_page({'slug': 'page1'})
     fakefile = SimpleUploadedFile(name=u"hello<script>world",
                                   content=six.b('bytes'))
     filename = get_filename(page, placeholder.ctype, fakefile)
     self.assertNotIn('<', filename)
예제 #11
0
 def test_get_filename(self):
     placeholder = PlaceholderNode("placeholdername")
     page = self.new_page({'slug': 'page1'})
     fakefile = SimpleUploadedFile(name=six.u("myfile.pdf"), content=six.b('bytes'))
     self.assertTrue(fakefile.name in get_filename(page, placeholder, fakefile))
     self.assertTrue("page_%d" % page.id in get_filename(page, placeholder, fakefile))
     self.assertTrue(placeholder.name in get_filename(page, placeholder, fakefile))
예제 #12
0
 def test_get_filename(self):
     placeholder = PlaceholderNode("placeholdername")
     page = self.new_page({'slug': 'page1'})
     fakefile = SimpleUploadedFile(name=u"some {}[]@$%*()+myfile.pdf", content=six.b('bytes'))
     filename = get_filename(page, placeholder, fakefile)
     self.assertTrue('some-myfile.pdf' in filename)
     self.assertTrue("page_%d" % page.id in filename)
     self.assertTrue(placeholder.name in filename)
 def test_get_filename_encoding_bug(self):
     """Problem with encoding file names"""
     placeholder = PlaceholderNode("placeholdername")
     page = self.new_page({'slug': 'page1'})
     fakefile = SimpleUploadedFile(name=u"АБВГДЕЖ.pdf", content=b'blop')
     filename = get_filename(page, placeholder.ctype, fakefile)
     self.assertTrue(fakefile.name.lower() in filename)
     self.assertTrue("page_%d" % page.id in filename)
     self.assertTrue(placeholder.name in filename)
예제 #14
0
 def test_get_filename_encoding_bug(self):
     """Problem with encoding file names"""
     placeholder = PlaceholderNode("placeholdername")
     page = self.new_page({'slug': 'page1'})
     fakefile = SimpleUploadedFile(name=six.u("АБВГДЕЖ.pdf"), content=six.b('bytes'))
     filename = get_filename(page, placeholder, fakefile)
     self.assertTrue(fakefile.name in filename)
     self.assertTrue("page_%d" % page.id in filename)
     self.assertTrue(placeholder.name in filename)
예제 #15
0
 def test_placeholder_need_iterable_nodelist_attr(self):
     """Should have a iterable nodelist."""
     from pages.placeholders import PlaceholderNode
     page = self.new_page()
     placeholder = PlaceholderNode('test itrable', page=page)
     try:
         _ = (e for e in placeholder.nodelist)
     except TypeError:
         assert (False, 'is not iterable')
예제 #16
0
    def test_placeholder_quoted_name(self):
        """Test placeholder name with quotes."""
        page = self.new_page()
        context = {'current_page': page, 'lang': 'en-us'}
        placeholder = PlaceholderNode("test name")
        placeholder.save(page, 'en-us', 'some random value', False)

        pl1 = """{% load pages_tags %}{% placeholder "test name" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(render(template, context), 'some random value')

        placeholder = PlaceholderNode("with accent éàè")
        placeholder.save(page, 'en-us', 'some random value', False)

        pl1 = """{% load pages_tags %}{% placeholder "with accent éàè" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(render(template, context), 'some random value')
예제 #17
0
def do_placeholder(parser, token):
    """
    Method that parse the placeholder template tag.

    Syntax::

        {% placeholder <name> [on <page>] [with <widget>] \
[parsed] [as <varname>] %}

    Example usage::

        {% placeholder about %}
        {% placeholder body with TextArea as body_text %}
        {% placeholder welcome with TextArea parsed as welcome_text %}
        {% placeholder teaser on next_page with TextArea parsed %}
    """
    name, params = parse_placeholder(parser, token)
    return PlaceholderNode(name, **params)
예제 #18
0
    def test_placeholder_untranslated_content(self):
        """Test placeholder untranslated content."""
        self.set_setting("PAGE_USE_SITE_ID", False)
        page = self.new_page(content={})
        placeholder = PlaceholderNode('untrans', page='p', untranslated=True)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        placeholder.save(page, 'en-us', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 1)
        self.assertEqual(Content.objects.all()[0].language, 'en-us')

        placeholder = PlaceholderNode('untrans', page='p', untranslated=False)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 2)

        # test the syntax
        page = self.new_page()
        template = django.template.loader.get_template(
            'pages/tests/untranslated.html')
        context = {'current_page': page, 'lang': 'en-us'}
        self.assertEqual(render(template, context), '')
예제 #19
0
    def test_placeholder_untranslated_content(self):
        """Test placeholder untranslated content."""
        from pages import settings as pages_settings
        setattr(pages_settings, "PAGE_USE_SITE_ID", False)
        author = User.objects.all()[0]
        page = Page(author=author, status=Page.PUBLISHED)
        page.save()
        placeholder = PlaceholderNode('untrans', page='p', untranslated=True)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        placeholder.save(page, 'en-us', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 1)
        self.assertEqual(Content.objects.all()[0].language, 'en-us')

        placeholder = PlaceholderNode('untrans', page='p', untranslated=False)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 2)
예제 #20
0
    def test_placeholder_quoted_name(self):
        """Test placeholder name with quotes."""
        page = self.new_page()
        context = Context({"current_page": page, "lang": "en-us"})
        placeholder = PlaceholderNode("test name")
        placeholder.save(page, "en-us", "some random value", False)

        pl1 = """{% load pages_tags %}{% placeholder "test name" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(template.render(context), "some random value")

        placeholder = PlaceholderNode("with accent éàè")
        placeholder.save(page, "en-us", "some random value", False)

        pl1 = """{% load pages_tags %}{% placeholder "with accent éàè" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(template.render(context), "some random value")
예제 #21
0
    def test_placeholder_quoted_name(self):
        """Test placeholder name with quotes."""
        page = self.new_page()
        context = {'current_page': page, 'lang': 'en-us'}
        placeholder = PlaceholderNode("test name")
        placeholder.save(page, 'en-us', 'some random value', False)

        pl1 = """{% load pages_tags %}{% placeholder "test name" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(render(template, context), 'some random value')

        placeholder = PlaceholderNode("with accent éàè")
        placeholder.save(page, 'en-us', 'some random value', False)

        pl1 = """{% load pages_tags %}{% placeholder "with accent éàè" as hello %}{{ hello }}"""
        template = self.get_template_from_string(pl1)
        self.assertEqual(render(template, context), 'some random value')
예제 #22
0
    def test_placeholder_untranslated_content(self):
        """Test placeholder untranslated content."""
        self.set_setting("PAGE_USE_SITE_ID", False)
        page = self.new_page(content={})
        placeholder = PlaceholderNode("untrans", page="p", untranslated=True)
        placeholder.save(page, "fr-ch", "test-content", True)
        placeholder.save(page, "en-us", "test-content", True)
        self.assertEqual(len(Content.objects.all()), 1)
        self.assertEqual(Content.objects.all()[0].language, "en-us")

        placeholder = PlaceholderNode("untrans", page="p", untranslated=False)
        placeholder.save(page, "fr-ch", "test-content", True)
        self.assertEqual(len(Content.objects.all()), 2)

        # test the syntax
        page = self.new_page()
        template = django.template.loader.get_template("pages/tests/untranslated.html")
        context = Context({"current_page": page, "lang": "en-us"})
        self.assertEqual(template.render(context), "")
예제 #23
0
    def test_placeholder_untranslated_content(self):
        """Test placeholder untranslated content."""
        self.set_setting("PAGE_USE_SITE_ID", False)
        page = self.new_page(content={})
        placeholder = PlaceholderNode('untrans', page='p', untranslated=True)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        placeholder.save(page, 'en-us', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 1)
        self.assertEqual(Content.objects.all()[0].language, 'en-us')

        placeholder = PlaceholderNode('untrans', page='p', untranslated=False)
        placeholder.save(page, 'fr-ch', 'test-content', True)
        self.assertEqual(len(Content.objects.all()), 2)

        # test the syntax
        page = self.new_page()
        template = django.template.loader.get_template(
                'pages/tests/untranslated.html')
        context = {'current_page': page, 'lang': 'en-us'}
        self.assertEqual(render(template, context), '')