Пример #1
0
 def _render_link(self, link, page_links):
     page = Page()
     page.set_slot_content('content', '<a href="%s">Foo</a>' % link)
     return self._render("{% load cms_tags %}{% slot 'content' %}", {
         'page': page,
         'page_links': page_links
     })
Пример #2
0
 def test_should_render_slot_content_from_page(self):
     page = Page()
     page.set_slot_content('content', '<h1>Test</h1>')
     self.assertEqual(
         '<h1>Test</h1>',
         self._render("{% load cms_tags %}{% slot 'content' %}",
                      {'page': page}))
Пример #3
0
 def test_should_ignore_transpose_if_not_an_integer(self):
     page = Page()
     page.set_slot_content('content', '<h1>Page</h1>')
     self.assertEqual(
         '<h1>Page</h1>',
         self._render(
             "{% load cms_tags %}{% slot 'content' 'not-an-integer' %}",
             {'page': page}))
Пример #4
0
 def test_should_transpose_html_headlines_according_to_transpose_argument(
         self):
     page = Page()
     page.set_slot_content('content', '<h1>Page</h1>')
     self.assertEqual(
         '<h3>Page</h3>',
         self._render("{% load cms_tags %}{% slot 'content' 2 %}",
                      {'page': page}))
Пример #5
0
 def test_meta_description_should_be_based_on_configured_slot(self):
     s = Page(_meta_description=None)
     s.set_slot_content(
         'b',
         '<h1>Einstein:</h1><p>A human being is a part of a whole, called by us _universe_, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty.</p>'
     )
     self.assertEqual(
         'Einstein: A human being is a part of a whole, called by us _universe_, a part limited in time and space. He experiences himself, his thoughts and feelings as something',
         s.meta_description)
Пример #6
0
 def test_meta_description_should_return_meta_description_based_on_excerpt_if_available(
         self):
     s = Page(_meta_description=None)
     s.set_slot_content(
         'content',
         '<h1>Einstein:</h1><p>We cannot solve our problems with the same thinking we used when we created them.</p>'
     )
     self.assertEqual(
         'Einstein: We cannot solve our problems with the same thinking we used when we created them.',
         s.meta_description)
Пример #7
0
 def create_page(self, title, seq):
     p = Page(
         title=title,
         slug=slugify(title),
         template='testapp/page.html',
         entity_type='TestModelWithManyToMany',
         _nav='header',
         seq=seq
     )
     p.save()
     return p
Пример #8
0
 def _render_image(self, lightbox=False, media_id=1, markup_media_id=1):
     page = Page()
     page.set_slot_content('content',
                           self._image_markup(lightbox, markup_media_id))
     return self._render(
         "{% load cms_tags %}{% slot 'content' %}", {
             'page': page,
             'images': {
                 media_id:
                 Media(id=media_id, caption='Test', width=64, height=64)
             }
         })
Пример #9
0
    def setUpClass(cls):
        super(CMSModelsChildPageTestCase, cls).setUpClass()
        cls.homepage = Page(is_homepage=True, title='Homepage')
        cls.homepage.save()

        cls.homechild = CustomChildPage(title='Home Child', page=cls.homepage)
        cls.homechild.save()

        cls.page = Page(title='Page', entity_type='CustomChildPage')
        cls.page.save()

        cls.child = CustomChildPage(title='Child', page=cls.page)
        cls.child.save()
Пример #10
0
 def test_should_fallback_to_original_shape_if_specified_shape_does_not_exist(
         self):
     page = Page()
     page.set_slot_content('content', self._image_markup())
     html = self._render(
         "{% load cms_tags %}{% slot 'content' 0 'shape-does-not-exist' %}",
         {
             'page': page,
             'images': {
                 1: Media(id=1, caption='Test', width=64, height=64)
             }
         })
     self.assertMarkup(html, 'noscript', {'data-shape': 'original'})
Пример #11
0
    def test_should_render_child_page_rather_than_page_if_provided(self):
        page = Page()
        page.set_slot_content('content', '<h1>Page</h1>')

        child_page = BlogPost()
        child_page.set_slot_content('content', '<h1>Child Page</h1>')

        self.assertEqual(
            '<h1>Child Page</h1>',
            self._render("{% load cms_tags %}{% slot 'content' %}", {
                'page': page,
                'child_page': child_page
            }))
Пример #12
0
    def test_meta_keywords_should_generate_meta_keywords_automatically_from_content_if_no_meta_keywords_are_available(
            self):
        # source: wikipedia: https://en.wikipedia.org/wiki/Albert_Einstein
        s = Page()
        s.set_slot_content(
            'content', """
            <p><b>Albert Einstein</b> (<span class="nowrap"><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English" title="Help:IPA for English">/<span style="border-bottom:1px dotted"><span title="/ˈ/ primary stress follows">ˈ</span><span title="/aɪ/ long 'i' in 'tide'">aɪ</span><span title="'n' in 'no'">n</span><span title="'s' in 'sigh'">s</span><span title="'t' in 'tie'">t</span><span title="/aɪ/ long 'i' in 'tide'">aɪ</span><span title="'n' in 'no'">n</span></span>/</a></span></span>;<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span>[</span>3<span>]</span></a></sup> <small>German:</small> <span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA"><a href="/wiki/Help:IPA_for_German" title="Help:IPA for German">[ˈalbɛɐ̯t ˈaɪnʃtaɪn]</a></span><small class="nowrap metadata">&nbsp;(<a href="/wiki/File:Albert_Einstein_german.ogg" title="File:Albert Einstein german.ogg"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/2/21/Speaker_Icon.svg/13px-Speaker_Icon.svg.png" width="13" height="13" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/2/21/Speaker_Icon.svg/20px-Speaker_Icon.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/2/21/Speaker_Icon.svg/26px-Speaker_Icon.svg.png 2x" data-file-width="500" data-file-height="500"></a> <a href="//upload.wikimedia.org/wikipedia/commons/6/6b/Albert_Einstein_german.ogg" class="internal" title="Albert Einstein german.ogg">listen</a>)</small>; 14 March 1879&nbsp;– 18 April 1955) was a German-born <a href="/wiki/Theoretical_physicist" title="Theoretical physicist" class="mw-redirect">theoretical physicist</a>. He developed the <a href="/wiki/General_theory_of_relativity" title="General theory of relativity" class="mw-redirect">general theory of relativity</a>, one of the two pillars of <a href="/wiki/Modern_physics" title="Modern physics">modern physics</a> (alongside <a href="/wiki/Quantum_mechanics" title="Quantum mechanics">quantum mechanics</a>).<sup id="cite_ref-frs_2-2" class="reference"><a href="#cite_note-frs-2"><span>[</span>2<span>]</span></a></sup><sup id="cite_ref-YangHamilton2010_4-0" class="reference"><a href="#cite_note-YangHamilton2010-4"><span>[</span>4<span>]</span></a></sup><sup class="reference" style="white-space:nowrap;">:274</sup> Einstein's work is also known for its influence on the <a href="/wiki/Philosophy_of_science" title="Philosophy of science">philosophy of science</a>.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span>[</span>5<span>]</span></a></sup><sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span>[</span>6<span>]</span></a></sup> Einstein is best known in popular culture for his <a href="/wiki/Mass%E2%80%93energy_equivalence" title="Mass–energy equivalence">mass–energy equivalence</a> formula <span class="nowrap"><i>E</i> = <i>mc</i><sup>2</sup></span> (which has been dubbed "the world's most famous equation").<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span>[</span>7<span>]</span></a></sup> He received the 1921 <a href="/wiki/Nobel_Prize_in_Physics" title="Nobel Prize in Physics">Nobel Prize in Physics</a> for his "services to theoretical physics", in particular his discovery of the law of the <a href="/wiki/Photoelectric_effect" title="Photoelectric effect">photoelectric effect</a>, a pivotal step in the evolution of <a href="/wiki/Introduction_to_quantum_mechanics" title="Introduction to quantum mechanics">quantum theory</a>.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span>[</span>8<span>]</span></a></sup></p>
            <p>Near the beginning of his career, Einstein thought that <a href="/wiki/Newtonian_mechanics" title="Newtonian mechanics" class="mw-redirect">Newtonian mechanics</a> was no longer enough to reconcile the laws of <a href="/wiki/Classical_mechanics" title="Classical mechanics">classical mechanics</a> with the laws of the <a href="/wiki/Electromagnetic_field" title="Electromagnetic field">electromagnetic field</a>. This led to the development of his <a href="/wiki/Special_theory_of_relativity" title="Special theory of relativity" class="mw-redirect">special theory of relativity</a>. He realized, however, that the principle of relativity could also be extended to <a href="/wiki/Gravitational_fields" title="Gravitational fields" class="mw-redirect">gravitational fields</a>, and with his subsequent theory of gravitation in 1916, he published a paper on general relativity. He continued to deal with problems of <a href="/wiki/Statistical_mechanics" title="Statistical mechanics">statistical mechanics</a> and quantum theory, which led to his explanations of <a href="/wiki/Particle" title="Particle">particle</a> theory and the <a href="/wiki/Brownian_motion" title="Brownian motion">motion of molecules</a>. He also investigated the thermal properties of light which laid the foundation of the <a href="/wiki/Photon" title="Photon">photon</a> theory of light. In 1917, Einstein applied the general theory of relativity to model the large-scale structure of the <a href="/wiki/Universe" title="Universe">universe</a>.<sup id="cite_ref-Nobel_9-0" class="reference"><a href="#cite_note-Nobel-9"><span>[</span>9<span>]</span></a></sup><sup id="cite_ref-NYT-20151124_10-0" class="reference"><a href="#cite_note-NYT-20151124-10"><span>[</span>10<span>]</span></a></sup></p>
            <p>He was visiting the United States when <a href="/wiki/Adolf_Hitler" title="Adolf Hitler">Adolf Hitler</a> came to power in 1933 and, being Jewish, did not go back to Germany, where he had been a professor at the <a href="/wiki/Prussian_Academy_of_Sciences" title="Prussian Academy of Sciences">Berlin Academy of Sciences</a>. He settled in the U.S., becoming an <a href="/wiki/American_citizen" title="American citizen" class="mw-redirect">American citizen</a> in 1940.<sup id="cite_ref-BoyerDubofsky2001_11-0" class="reference"><a href="#cite_note-BoyerDubofsky2001-11"><span>[</span>11<span>]</span></a></sup> On the eve of World War II, he endorsed a <a href="/wiki/Einstein%E2%80%93Szil%C3%A1rd_letter" title="Einstein–Szilárd letter">letter to President Franklin D. Roosevelt</a> alerting him to the potential development of "extremely powerful bombs of a new type" and recommending that the U.S. begin similar research. This eventually led to what would become the <a href="/wiki/Manhattan_Project" title="Manhattan Project">Manhattan Project</a>. Einstein supported defending the Allied forces, but largely denounced the idea of using the newly discovered <a href="/wiki/Nuclear_fission" title="Nuclear fission">nuclear fission</a> as a weapon. Later, with the British philosopher <a href="/wiki/Bertrand_Russell" title="Bertrand Russell">Bertrand Russell</a>, Einstein signed the <a href="/wiki/Russell%E2%80%93Einstein_Manifesto" title="Russell–Einstein Manifesto">Russell–Einstein Manifesto</a>, which highlighted the danger of nuclear weapons. Einstein was affiliated with the <a href="/wiki/Institute_for_Advanced_Study" title="Institute for Advanced Study">Institute for Advanced Study</a> in <a href="/wiki/Princeton,_New_Jersey" title="Princeton, New Jersey">Princeton, New Jersey</a>, until his death in 1955.</p>
            <p>Einstein published <a href="/wiki/List_of_scientific_publications_by_Albert_Einstein" title="List of scientific publications by Albert Einstein">more than 300 scientific papers</a> along with over 150 non-scientific works.<sup id="cite_ref-Nobel_9-1" class="reference"><a href="#cite_note-Nobel-9"><span>[</span>9<span>]</span></a></sup><sup id="cite_ref-Paul_Arthur_Schilpp.2C_editor_1951_730.E2.80.93746_12-0" class="reference"><a href="#cite_note-Paul_Arthur_Schilpp.2C_editor_1951_730.E2.80.93746-12"><span>[</span>12<span>]</span></a></sup> On 5 December 2014, universities and archives announced the release of Einstein's papers, comprising more than 30,000 unique documents.<sup id="cite_ref-FOOTNOTEStachel2008_13-0" class="reference"><a href="#cite_note-FOOTNOTEStachel2008-13"><span>[</span>13<span>]</span></a></sup><sup id="cite_ref-NYT-20141204-DB_14-0" class="reference"><a href="#cite_note-NYT-20141204-DB-14"><span>[</span>14<span>]</span></a></sup> Einstein's intellectual achievements and originality have made the word "Einstein" synonymous with "<a href="/wiki/Genius" title="Genius">genius</a>".<sup id="cite_ref-wordnetweb.princeton.edu_15-0" class="reference"><a href="#cite_note-wordnetweb.princeton.edu-15"><span>[</span>15<span>]</span></a></sup></p>
        """)

        self.assertEqual(
            'einstein, theory, relativity, mechanics, quantum, general, physics, german, world, scientific, nuclear, russell, published, theoretical, papers, development, light, laws, endorsed, developed',
            s.meta_keywords)
Пример #13
0
 def setUpClass(cls):
     super(CMSModelsExcerptMixinTestCase, cls).setUpClass()
     cls.page = Page()
     cls.page.set_slot_content(
         'content',
         '<p>Any <em>intelligent</em> fool can make things <b>bigger</b>, more complex, and more violent. It takes a touch of <em>genius</em> - <span class="highlight">and a lot of courage</span> - to move in the opposite direction.</p>'
     )
Пример #14
0
 def test_should_raise_exception_for_unresolved_page_link_in_debug(self):
     with self.assertRaisesRegexp(ValueError,
                                  'Unable to resolve page link'):
         self._render_link('#link[Page:2]',
                           {'Page': {
                               '1': Page(id=1, slug='foo')
                           }})
Пример #15
0
 def test_should_return_empty_link_for_unresolved_page_link_id(self):
     self.assertEqual(
         '<a href="">Foo</a>',
         self._render_link('#link[Page:2]',
                           {'Page': {
                               '1': Page(id=1, slug='foo')
                           }}))
Пример #16
0
 def test_should_rewrite_page_links(self):
     self.assertEqual(
         '<a href="http://www.testapp.cubane.innershed.com/foo/">Foo</a>',
         self._render_link('#link[Page:1]',
                           {'Page': {
                               '1': Page(id=1, slug='foo')
                           }}))
Пример #17
0
    def test_should_render_cms_page_and_dispatch_email(self):
        page = Page()
        page.title = 'Test Page'
        page.slug = 'test'
        page.template = 'testapp/mail/enquiry_visitor.html'
        page.set_slot_content('content', '<h1>Test</h1>')
        page.save()

        cubane_send_cms_mail(None, '*****@*****.**', 'Test', page)

        m = self.get_latest_email()
        self.assertTrue('*****@*****.**' in m.to, 'to address not found')
        self.assertEqual(m.subject, 'Test')
        self.assertTrue('<html><head><title>' in m.message().as_string())
        self.assertTrue('<h1>Test</h1>' in m.message().as_string())
Пример #18
0
 def create_page(self,
                 title,
                 template='testapp/page.html',
                 nav='header',
                 entity_type=None,
                 seq=0,
                 legacy_url=None,
                 identifier=None,
                 parent=None):
     p = Page(title=title,
              slug=slugify(title),
              template=template,
              _nav=nav,
              entity_type=entity_type,
              seq=seq,
              legacy_url=legacy_url,
              identifier=identifier,
              parent=parent)
     p.save()
     return p
Пример #19
0
 def create_page(cls,
                 title,
                 template='testapp/page.html',
                 nav='header',
                 entity_type=None,
                 seq=0,
                 legacy_url=None,
                 identifier=None,
                 parent=None,
                 is_homepage=False,
                 disabled=False):
     p = Page(title=title,
              slug=slugify(title),
              template=template,
              _nav=nav,
              entity_type=entity_type,
              seq=seq,
              legacy_url=legacy_url,
              identifier=identifier,
              parent=parent,
              is_homepage=is_homepage,
              disabled=disabled)
     p.save()
     return p
Пример #20
0
 def test_requires_cubane_cms_module(self):
     with self.assertRaisesRegexp(
             ValueError,
             'cubane.cms required for sending cms page emails.'):
         cubane_send_cms_mail(None, '*****@*****.**', 'Test', Page())
Пример #21
0
 def test_meta_description_can_be_based_on_multiple_slots(self):
     s = Page(_meta_description=None)
     s.set_slot_content('c', '<h1>Foo</h1>')
     s.set_slot_content('b', '<p>Bar</p>')
     self.assertEqual('Foo Bar', s.meta_description)
Пример #22
0
    def test_get_default_pages_pks_should_return_pks_for_default_pages_as_list_abmitting_not_assigned_pages(
            self):
        contact = Page()
        enquiry = Page()

        contact.save()
        enquiry.save()

        self.settings.contact_page = contact
        self.settings.enquiry_template = enquiry

        self.assertEqual([contact.pk, enquiry.pk],
                         self.settings.get_default_pages_pks())

        contact.delete()
        enquiry.delete()
Пример #23
0
    def test_get_default_pages_pks_should_return_pks_for_default_pages_as_list(
            self):
        home = Page()
        contact = Page()
        _404 = Page()
        enquiry = Page()

        home.save()
        contact.save()
        _404.save()
        enquiry.save()

        self.settings.homepage = home
        self.settings.contact_page = contact
        self.settings.default_404 = _404
        self.settings.enquiry_template = enquiry

        self.assertEqual([home.pk, contact.pk, _404.pk, enquiry.pk],
                         self.settings.get_default_pages_pks())

        home.delete()
        contact.delete()
        _404.delete()
        enquiry.delete()
Пример #24
0
 def test_meta_keywords_should_return_empty_string_if_no_keywords_are_available_and_content_is_empty(
         self):
     s = Page()
     self.assertEqual('', s.meta_keywords)
Пример #25
0
 def setUp(self):
     self.page = Page()
Пример #26
0
class CMSModelsPageTestCase(CubaneTestCase):
    def setUp(self):
        self.page = Page()

    def test_get_backend_section_group_should_return_none_if_not_set(self):
        self.assertFalse(hasattr(Page.Listing, 'group'))
        self.assertIsNone(self.page.get_backend_section_group())

    def test_get_backend_section_group_should_return_group_name(self):
        Page.Listing.group = 'testgroup'
        self.assertEqual(Page.Listing.group,
                         self.page.get_backend_section_group())
        delattr(Page.Listing, 'group')

    def test_save_should_auto_generate_slug_if_no_slug_is_present(self):
        self.page.title = 'Hello World'
        self.page.save()
        self.assertEqual('hello-world', self.page.slug)
        self.page.delete()

    def test_save_should_not_auto_generate_slug_if_slug_is_present(self):
        self.page.title = 'Hello World'
        self.page.slug = 'already-present'
        self.page.save()
        self.assertEqual('already-present', self.page.slug)
        self.page.delete()

    def test_gallery_property_should_return_attached_media_in_seq(self):
        self.page.title = 'Test'
        self.page.save()

        content_type = ContentType.objects.get_for_model(self.page.__class__)
        names = ['c', 'b', 'a']
        for seq, name in enumerate(names, start=1):
            m = Media(caption=name)
            m.save()

            mg = MediaGallery()
            mg.media = m
            mg.content_type = content_type
            mg.target_id = self.page.pk
            mg.seq = seq
            mg.save()

        self.assertEqual(names, [m.caption for m in self.page.gallery])

        [mg.delete() for mg in MediaGallery.objects.all()]
        [m.delete() for m in Media.objects.all()]
        self.page.delete()

    def test_to_dict(self):
        self.page.id = 1
        self.page.title = 'Hello World'
        self.page.slug = 'hello-world'

        self.assertEqual(
            {
                'foo': 'bar',
                'title': 'Hello World',
                'url': 'http://www.testapp.cubane.innershed.com/hello-world/',
                'url_path': '/hello-world/',
                'slug': 'hello-world',
                'id': 1
            }, self.page.to_dict({'foo': 'bar'}))
Пример #27
0
class CMSModelsEditableContentMixinTestCase(CubaneTestCase):
    def setUp(self):
        self.page = Page()

    def test_set_and_get_data(self):
        self.assertIsNone(self.page._data)
        self.page.set_data('Hello World')
        self.assertIsNotNone(self.page._data)
        self.assertEqual('Hello World', self.page.get_data())

    def test_set_and_get_slot_content(self):
        self.assertIsNone(self.page._data)
        self.page.set_slot_content('content', '<h1>Test</h1>')
        self.page.set_slot_content('introduction', '<h1>Introduction</h1>')
        self.assertIsNotNone(self.page._data)
        self.assertEqual('<h1>Test</h1>',
                         self.page.get_slot_content('content'))
        self.assertEqual('<h1>Introduction</h1>',
                         self.page.get_slot_content('introduction'))

    def test_get_slot_content_should_return_empty_for_empty_data(self):
        self.assertIsNone(self.page._data)
        self.assertEqual('', self.page.get_slot_content('content'))

    def test_get_slot_content_should_return_empty_for_non_existing_slot(self):
        self.page.set_data({'does-not-exist': 'Foo'})
        self.assertEqual('', self.page.get_slot_content('does-not-exist'))

    def test_set_slot_content_should_not_allow_setting_content_for_slot_that_does_not_exist(
            self):
        self.page.set_slot_content('does-not-exist', 'Foo')
        self.assertEqual({}, self.page.get_data())

    @override_settings(CMS_SLOTNAMES=['a', 'b'])
    def test_get_combined_slot_content_should_return_content_of_multiple_slots_combined(
            self):
        self.page.set_slot_content('a', 'Foo')
        self.page.set_slot_content('b', 'Bar')
        self.assertEqual('Foo Bar',
                         self.page.get_combined_slot_content(['a', 'b']))

    @override_settings(CMS_SLOTNAMES=['a', 'b'])
    def test_get_combined_slot_content_should_ignore_empty_slot(self):
        self.page.set_slot_content('a', 'Foo')
        self.assertEqual('Foo', self.page.get_combined_slot_content(['a',
                                                                     'b']))

    def test_slotnames_with_content(self):
        self.page.set_slot_content('content', '<h1>Test</h1>')
        self.page.set_slot_content('introduction', '<h1>Introduction</h1>')
        self.assertEqual(['content', 'introduction'],
                         self.page.slotnames_with_content())

    def test_slotnames_with_content_with_empty_data(self):
        self.assertIsNone(self.page._data)
        self.assertEqual([], self.page.slotnames_with_content())

    def test_content_by_slot(self):
        self.page.set_slot_content('content', '<h1>Test</h1>')
        self.page.set_slot_content('introduction', '<h1>Introduction</h1>')
        self.assertEqual(
            {
                'content': '<h1>Test</h1>',
                'introduction': '<h1>Introduction</h1>'
            }, self.page.content_by_slot())

    def test_content_by_slot_with_image_rewrite(self):
        self.page.set_slot_content('content',
                                   '<img data-cubane-media-id="1"/>')
        images = {1: Media(id=1, caption='Test')}
        html = self.page.content_by_slot(images).get('content')
        self.assertIn('class="lazy-load-shape-original"', html)
        self.assertIn('style="padding-bottom:100.0%;"', html)
        self.assertIn('data-shape="original"', html)
        self.assertIn('data-path="/0/1/"', html)
        self.assertIn('data-blank="0"', html)
        self.assertIn('data-sizes="xx-small"', html)
        self.assertIn(
            '<img src="http://www.testapp.cubane.innershed.com/media/shapes/original/xx-small/0/1/" alt="Test" title="Test">',
            html)

    def test_content_by_slot_with_empty_data(self):
        self.assertIsNone(self.page._data)
        self.assertEqual({}, self.page.content_by_slot())
Пример #28
0
class CMSModelsPageAbstractTestCase(CubaneTestCase):
    def setUp(self):
        self.page = Page()

    def test_get_nav_should_return_list_of_navigation_section_assigned(self):
        self.page.set_nav(['a', 'b'])
        self.assertEqual(['a', 'b'], self.page.get_nav())

    def test_get_nav_should_return_empty_list_if_no_navigation_is_assigned(
            self):
        self.assertEqual([], self.page.get_nav())

    def test_set_nav_should_clear_property_for_empty_list(self):
        self.page.set_nav(['a', 'b'])
        self.assertIsNotNone(self.page._nav)
        self.page.set_nav([])
        self.assertIsNone(self.page._nav)

    def test_get_nav_property(self):
        self.page.nav = ['a', 'b']
        self.assertEqual(['a', 'b'], self.page.nav)

    def test_get_entity_model_should_return_model_of_entity_used_for_child_pages_for_this_page(
            self):
        self.page.entity_type = 'CustomChildPage'
        self.assertTrue(
            issubclass(self.page.get_entity_model(), CustomChildPage))

    def test_get_entity_model_not_found(self):
        self.page.entity_type = 'DoesNotExist'
        self.assertIsNone(self.page.get_entity_model())

    def test_get_filepath_should_return_path_to_cache_for_empty_slug(self):
        self.assertEqual('index.html', self.page.get_filepath())

    def test_get_filepath_should_return_path_to_cache_with_slug_prefix(self):
        self.page.slug = 'test-page'
        self.assertEqual('test-page/index.html', self.page.get_filepath())

    def test_get_filepath_for_homepage_should_return_path_to_cache(self):
        self.page.is_homepage = True
        self.assertEqual('index.html', self.page.get_filepath())

    def test_get_filepath_for_homepage_should_ignore_slug(self):
        self.page.is_homepage = True
        self.page.slug = 'test-page'
        self.assertEqual('index.html', self.page.get_filepath())

    def test_get_slug_should_be_empty_for_homepage(self):
        self.page.is_homepage = True
        self.page.slug = 'test-page'
        self.assertEqual('', self.page.get_slug())

    def test_get_slug_should_return_slug_for_page_other_than_homepage(self):
        self.page.is_homepage = False
        self.page.slug = 'test-page'
        self.assertEqual('test-page', self.page.get_slug())

    def test_get_fullslug_for_homepage_should_be_slash_ignoring_slug(self):
        self.page.is_homepage = True
        self.page.slug = 'test-page'
        self.assertEqual('', self.page.get_fullslug())

    def test_get_fullslug_for_page_should_contain_slug_with_slashes(self):
        self.page.is_homepage = False
        self.page.slug = 'test-page'
        self.assertEqual('/test-page/', self.page.get_fullslug())

    def test_get_absolute_url_should_return_root_url_for_homepage(self):
        self.page.is_homepage = True
        self.page.slug = 'test-page'
        self.assertEqual('http://www.testapp.cubane.innershed.com/',
                         self.page.get_absolute_url())

    @override_settings(APPEND_SLASH=True)
    def test_get_absolute_url_should_return_full_slug_ending_with_slash_with_append_slash_option(
            self):
        self.page.is_homepage = False
        self.page.slug = 'test-page'
        self.assertEqual('http://www.testapp.cubane.innershed.com/test-page/',
                         self.page.get_absolute_url())

    @override_settings(APPEND_SLASH=False)
    def test_get_absolute_url_should_return_full_slug_ending_with_slash_without_append_slash_option(
            self):
        self.page.is_homepage = False
        self.page.slug = 'test-page'
        self.assertEqual('http://www.testapp.cubane.innershed.com/test-page',
                         self.page.get_absolute_url())
Пример #29
0
 def test_meta_keywords_should_return_meta_keywords_if_available(self):
     s = Page(_meta_keywords='einstein, relativity, speed of light')
     self.assertEqual('einstein, relativity, speed of light',
                      s.meta_keywords)
Пример #30
0
 def _page(self, title=None, meta_title=None):
     page = Page()
     page.title = title
     page._meta_title = meta_title
     return page