コード例 #1
0
ファイル: test_sitemap.py プロジェクト: shoyshab/django-cms
    def test_sitemap_unpublished_titles(self):
        """
        Check that titles attached to unpublished pages are not in the urlset.
        As titles are 'published' depending on their attached page, we create a
        set of unpublished titles by checking titles attached to the draft and
        public version of each page
        """
        sitemap = CMSSitemap()
        locations = []
        urlset = sitemap.get_urls()
        unpublished_titles = set()
        for item in urlset:
            locations.append(item['location'])
        for page in Page.objects.drafts():
            if page.get_public_object():
                set1 = set(page.get_public_object().title_set.values_list(
                    'path', flat=True))
                set2 = set(page.title_set.values_list('path', flat=True))
                unpublished_titles.update(set2.difference(set1))
            else:
                unpublished_titles.update(
                    page.title_set.values_list('path', flat=True))

        for path in unpublished_titles:
            title = Title.objects.get(path=path)
            if title.path:
                url = 'http://example.com/%s/%s/' % (title.language,
                                                     title.path)
            else:
                url = 'http://example.com/%s/%s' % (title.language, title.path)
            self.assertFalse(url in locations)
コード例 #2
0
    def test_sitemap_unpublished_titles(self):
        """
        Check that titles attached to unpublished pages are not in the urlset.
        As titles are 'published' depending on their attached page, we create a
        set of unpublished titles by checking titles attached to the draft and
        public version of each page
        """
        sitemap = CMSSitemap()
        locations = []
        urlset = sitemap.get_urls()
        unpublished_titles = set()
        for item in urlset:
            locations.append(item['location'])
        for page in Page.objects.drafts():
            if page.get_public_object():
                set1 = set(page.get_public_object().title_set.values_list('path', flat=True))
                set2 = set(page.title_set.values_list('path', flat=True))
                unpublished_titles.update(set2.difference(set1))
            else:
                unpublished_titles.update(page.title_set.values_list('path', flat=True))

        for path in unpublished_titles:
            title = Title.objects.get(path=path)
            if title.path:
                url = 'http://example.com/%s/%s/' % (title.language, title.path)
            else:
                url = 'http://example.com/%s/%s' % (title.language, title.path)
            self.assertFalse(url in locations)
コード例 #3
0
ファイル: page.py プロジェクト: sekouperry/django-cms
 def test_sitemap_uses_publication_date_when_later_than_modification(self):
     now = timezone.now()
     one_day_ago = now - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=now)
     page.creation_date = one_day_ago
     page.changed_date = one_day_ago
     sitemap = CMSSitemap()
     actual_last_modification_time = sitemap.lastmod(page)
     self.assertEqual(actual_last_modification_time, now)
コード例 #4
0
ファイル: page.py プロジェクト: sekouperry/django-cms
 def test_sitemap_includes_last_modification_date(self):
     one_day_ago = timezone.now() - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=one_day_ago)
     page.creation_date = one_day_ago
     page.save()
     sitemap = CMSSitemap()
     self.assertEqual(sitemap.items().count(), 1)
     actual_last_modification_time = sitemap.lastmod(sitemap.items()[0])
     self.assertTrue(actual_last_modification_time > one_day_ago)
コード例 #5
0
ファイル: page.py プロジェクト: Nucleoos/sowing-church
 def test_sitemap_uses_publication_date_when_later_than_modification(self):
     now = datetime.datetime.now()
     one_day_ago = now - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=now)
     page.creation_date = one_day_ago
     page.changed_date = one_day_ago
     sitemap = CMSSitemap()
     actual_last_modification_time = sitemap.lastmod(page)
     self.assertEqual(actual_last_modification_time, now)
コード例 #6
0
ファイル: page.py プロジェクト: Nucleoos/sowing-church
 def test_sitemap_includes_last_modification_date(self):
     one_day_ago = datetime.datetime.now() - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=one_day_ago)
     page.creation_date = one_day_ago
     page.save()
     sitemap = CMSSitemap()
     self.assertEqual(sitemap.items().count(), 1)
     actual_last_modification_time = sitemap.lastmod(sitemap.items()[0])
     self.assertTrue(actual_last_modification_time > one_day_ago)
コード例 #7
0
ファイル: test_sitemap.py プロジェクト: shoyshab/django-cms
 def test_sitemap_count(self):
     """
     Has the sitemap the correct number of elements?
     """
     sitemap = CMSSitemap()
     # 8 pages with en and de titles published
     # 1 page published only in english(with existsing de title)
     # 1 page with both titles but unpublished
     # 1 page with only english title
     self.assertEqual(sitemap.items().count(), 18)
コード例 #8
0
 def test_sitemap_count(self):
     """
     Has the sitemap the correct number of elements?
     """
     sitemap = CMSSitemap()
     # 8 pages with en and de titles published
     # 1 page published only in english(with existsing de title)
     # 1 page with both titles but unpublished
     # 1 page with only english title
     self.assertEqual(sitemap.items().count(), 18)
コード例 #9
0
ファイル: page.py プロジェクト: 360yln/django-cms-2.4
 def test_sitemap_uses_publication_date_when_later_than_modification(self):
     now = tz_now()
     now -= datetime.timedelta(microseconds=now.microsecond)
     one_day_ago = now - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=now)
     title = page.get_title_obj('en')
     page.creation_date = one_day_ago
     page.changed_date = one_day_ago
     sitemap = CMSSitemap()
     actual_last_modification_time = sitemap.lastmod(title)
     self.assertEqual(actual_last_modification_time.date(), now.date())
コード例 #10
0
ファイル: page.py プロジェクト: virtualuser/django-cms
 def test_sitemap_uses_publication_date_when_later_than_modification(self):
     now = timezone.now()
     now -= datetime.timedelta(microseconds=now.microsecond)
     one_day_ago = now - datetime.timedelta(days=1)
     page = create_page("page", "nav_playground.html", "en", published=True, publication_date=now)
     title = page.get_title_obj('en')
     page.creation_date = one_day_ago
     page.changed_date = one_day_ago
     sitemap = CMSSitemap()
     actual_last_modification_time = sitemap.lastmod(title)
     self.assertEqual(actual_last_modification_time.date(), now.date())
コード例 #11
0
 def test_sitemap_items_location(self):
     """
     Check the correct URL in location, recreating it according to the title
     attributes (instead of using Page.get_absolute_url) for a lower level
     check
     """
     sitemap = CMSSitemap()
     urlset = sitemap.get_urls()
     for item in urlset:
         if item['item'].path:
             url = 'http://example.com/%s/%s/' % (item['item'].language, item['item'].path)
         else:
             url = 'http://example.com/%s/%s' % (item['item'].language, item['item'].path)
         self.assertEqual(item['location'], url)
コード例 #12
0
ファイル: page.py プロジェクト: sekouperry/django-cms
 def test_sitemap_login_required_pages(self):
     """
     Test that CMSSitemap object contains only published,public (login_required=False) pages
     """
     create_page("page", "nav_playground.html", "en", login_required=True,
                 published=True, in_navigation=True)
     self.assertEqual(CMSSitemap().items().count(), 0)
コード例 #13
0
 def test_12_sitemap_login_required_pages(self):
     """
     Test that CMSSitemap object contains only published,public (login_required=False) pages
     """
     self.create_page(parent_page=None, published=True, in_navigation=True)
     page1 = Page.objects.all()[0]
     page1.login_required = True
     page1.save()
     self.assertEqual(CMSSitemap().items().count(), 0)
コード例 #14
0
 def test_sitemap_published_titles(self):
     """
     Check that published titles are in the urls
     """
     sitemap = CMSSitemap()
     locations = []
     urlset = sitemap.get_urls()
     for item in urlset:
         locations.append(item['location'])
     for title in Title.objects.public():
         page = title.page.get_public_object()
         if title.path:
             url = 'http://example.com/%s/%s/' % (title.language, title.path)
         else:
             url = 'http://example.com/%s/%s' % (title.language, title.path)
         if page.is_published('en') and not page.publisher_is_draft:
             self.assertTrue(url in locations)
         else:
             self.assertFalse(url in locations)
コード例 #15
0
ファイル: test_sitemap.py プロジェクト: shoyshab/django-cms
    def test_sitemap_uses_public_languages_only(self):
        """
        Pages on the sitemap should only show public languages.
        """
        lang_settings = copy.deepcopy(get_cms_setting('LANGUAGES'))
        # sanity check
        assert lang_settings[1][1]['code'] == 'de'
        # set german as private
        lang_settings[1][1]['public'] = False

        with self.settings(CMS_LANGUAGES=lang_settings):
            for item in CMSSitemap().get_urls():
                url = 'http://example.com/en/'

                if item['item'].path:
                    url += item['item'].path + '/'
                self.assertEqual(item['location'], url)