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')
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' )
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")
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!')
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' )
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!')
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!")
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)
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')
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")
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), "")
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), '')