Пример #1
0
 def setUpTestData(cls):
     blog1 = BlogPage(title='test page')
     blog1.categories.add(CFGOVPageCategory(name='foo'))
     blog1.categories.add(CFGOVPageCategory(name='bar'))
     blog1.tags.add('foo')
     blog1.authors.add('richa-agarwal')
     blog1.authors.add('sarah-simpson')
     blog2 = BlogPage(title='another test page')
     blog2.categories.add(CFGOVPageCategory(name='bar'))
     blog2.tags.add('blah')
     blog2.authors.add('richard-cordray')
     event1 = EventPage(title='test page 2',
                        start_dt=datetime.now(timezone('UTC')))
     event1.tags.add('bar')
     cool_event = EventPage(title='Cool Event',
                            start_dt=datetime.now(timezone('UTC')))
     awesome_event = EventPage(title='Awesome Event',
                               start_dt=datetime.now(timezone('UTC')))
     publish_page(blog1)
     publish_page(blog2)
     publish_page(event1)
     publish_page(cool_event)
     publish_page(awesome_event)
     cls.blog1 = blog1
     cls.blog2 = blog2
     cls.event1 = event1
     cls.cool_event = cool_event
     cls.awesome_event = awesome_event
Пример #2
0
    def setUpTestData(cls):
        blog1 = BlogPage(title='test page')
        blog1.categories.add(CFGOVPageCategory(name='foo'))
        blog1.categories.add(CFGOVPageCategory(name='bar'))
        blog1.tags.add('foo')
        blog1.authors.add('richa-agarwal')
        blog1.authors.add('sarah-simpson')
        blog2 = BlogPage(title='another test page')
        blog2.categories.add(CFGOVPageCategory(name='bar'))
        blog2.tags.add('blah')
        blog2.authors.add('richard-cordray')
        category_blog = BlogPage(title='Category Test')
        category_blog.categories.add(
            CFGOVPageCategory(name='info-for-consumers'))
        event1 = EventPage(title='test page 2',
                           start_dt=datetime.now(timezone('UTC')))
        event1.tags.add('bar')
        cool_event = EventPage(title='Cool Event',
                               start_dt=datetime.now(timezone('UTC')))
        awesome_event = EventPage(title='Awesome Event',
                                  start_dt=datetime.now(timezone('UTC')))
        publish_page(blog1)
        publish_page(blog2)
        publish_page(event1)
        publish_page(cool_event)
        publish_page(awesome_event)
        publish_page(category_blog)
        cls.blog1 = blog1
        cls.blog2 = blog2
        cls.event1 = event1
        cls.cool_event = cool_event
        cls.awesome_event = awesome_event
        cls.category_blog = category_blog

        cls.rebuild_elasticsearch_index('v1', stdout=StringIO())
Пример #3
0
    def test_get_latest_activities_returns_activities_sorted(self):
        hostname = Site.objects.get(is_default_site=True).hostname
        page1 = BlogPage(title='oldest page',
                         date_published=datetime.date(2015, 9, 3))
        # Give it a newsroom subcategory
        page1.categories.add(CFGOVPageCategory(name='press-release'))
        publish_page(page1)

        page2 = BlogPage(title='second page',
                         date_published=datetime.date(2016, 5, 3))
        # Give it a newsroom subcategory
        page2.categories.add(CFGOVPageCategory(name='speech'))
        publish_page(page2)

        page3 = BlogPage(title='most recent page')
        # Give it a newsroom subcategory
        page3.categories.add(CFGOVPageCategory(name='testimony'))
        publish_page(page3)

        activities = activity_feed.get_latest_activities(
            activity_type='newsroom', hostname=hostname)
        self.assertEquals(len(activities), 3)
        self.assertEquals(activities[0].specific, page3)
        self.assertEquals(activities[1].specific, page2)
        self.assertEquals(activities[2].specific, page1)
 def test_filter_by_category(self):
     page1 = BlogPage(title='test page')
     page1.categories.add(CFGOVPageCategory(name='foo'))
     page1.categories.add(CFGOVPageCategory(name='bar'))
     page2 = BlogPage(title='another test page')
     page2.categories.add(CFGOVPageCategory(name='bar'))
     publish_page(page1)
     publish_page(page2)
     form = self.setUpFilterableForm(data={'categories': ['foo']})
     page_set = form.get_page_set()
     self.assertEquals(len(page_set), 1)
     self.assertEquals(page_set[0].specific, page1)
Пример #5
0
    def setUpTestData(cls):
        cls.site = Site.objects.get(is_default_site=True)
        event = EventPage(title='Event Test',
                          start_dt=datetime(2021,
                                            2,
                                            16,
                                            tzinfo=timezone('UTC')),
                          end_dt=datetime(2021, 2, 16, tzinfo=timezone('UTC')))
        event.tags.add('test-topic')
        event.categories.add(CFGOVPageCategory(name='test-category'))
        event.authors.add('test-author')
        publish_page(event)
        enforcement = EnforcementActionPage(
            title="Great Test Page",
            preview_description='This is a great test page.',
            initial_filing_date=datetime.now(timezone('UTC')))
        status = EnforcementActionStatus(status='expired-terminated-dismissed')
        enforcement.statuses.add(status)
        product = EnforcementActionProduct(product='Debt Collection')
        enforcement.products.add(product)
        publish_page(enforcement)
        blog = BlogPage(title="Blog Page")
        publish_page(blog)
        cls.event = event
        cls.enforcement = enforcement
        cls.blog = blog

        cls.rebuild_elasticsearch_index('v1', stdout=StringIO())
Пример #6
0
    def test_get_latest_activities_returns_relevant_activities(self):
        page1 = BlogPage(title='test page')
        # Give it a blog subcategory
        page1.categories.add(CFGOVPageCategory(name='at-the-cfpb'))
        publish_page(page1)

        page2 = BlogPage(title='another test page')
        # Don't give it a blog subcategory
        publish_page(page2)

        activities = activity_feed.get_latest_activities(activity_type='blog')
        self.assertEquals(len(activities), 1)
        self.assertEquals(activities[0].specific, page1)
Пример #7
0
    def setUp(self):

        self.hostname = 'localhost'

        # add some authors to a CFGOV page and give it some tags

        self.author1 = 'Some Author'
        self.author2 = 'Another Person'
        self.author3 = 'A Third Author'
        self.page_with_authors = CFGOVPage(title='a cfgov page with authors')
        helpers.save_new_page(self.page_with_authors)

        self.page_with_authors.authors.add(self.author1)
        self.page_with_authors.authors.add(self.author2)
        self.page_with_authors.authors.add(self.author3)

        self.page_with_authors.tags.add('tag 1')
        self.page_with_authors.tags.add('tag 2')

        # set up parent pages for the different types of related
        # posts we can have

        self.blog_parent = CFGOVPage(slug='blog', title='blog parent')
        self.newsroom_parent = CFGOVPage(slug='newsroom', title='newsroom parent')
        self.events_parent = CFGOVPage(slug='events', title='events parent')
        self.archive_events_parent = CFGOVPage(slug='archive-past-events', title='archive past events parent')

        helpers.save_new_page(self.blog_parent)
        helpers.save_new_page(self.newsroom_parent)
        helpers.save_new_page(self.events_parent)
        helpers.save_new_page(self.archive_events_parent)

        # set up children of the parent pages and give them some tags
        # and some categories

        self.blog_child1 = AbstractFilterPage(title='blog child 1', date_published=dt.date(2016, 9, 1))
        self.blog_child1.tags.add('tag 1')
        self.blog_child1.categories.add(CFGOVPageCategory(name='info-for-consumers'))

        self.blog_child2 = AbstractFilterPage(title='blog child 2', date_published=dt.date(2016, 9, 2))
        self.blog_child2.tags.add('tag 2')
        self.blog_child2.categories.add(CFGOVPageCategory(name='policy_compliance'))

        self.newsroom_child1 = AbstractFilterPage(title='newsroom child 1', date_published=dt.date(2016, 9, 2))
        self.newsroom_child1.tags.add('tag 1')
        self.newsroom_child1.tags.add('tag 2')
        self.newsroom_child1.categories.add(CFGOVPageCategory(name='op-ed'))

        self.newsroom_child2 = AbstractFilterPage(title='newsroom child 2', date_published=dt.date(2016, 9, 3))
        self.newsroom_child2.tags.add('tag 2')
        self.newsroom_child2.categories.add(CFGOVPageCategory(name='some-other-category'))

        self.events_child1 = AbstractFilterPage(title='events child 1', date_published=dt.date(2016, 9, 7))
        self.events_child1.tags.add('tag 1')

        self.events_child2 = AbstractFilterPage(title='events child 2', date_published=dt.date(2016, 9, 5))
        self.events_child2.tags.add('tag 2')

        helpers.save_new_page(self.blog_child1, self.blog_parent)
        helpers.save_new_page(self.blog_child2, self.blog_parent)
        helpers.save_new_page(self.newsroom_child1, self.newsroom_parent)
        helpers.save_new_page(self.newsroom_child2, self.newsroom_parent)
        helpers.save_new_page(self.events_child1, self.events_parent)

        # mock a stream block that dictates how to retrieve the related posts
        # note that because of the way that the related_posts_category_lookup function
        # works i.e. by consulting a hard-coded object, the specific_categories
        # slot of the dict has to be something that it can actually find.

        self.block = mock.MagicMock()
        self.block.block_type = 'related_posts'
        self.block.value = dict({
            'limit': 3,
            'show_heading': True,
            'header_title': 'Further reading',
            'relate_posts': False,
            'relate_newsroom': False,
            'relate_events': False,
            'specific_categories': []
        })