Esempio n. 1
0
    def test_expand_db_attributes_for_editor(self):
        result = PageLinkHandler.expand_db_attributes({'id': 1})
        self.assertEqual(result,
                         '<a data-linktype="page" data-id="1" href="None">')

        events_page_id = Page.objects.get(url_path='/home/events/').pk
        result = PageLinkHandler.expand_db_attributes({'id': events_page_id})
        self.assertEqual(
            result,
            '<a data-linktype="page" data-id="%d" data-parent-id="2" href="/events/">'
            % events_page_id)
    def test_expand_db_attributes_for_editor(self):
        result = PageLinkHandler.expand_db_attributes({'id': 1})
        self.assertEqual(
            result,
            '<a data-linktype="page" data-id="1" href="None">'
        )

        events_page_id = Page.objects.get(url_path='/home/events/').pk
        result = PageLinkHandler.expand_db_attributes({'id': events_page_id})
        self.assertEqual(
            result,
            '<a data-linktype="page" data-id="%d" data-parent-id="2" href="/events/">' % events_page_id
        )
Esempio n. 3
0
 def test_expand_db_attributes_autolocalizes(self):
     # Even though it's linked to the english page in rich text.
     # The link should be to the local language version if it's available
     with translation.override("fr"):
         result = PageLinkHandler.expand_db_attributes(
             {"id": self.event_page.id})
         self.assertEqual(result, '<a href="/fr/events/noel/">')
Esempio n. 4
0
    def test_expand_db_attributes_doesnt_autolocalize_unpublished_page(self):
        # We shouldn't autolocalize if the translation is unpublished
        self.fr_event_page.unpublish()
        self.fr_event_page.save()

        with translation.override("fr"):
            result = PageLinkHandler.expand_db_attributes({'id': self.event_page.id})
            self.assertEqual(result, '<a href="/en/events/christmas/">')
Esempio n. 5
0
 def test_expand_db_attributes_not_for_editor(self):
     result = PageLinkHandler.expand_db_attributes({'id': 1})
     self.assertEqual(result, '<a href="None">')
Esempio n. 6
0
 def test_expand_db_attributes_page_does_not_exist(self):
     result = PageLinkHandler.expand_db_attributes({'id': 0})
     self.assertEqual(result, '<a>')
Esempio n. 7
0
 def test_get_db_attributes(self):
     soup = BeautifulSoup('<a data-id="test-id">foo</a>', 'html5lib')
     tag = soup.a
     result = PageLinkHandler.get_db_attributes(tag)
     self.assertEqual(result, {'id': 'test-id'})
Esempio n. 8
0
 def test_expand_db_attributes_not_for_editor(self):
     result = PageLinkHandler.expand_db_attributes({'id': 1})
     self.assertEqual(result, '<a href="None">')
Esempio n. 9
0
 def test_expand_db_attributes_page_does_not_exist(self):
     result = PageLinkHandler.expand_db_attributes({'id': 0})
     self.assertEqual(result, '<a>')
Esempio n. 10
0
 def test_expand_db_attributes(self):
     result = PageLinkHandler.expand_db_attributes(
         {"id": self.event_page.id})
     self.assertEqual(result, '<a href="/en/events/christmas/">')
Esempio n. 11
0
 def test_expand_db_attributes(self):
     result = PageLinkHandler.expand_db_attributes(
         {"id": Page.objects.get(url_path="/home/events/christmas/").id})
     self.assertEqual(result, '<a href="/events/christmas/">')
 def test_get_db_attributes(self):
     soup = BeautifulSoup('<a data-id="test-id">foo</a>', 'html5lib')
     tag = soup.a
     result = PageLinkHandler.get_db_attributes(tag)
     self.assertEqual(result,
                      {'id': 'test-id'})