def test_invalid_attribute(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "fake_field" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-%s-%s cms_render_model"></div>' % ( 'placeholderapp', 'example1', 'fake_field', ex1.pk)) # no attribute template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<div class="cms_plugin cms_plugin-%s cms_render_model"></div>' % ex1.pk)
def test_admin_url_multiple_fields(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load placeholder_tags %} {% block content %} <h1>{% show_editable_model instance "callable_item" "char_1,char_2" "en" "admin:placeholderapp_example1_edit_field" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, 'callable_item')) self.assertContains( response, "/admin/placeholderapp/example1/edit-field/%s/en/" % ex1.pk) self.assertTrue( re.search(self.edit_fields_rx % "char_1", response.content.decode('utf8'))) self.assertTrue( re.search(self.edit_fields_rx % "char_1%2Cchar_2", response.content.decode('utf8')))
def test_noedit(self): user = self.get_staff() page = create_page("Test", "col_two.html", "en", published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=False) response = detail_view(request, ex1.pk) self.assertContains(response, "<h1>char_1</h1>") self.assertContains(response, "CMS.API.Toolbar")
def test_anon(self): user = self.get_anon() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=False) response = detail_view(request, ex1.pk) self.assertContains(response, "<h1>char_1</h1>") self.assertNotContains(response, "CMS.API")
def test_edit(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk) self.assertContains( response, '<h1><div class="cms_plugin cms_plugin-%s-%s-%s-%s cms_render_model">char_1</div></h1>' % ( 'placeholderapp', 'example1', 'char_1', ex1.pk))
def test_noedit(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=False) response = detail_view(request, ex1.pk) self.assertContains(response, "<h1>char_1</h1>") self.assertContains(response, "CMS.API.Toolbar")
def test_edit(self): user = self.get_staff() page = create_page("Test", "col_two.html", "en", published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk) self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, "char_1"), )
def test_edit(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk) self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, 'char_1'))
def test_filters_date(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1, <p>hello</p>, <p>hello</p>, <p>hello</p>, <p>hello</p>", char_2="char_2", char_3="char_3", char_4="char_4", date_field=datetime.date(2012, 1, 1)) ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "date_field" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<h1><div class="cms_plugin cms_plugin-%s-%s-%s-%s cms_render_model">%s</div></h1>' % ( 'placeholderapp', 'example1', 'date_field', ex1.pk, ex1.date_field.strftime("%Y-%m-%d"))) template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "date_field" "" "" 'date:"Y m d"' %}</h1> {% endblock content %} ''' response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<h1><div class="cms_plugin cms_plugin-%s-%s-%s-%s cms_render_model">%s</div></h1>' % ( 'placeholderapp', 'example1', 'date_field', ex1.pk, ex1.date_field.strftime("%Y %m %d")))
def test_filters_notoolbar(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1, <p>hello</p>, <p>hello</p>, <p>hello</p>, <p>hello</p>", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "char_1" "" "" 'truncatewords:2' %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=False) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains(response, '<h1>%s</h1>' % truncatewords(ex1.char_1, 2))
def test_as_varname(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "char_1" as tempvar %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertNotContains( response, '<div class="cms_plugin cms_plugin-%s cms_render_model"></div>' % ex1.pk)
def test_admin_url(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} <h1>{% render_model instance "callable_item" "char_1" "en" "" "admin:placeholderapp_example1_edit_field" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains(response, '<h1><div class="cms_plugin cms_plugin-%s-%s-%s-%s cms_render_model">char_1</div></h1>' % ( 'placeholderapp', 'example1', 'callable_item', ex1.pk))
def test_no_cms(self): user = self.get_staff() ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} {% render_model_icon instance %} {% endblock content %} ''' request = self.get_page_request('', user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-%s cms_render_model_icon"><img src="/static/cms/img/toolbar/render_model_placeholder.png"></div>' % ( 'placeholderapp', 'example1', ex1.pk)) self.assertContains(response, "'onClose': 'REFRESH_PAGE',")
def test_add_tag(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load cms_tags %} {% block content %} {% render_model_add instance %} {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-add-%s cms_render_model_add"><img src="/static/cms/img/toolbar/render_model_placeholder.png"></div>' % ( 'placeholderapp', 'example1', ex1.pk))
def test_item_from_context(self): user = self.get_staff() page = create_page("Test", "col_two.html", "en", published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = """{% extends "base.html" %} {% load placeholder_tags %} {% block content %} <h1>{% show_editable_model instance item_name %}</h1> {% endblock content %} """ request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text, item_name="callable_item") self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, "callable_item"), )
def test_instance_method(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = '''{% extends "base.html" %} {% load placeholder_tags %} {% block content %} <h1>{% show_editable_model instance "callable_item" %}</h1> {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, 'callable_item'))
def test_admin_url_extra_field(self): user = self.get_staff() page = create_page("Test", "col_two.html", "en", published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4") ex1.save() template_text = """{% extends "base.html" %} {% load placeholder_tags %} {% block content %} <h1>{% show_editable_model instance "callable_item" "char_2" %}</h1> {% endblock content %} """ request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertContains( response, '<h1><span id="cms_placeholder-model-placeholderapp-%s-%s" class="cms_placeholder-generic">char_1</span></h1>' % (ex1.pk, "callable_item"), ) self.assertContains(response, "/admin/placeholderapp/example1/edit-field/%s/en/" % ex1.pk) self.assertTrue(re.search(self.edit_fields_rx % "char_2", response.content.decode("utf8")))
def test_block_tag(self): user = self.get_staff() page = create_page('Test', 'col_two.html', 'en', published=True) ex1 = Example1(char_1="char_1", char_2="char_2", char_3="char_3", char_4="char_4", date_field=datetime.date(2012, 1, 1)) ex1.save() # This template does not render anything as content is saved in a # variable and never inserted in the page template_text = '''{% extends "base.html" %} {% load cms_tags %}{% load url from future %} {% block content %} {% render_model_block instance as rendered_model %} {{ instance }} <h1>{{ instance.char_1 }} - {{ instance.char_2 }}</h1> {{ instance.date_field|date:"Y" }} {% if instance.char_1 %} <a href="{% url 'detail' instance.pk %}">successful if</a> {% endif %} {% endrender_model_block %} {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) self.assertNotContains( response, '<div class="cms_plugin cms_plugin-%s-%s-%s cms_render_model_icon"><img src="/static/cms/img/toolbar/render_model_icon.png"></div>' % ( 'placeholderapp', 'example1', ex1.pk)) # This template does not render anything as content is saved in a # variable and inserted in the page afterwards template_text = '''{% extends "base.html" %} {% load cms_tags %}{% load url from future %} {% block content %} {% render_model_block instance as rendered_model %} {{ instance }} <h1>{{ instance.char_1 }} - {{ instance.char_2 }}</h1> <span class="date">{{ instance.date_field|date:"Y" }}</span> {% if instance.char_1 %} <a href="{% url 'detail' instance.pk %}">successful if</a> {% endif %} {% endrender_model_block %} {{ rendered_model }} {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) # Assertions on the content of the block tag self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-%s cms_render_model cms_render_model_block">' % ( 'placeholderapp', 'example1', ex1.pk)) self.assertContains(response, '<h1>%s - %s</h1>' % (ex1.char_1, ex1.char_2)) self.assertContains(response, '<span class="date">%s</span>' % (ex1.date_field.strftime("%Y"))) self.assertContains(response, '<a href="%s">successful if</a></div>' % (reverse('detail', args=(ex1.pk,)))) # This template is rendered directly template_text = '''{% extends "base.html" %} {% load cms_tags %}{% load url from future %} {% block content %} {% render_model_block instance %} {{ instance }} <h1>{{ instance.char_1 }} - {{ instance.char_2 }}</h1> <span class="date">{{ instance.date_field|date:"Y" }}</span> {% if instance.char_1 %} <a href="{% url 'detail' instance.pk %}">successful if</a> {% endif %} {% endrender_model_block %} {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) # Assertions on the content of the block tag self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-%s cms_render_model cms_render_model_block">' % ( 'placeholderapp', 'example1', ex1.pk)) self.assertContains(response, '<h1>%s - %s</h1>' % (ex1.char_1, ex1.char_2)) self.assertContains(response, '<span class="date">%s</span>' % (ex1.date_field.strftime("%Y"))) self.assertContains(response, '<a href="%s">successful if</a></div>' % (reverse('detail', args=(ex1.pk,)))) # Changelist check template_text = '''{% extends "base.html" %} {% load cms_tags %}{% load url from future %} {% block content %} {% render_model_block instance 'changelist' %} {{ instance }} {% endrender_model_block %} {% endblock content %} ''' request = self.get_page_request(page, user, edit=True) response = detail_view(request, ex1.pk, template_string=template_text) # Assertions on the content of the block tag self.assertContains( response, '<div class="cms_plugin cms_plugin-%s-%s-changelist-%s cms_render_model cms_render_model_block">' % ( 'placeholderapp', 'example1', ex1.pk))