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())
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)
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()
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()
def test_indexed_page_should_have_correct_content(self): blog_index = BlogIndexPageFactory( parent=self.page, title="News", body=[('rich_text', RichText('hello world'))], ) index_wagtail_page(blog_index) self.assertEqual( SearchDocument.objects.filter(search_vector='hello').count(), 1) self.assertEqual( SearchDocument.objects.get( key=KEY_FORMAT.format(blog_index.pk)).search_content, blog_index.get_search_content().as_string(), )
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)
class RSSTest(unittest.TestCase): 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) def test_valid_rss_feed(self): # feed.bozo will be 1 if there is an error in the feed self.assertEqual(self.parsed.bozo, 0) def test_feed_has_correct_title(self): expected_title = '{}: {}'.format(self.blog_index.get_site().site_name, self.blog_index.title) feed_title = self.parsed.feed.get('title') self.assertEqual(expected_title, feed_title) def test_feed_has_posts(self): # Two posts were created in setup self.assertEqual(len(self.parsed.entries), 2) def test_feed_has_correct_link(self): expected_link = '{}{}'.format(self.blog_index.get_site().root_url, self.blog_index.url) self.assertEqual(self.parsed.feed.get('link'), expected_link) def test_feed_has_correct_description(self): self.assertEqual(self.parsed.feed.get('description'), self.blog_index.search_description) def test_feed_has_correct_item_title(self): first_post = self.blog_index.get_posts().first() self.assertEqual(self.parsed.entries[0].title, first_post.title) def test_feed_has_correct_item_link(self): first_post = self.blog_index.get_posts().first() expected_link = '{}{}'.format(self.blog_index.get_site().root_url, first_post.url) self.assertEqual(self.parsed.entries[0].link, expected_link)
def handle(self, *args, **options): if options['delete']: Menu.objects.filter(slug='main').delete() if not Menu.objects.filter(slug='main').exists(): main = Menu.objects.create(name='Main Menu', slug='main') home_page = HomePage.objects.get(slug='home') if BlogIndexPage.objects.first(): blog_index_page = BlogIndexPage.objects.first() else: blog_index_page = BlogIndexPageFactory(parent=home_page, title="News") if DirectoryPage.objects.first(): directory = DirectoryPage.objects.first() else: directory = DirectoryPageFactory(parent=home_page, title="Directory") if MarketingIndexPage.objects.first(): marketing = MarketingIndexPage.objects.first() else: marketing = MarketingPageFactory(parent=home_page, title="Features") MenuItem.objects.bulk_create([ MenuItem(text='Overview', link_page=marketing, menu=main, sort_order=1), MenuItem(text='News', link_page=blog_index_page, menu=main, sort_order=2), MenuItem(text='Instance Directory', link_page=directory, menu=main, sort_order=3), MenuItem( text='Contribute', link_url='#', menu=main, sort_order=4, ), MenuItem( text='Support', link_url='#', menu=main, sort_order=5, ), ])
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)
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 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)
class TestBlogIndex(TestCase): 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() def test_get_search_content_indexes_title(self): self.assertIn(self.title, self.search_content.text) def test_get_search_content_indexes_body(self): self.assertIn(self.body, self.search_content.text) def test_get_search_content_index_blog_page_titles(self): self.assertIn(self.blog_title, self.search_content.text)
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)
class BlogIndexPageTest(TestCase): 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) def tearDown(self): BlogPage.objects.all().delete() 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): 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()) def test_get_posts_returns_oldest_post_last(self): BlogPageFactory(publication_datetime=datetime(2018, 1, 1, tzinfo=pytz.UTC), parent=self.blog_index) BlogPageFactory(publication_datetime=datetime(2018, 3, 31, tzinfo=pytz.UTC), parent=self.blog_index) last = BlogPageFactory(publication_datetime=datetime(2015, 3, 31, tzinfo=pytz.UTC), parent=self.blog_index) BlogPageFactory(publication_datetime=datetime(2018, 3, 1, tzinfo=pytz.UTC), parent=self.blog_index) posts = self.blog_index.get_posts() self.assertEqual(last, posts.last())
def handle(self, *args, **options): site = Site.objects.get(site_name='SecureDrop.org (Dev)') home_page = HomePage.objects.get(slug='home') donation_url = 'https://freedom.press/crowdfunding/securedrop/' footer_settings = FooterSettings.for_site(site) footer_settings.title = RichText('SecureDrop is a project of <a href="https://freedom.press">Freedom of the Press Foundation</a>.') footer_settings.release_key = 'abcdefghijklmonopqrs' try: contribute_page = Page.objects.get(slug='contribute') except ObjectDoesNotExist: contribute_page = SimplePage(title='Contribute', slug='contribute') home_page.add_child(instance=contribute_page) footer_settings.donation_link = donation_url footer_settings.contribute_link = contribute_page footer_menu, fm_created = Menu.objects.get_or_create( name='Footer Menu', slug='footer_menu') if fm_created: if BlogIndexPage.objects.first(): blog_index_page = BlogIndexPage.objects.first() else: blog_index_page = BlogIndexPageFactory(parent=home_page) MenuItem.objects.bulk_create([ MenuItem( text='Donate', link_url=donation_url, menu=footer_menu, sort_order=1 ), MenuItem( text='Contribute Code', link_page=contribute_page, menu=footer_menu, sort_order=2 ), MenuItem( text='Get Support', link_url='#', menu=footer_menu, sort_order=3 ), MenuItem( text='Media', link_url='#', menu=footer_menu, sort_order=4, ), MenuItem( text='Privacy Policy', link_url='#', menu=footer_menu, sort_order=5, ), MenuItem( text='News', link_page=blog_index_page, menu=footer_menu, sort_order=5, ), ]) footer_settings.main_menu = footer_menu support_menu, sm_created = Menu.objects.get_or_create( name='Support Menu', slug='support_menu') if sm_created: MenuItem.objects.bulk_create([ MenuItem( text='Documentation', link_url='#', menu=support_menu, sort_order=1 ), MenuItem( text='Support Forum', link_url='#', menu=support_menu, sort_order=2 ), MenuItem( text='Guide for Journalists', link_url='#', menu=support_menu, sort_order=3 ), MenuItem( text='Guide for Administrators', link_url='#', menu=support_menu, sort_order=4, ), ]) footer_settings.support_menu = support_menu footer_settings.save()