コード例 #1
0
    def handle(self, *args, **options):
        number_of_posts = options['number_of_posts']

        home_page = HomePage.objects.get(slug='home')

        if BlogIndexPage.objects.all():
            blog_index_page = BlogIndexPage.objects.all().first()
        else:
            blog_index_page = BlogIndexPageFactory(parent=home_page,
                                                   title="News")

        CATEGORY_NAMES = [
            'Release Announcement',
            'Pre-Release Announcement',
            'Interest Article',
            'Security Advisory',
        ]

        categories = []
        for name in CATEGORY_NAMES:
            try:
                category_page = CategoryPage.objects.get(title=name)
            except ObjectDoesNotExist:
                category_page = CategoryPageFactory(title=name,
                                                    parent=blog_index_page)

            categories.append(category_page)

        for x in range(number_of_posts):
            blog_page = BlogPageFactory(parent=blog_index_page,
                                        category=random.choice(categories))
            blog_page.save()
コード例 #2
0
class BlogIndexPageTest(TestCase):
    def setUp(self):
        self.blog_index = BlogIndexPageFactory()
        self.live_post = BlogPageFactory(live=True, parent=self.blog_index)
        self.unpublished_post = BlogPageFactory(live=False, parent=self.blog_index)

    def test_get_posts_should_return_live_posts(self):
        posts = self.blog_index.get_posts()
        self.assertIn(self.live_post, posts)

    def test_get_posts_should_not_return_unpublished_posts(self):
        posts = self.blog_index.get_posts()
        self.assertNotIn(self.unpublished_post, posts)

    def test_get_posts_returns_newest_post_first(self):
        self.live_post.delete()  # not necessary for this test
        BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index)
        first = BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index)
        BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index)
        posts = self.blog_index.get_posts()
        self.assertEqual(first, posts.first())

    def test_get_posts_returns_oldest_post_last(self):
        self.live_post.delete()  # not necessary for this test
        BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index)
        BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index)
        last = BlogPageFactory(publication_datetime='2015-03-31 00:00Z', parent=self.blog_index)
        BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index)
        posts = self.blog_index.get_posts()
        self.assertEqual(last, posts.last())
コード例 #3
0
 def test_get_posts_returns_newest_post_first(self):
     self.live_post.delete()  # not necessary for this test
     BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index)
     first = BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index)
     BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index)
     posts = self.blog_index.get_posts()
     self.assertEqual(first, posts.first())
コード例 #4
0
 def setUp(self):
     self.blog_index = BlogIndexPageFactory()
     self.live_post = BlogPageFactory(live=True,
                                      parent=self.blog_index,
                                      publication_datetime=datetime(
                                          2017, 1, 1, tzinfo=pytz.UTC))
     self.unpublished_post = BlogPageFactory(live=False,
                                             parent=self.blog_index)
コード例 #5
0
 def test_get_posts_returns_oldest_post_last(self):
     self.live_post.delete()  # not necessary for this test
     self.category_post.delete()  # not necessary for this test
     BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index, category=self.category)
     BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index)
     last = BlogPageFactory(publication_datetime='2015-03-31 00:00Z', parent=self.blog_index, category=self.category)
     BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index, category=self.category)
     posts = self.category.get_posts()
     self.assertEqual(last, posts.last())
コード例 #6
0
 def setUp(self):
     self.title = 'Awesome'
     self.body = 'Cool'
     self.teaser_text = 'Best blog'
     blog_index = BlogIndexPageFactory()
     self.blog = BlogPageFactory(
         title=self.title,
         body=json.dumps([{
             'type': 'text',
             'value': self.body
         }]),
         parent=blog_index,
         teaser_text=self.teaser_text,
     )
     self.search_content = self.blog.get_search_content()
コード例 #7
0
class TestBlogPage(TestCase):
    def setUp(self):
        self.title = 'Awesome'
        self.body = 'Cool'
        self.teaser_text = 'Best blog'
        blog_index = BlogIndexPageFactory()
        self.blog = BlogPageFactory(
            title=self.title,
            body=json.dumps([{
                'type': 'text',
                'value': self.body
            }]),
            parent=blog_index,
            teaser_text=self.teaser_text,
        )
        self.search_content = self.blog.get_search_content()

    def test_get_search_content_indexes_title(self):
        self.assertIn(self.title, self.search_content.as_string())

    def test_get_search_content_indexes_body(self):
        self.assertIn(self.body, self.search_content.as_string())

    def test_get_search_content_indexes_category_page_title(self):
        self.assertIn(self.blog.category.title,
                      self.search_content.as_string())

    def test_get_search_content_indexes_teaser_text(self):
        self.assertIn(self.teaser_text, self.search_content.as_string())
コード例 #8
0
 def test_get_posts_returns_newest_post_first(self):
     BlogPageFactory(publication_datetime=datetime(2018,
                                                   1,
                                                   1,
                                                   tzinfo=pytz.UTC),
                     parent=self.blog_index)
     first = BlogPageFactory(publication_datetime=datetime(2018,
                                                           3,
                                                           31,
                                                           tzinfo=pytz.UTC),
                             parent=self.blog_index)
     BlogPageFactory(publication_datetime=datetime(2017,
                                                   3,
                                                   1,
                                                   tzinfo=pytz.UTC),
                     parent=self.blog_index)
     posts = self.blog_index.get_posts()
     self.assertEqual(first, posts.first())
コード例 #9
0
class CategoryPageTest(TestCase):
    def setUp(self):
        self.blog_index = BlogIndexPageFactory()
        self.category = CategoryPageFactory(parent=self.blog_index)
        self.live_post = BlogPageFactory(live=True, category=self.category, parent=self.blog_index)
        self.unpublished_post = BlogPageFactory(live=False, category=self.category, parent=self.blog_index)
        self.other_category = CategoryPageFactory(parent=self.blog_index)
        self.category_post = BlogPageFactory(parent=self.blog_index, category=self.category)
        self.other_category_post = BlogPageFactory(parent=self.blog_index, category=self.other_category)

    def test_get_posts_should_return_live_posts(self):
        posts = self.category.get_posts()
        self.assertIn(self.live_post, posts)

    def test_get_posts_should_not_return_unpublished_posts(self):
        posts = self.category.get_posts()
        self.assertNotIn(self.unpublished_post, posts)

    def test_get_posts_should_return_posts_in_its_category(self):
        posts = self.category.get_posts()
        self.assertIn(self.category_post, posts)

    def test_get_posts_should_not_return_posts_in_other_category(self):
        posts = self.category.get_posts()
        self.assertNotIn(self.other_category_post, posts)

    def test_get_posts_should_return_siblings(self):
        post = self.category.get_posts().first()
        # Because Wagtail sometimes returns a Page object, and sometimes a BlogIndexPage object, testing via title
        self.assertEqual(self.category.get_parent().title, post.get_parent().title)

    def test_get_posts_returns_newest_post_first(self):
        self.live_post.delete()  # not necessary for this test
        self.category_post.delete()  # not necessary for this test
        BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index, category=self.category)
        first = BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index, category=self.category)
        BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index, category=self.category)
        posts = self.category.get_posts()
        self.assertEqual(first, posts.first())

    def test_get_posts_returns_oldest_post_last(self):
        self.live_post.delete()  # not necessary for this test
        self.category_post.delete()  # not necessary for this test
        BlogPageFactory(publication_datetime='2018-01-01 00:00Z', parent=self.blog_index, category=self.category)
        BlogPageFactory(publication_datetime='2018-03-31 00:00Z', parent=self.blog_index)
        last = BlogPageFactory(publication_datetime='2015-03-31 00:00Z', parent=self.blog_index, category=self.category)
        BlogPageFactory(publication_datetime='2018-03-01 00:00Z', parent=self.blog_index, category=self.category)
        posts = self.category.get_posts()
        self.assertEqual(last, posts.last())
コード例 #10
0
    def setUp(self):
        Page.objects.filter(slug='home').delete()
        home_page = HomePageFactory.build(
            description_header="Share and accept documents securely.",
            slug="home")

        root_page = Page.objects.get(title='Root')
        root_page.add_child(instance=home_page)

        Site.objects.create(site_name='SecureDrop.org (Dev)',
                            hostname='localhost',
                            port='8000',
                            root_page=home_page,
                            is_default_site=True)
        self.blog_index = BlogIndexPageFactory(parent=home_page,
                                               search_description="Search me!")
        self.blog_index.save()
        self.blog = BlogPageFactory(parent=self.blog_index)
        BlogPageFactory(parent=self.blog_index)
        self.client = Client()
        response = self.client.get("{}feed/".format(self.blog_index.url))
        self.parsed = feedparser.parse(response.content)
コード例 #11
0
 def setUp(self):
     self.title = 'Awesome'
     self.body = 'Cool'
     self.blog_index = BlogIndexPageFactory(title=self.title,
                                            body=json.dumps([{
                                                'type':
                                                'rich_text',
                                                'value':
                                                self.body
                                            }]))
     self.blog_title = 'Blog'
     self.blog_page = BlogPageFactory(title='Blog', parent=self.blog_index)
     self.search_content = self.blog_index.get_search_content()
コード例 #12
0
 def setUp(self):
     self.blog_index = BlogIndexPageFactory()
     self.category = CategoryPageFactory(parent=self.blog_index)
     self.live_post = BlogPageFactory(live=True, category=self.category, parent=self.blog_index)
     self.unpublished_post = BlogPageFactory(live=False, category=self.category, parent=self.blog_index)
     self.other_category = CategoryPageFactory(parent=self.blog_index)
     self.category_post = BlogPageFactory(parent=self.blog_index, category=self.category)
     self.other_category_post = BlogPageFactory(parent=self.blog_index, category=self.other_category)
コード例 #13
0
    def handle(self, *args, **options):
        number_of_posts = options['number_of_posts']

        try:
            home_page = HomePage.objects.get(slug='home')
        except HomePage.DoesNotExist:
            management.call_command('createhomepage')
            home_page = HomePage.objects.get(slug='home')

        if BlogIndexPage.objects.all():
            blog_index_page = BlogIndexPage.objects.first()
        else:
            blog_index_page = BlogIndexPageFactory(parent=home_page)

        author_page = PersonPageFactory(title='Rachel S', parent=home_page)

        for x in range(number_of_posts):
            BlogPageFactory(parent=blog_index_page, author=author_page)
コード例 #14
0
 def setUp(self):
     self.blog_index = BlogIndexPageFactory()
     self.live_post = BlogPageFactory(live=True, parent=self.blog_index)
     self.unpublished_post = BlogPageFactory(live=False, parent=self.blog_index)