Example #1
0
 def test_filter_by_title(self):
     page1 = EventPage(title='Cool Event')
     page2 = EventPage(title='Awesome Event')
     publish_page(page1)
     publish_page(page2)
     form = self.setUpFilterableForm(data={'title': 'Cool'})
     page_set = form.get_page_set()
     self.assertEquals(len(page_set), 1)
     self.assertEquals(page_set[0].specific, page1)
 def test_filter_by_title(self):
     page1 = EventPage(title='Cool Event',
                       start_dt=datetime.now(timezone('UTC')))
     page2 = EventPage(title='Awesome Event',
                       start_dt=datetime.now(timezone('UTC')))
     publish_page(page1)
     publish_page(page2)
     form = self.setUpFilterableForm(data={'title': 'Cool'})
     page_set = form.get_page_set()
     self.assertEqual(len(page_set), 1)
     self.assertEqual(page_set[0].specific, page1)
Example #3
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())
Example #4
0
    def setUpTestData(cls):
        cls.rebuild_elasticsearch_index('v1', stdout=StringIO())

        event = EventPage(title='test page 2',
                          start_dt=datetime.now(timezone('UTC')))
        event.tags.add('bar')
        publish_page(event)
        cls.event = event
Example #5
0
    def test_current_future_events_stay_in_place(self):
        events_page = BrowseFilterablePage(title='Events',
                                           slug='events',
                                           content='Events',
                                           live=True)
        self.root_page.add_child(instance=events_page)
        archive_page = EventArchivePage(title='Archive',
                                        slug='archive',
                                        content='archive',
                                        live=True)
        events_page.add_child(instance=archive_page)
        current_event_page = EventPage(
            title='Current event',
            start_dt=datetime.datetime(2020, 2, 1, tzinfo=pytz.UTC),
            end_dt=datetime.datetime(2020, 2, 2, tzinfo=pytz.UTC))
        events_page.add_child(instance=current_event_page)
        future_event_page = EventPage(title='Future event',
                                      start_dt=datetime.datetime(
                                          2020, 3, 1, tzinfo=pytz.UTC))
        events_page.add_child(instance=future_event_page)

        self.assertIn('No past events found to be archived.',
                      self.call_command())
Example #6
0
 def test_filter_by_tags(self):
     page1 = BlogPage(title='test page 1')
     page1.tags.add('foo')
     page2 = EventPage(title='test page 2')
     page2.tags.add('bar')
     page3 = BlogPage(title='test page 3')
     page3.tags.add('blah')
     publish_page(page1)
     publish_page(page2)
     publish_page(page3)
     form = self.setUpFilterableForm(data={'topics': ['foo', 'bar']})
     page_set_pks = form.get_page_set().values_list('pk', flat=True)
     self.assertEquals(len(page_set_pks), 2)
     self.assertIn(page1.pk, page_set_pks)
     self.assertIn(page2.pk, page_set_pks)
 def test_filter_by_tags(self):
     page1 = BlogPage(title='test page 1')
     page1.tags.add('foo')
     page2 = EventPage(title='test page 2')
     page2.tags.add('bar')
     page3 = BlogPage(title='test page 3')
     page3.tags.add('blah')
     publish_page(page1)
     publish_page(page2)
     publish_page(page3)
     form = self.setUpFilterableForm(data={'topics': ['foo', 'bar']})
     page_set = form.get_page_set()
     self.assertEquals(len(page_set), 2)
     self.assertEquals(page_set[1].specific, page1)
     self.assertEquals(page_set[0].specific, page2)
    def set_up_published_pages(self):
        page1 = BlogPage(title='test page 1')
        page1.tags.add(u'C-tag-3-instances')

        page2 = EventPage(title='test page 2',
                          start_dt=datetime.now(timezone('UTC')))
        page2.tags.add(u'B-tag-2-instances')
        page2.tags.add(u'C-tag-3-instances')

        page3 = BlogPage(title='test page 3')
        page3.tags.add(u'A-tag-1-instance')
        page3.tags.add(u'B-tag-2-instances')
        page3.tags.add(u'C-tag-3-instances')

        helpers.publish_page(page1)
        helpers.publish_page(page2)
        helpers.publish_page(page3)

        filterable_pages = AbstractFilterPage.objects.live()
        self.page_ids = filterable_pages.values_list('id', flat=True)
    def setUp(self):

        # 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')
        self.activity_log = CFGOVPage(slug='activity-log',
                                      title='activity log')

        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)
        helpers.save_new_page(self.activity_log)

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

        self.blog_child1 = BlogPage(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 = BlogPage(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 = NewsroomPage(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 = NewsroomPage(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 = EventPage(title='events child 1',
                                       date_published=dt.date(2016, 9, 7),
                                       start_dt=dt.datetime.now(
                                           timezone('UTC')))
        self.events_child1.tags.add('tag 1')

        self.events_child2 = EventPage(title='events child 2',
                                       date_published=dt.date(2016, 9, 5),
                                       start_dt=dt.datetime.now(
                                           timezone('UTC')))
        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_value = {
            'limit': 3,
            'show_heading': True,
            'header_title': 'Further reading',
            'relate_posts': False,
            'relate_newsroom': False,
            'relate_events': False,
            'specific_categories': [],
            'and_filtering': False,
        }
Example #10
0
def run():
    print 'Running script \'scripts.initial_test_data\' ...'

    admin_user = User.objects.filter(username='******')
    if not admin_user:
        admin_user = User(username='******',
                          password=make_password(
                              os.environ.get('WAGTAIL_ADMIN_PW')),
                          is_superuser=True,
                          is_active=True,
                          is_staff=True)
        admin_user.save()
    else:
        admin_user = admin_user[0]

    # # Creates a new site root `CFGov`
    site_root = HomePage.objects.filter(title='CFGOV')
    if not site_root:
        root = Page.objects.first()
        site_root = HomePage(title='CFGOV',
                             slug='home',
                             depth=2,
                             owner=admin_user)
        site_root.live = True
        root.add_child(instance=site_root)
        latest = site_root.save_revision(user=admin_user,
                                         submitted_for_moderation=False)
        latest.save()
    else:
        site_root = site_root[0]

    # Setting new site root
    site = Site.objects.first()
    if site.root_page_id != site_root.id:
        site.port = 8000
        site.root_page_id = site_root.id
        site.save()
        content_site = Site(hostname='content.localhost',
                            port=8000,
                            root_page_id=site_root.id)
        content_site.save()

    def publish_page(child=None, root=site_root):
        try:
            root.add_child(instance=child)
        except NodeAlreadySaved:
            pass
        revision = child.save_revision(
            user=admin_user,
            submitted_for_moderation=False,
        )
        revision.publish()

    # Create each Page Type
    contact = Contact.objects.filter(heading='Test User')
    if not contact:
        contact = Contact(heading='Test User')
    else:
        contact = contact[0]
    contact.contact_info = StreamValue(
        contact.contact_info.stream_block, [{
            "type": "email",
            "value": {
                "emails": [{
                    "url": "/",
                    "text": "*****@*****.**"
                }]
            }
        }, {
            "type": "phone",
            "value": {
                "phones": [{
                    "tty": "",
                    "number": "1234567890",
                    "vanity": ""
                }],
                "fax": True
            }
        }, {
            "type": "address",
            "value": {
                "city": "Washington",
                "title": "",
                "label": "Address",
                "state": "DC",
                "street": "123 abc street",
                "zip_code": "20012"
            }
        }], True)
    contact.save()

    lap = LandingPage.objects.filter(title='Landing Page')
    if not lap:
        lap = LandingPage(title='Landing Page',
                          slug='landing-page',
                          owner=admin_user)
    else:
        lap = lap[0]
    lap.content = StreamValue(lap.content.stream_block, [{
        "type": "image_text_25_75_group",
        "value": {
            "heading":
            "Image 25 75 Group",
            "image_texts": [{
                "body": "",
                "has_rule": False,
                "image": {
                    "alt": "",
                    "upload": 84
                },
                "heading": "",
                "links": [{
                    "url": "/",
                    "text": "test"
                }]
            }]
        }
    }, {
        "type": "image_text_50_50_group",
        "value": {
            "heading":
            "Image 50 50 Group",
            "image_texts": [{
                "body": "",
                "links": [{
                    "url": "/",
                    "text": "test"
                }],
                "image": {
                    "alt": "",
                    "upload": 84
                },
                "is_widescreen": False,
                "is_button": False,
                "heading": ""
            }]
        }
    }, {
        "type": "half_width_link_blob_group",
        "value": {
            "link_blobs": [{
                "body": "",
                "heading": "",
                "links": [{
                    "url": "/",
                    "text": "test"
                }]
            }],
            "heading":
            "Half Width Link Blob Group"
        }
    }], True)
    publish_page(lap)

    sp = SublandingPage.objects.filter(title='Sublanding Page')
    if not sp:
        sp = SublandingPage(title='Sublanding Page',
                            slug='sublanding-page',
                            owner=admin_user)
    else:
        sp = sp[0]
    sp.content = StreamValue(sp.content.stream_block, [{
        "type": "contact",
        "value": {
            "body": "",
            "header": "Contact",
            "contact": contact.id
        }
    }], True)
    sp.sidefoot = StreamValue(sp.sidefoot.stream_block, [{
        "type": "email_signup",
        "value": {
            "text":
            "",
            "gd_code":
            "",
            "heading":
            "Email Sign Up",
            "form_field": [{
                "info": "",
                "type": "",
                "required": False,
                "label": "Email Sign up",
                "btn_text": "",
                "placeholder": ""
            }]
        }
    }, {
        "type": "rss_feed",
        "value": "blog_feed"
    }], True)

    publish_page(sp)

    bp = BrowsePage.objects.filter(title='Browse Page')
    if not bp:
        bp = BrowsePage(title='Browse Page',
                        slug='browse-page',
                        owner=admin_user)
    else:
        bp = bp[0]
    bp.header = StreamValue(bp.header.stream_block, [{
        'type': 'featured_content',
        'value': {
            'body': "<p>this is a featured content body</p>"
        }
    }], True)
    bp.content = StreamValue(bp.content.stream_block, [{
        'type': 'expandable',
        'value': {
            'label': 'this is an expandable'
        }
    }], True)
    publish_page(bp)

    # Filterable Pages
    bfp = BrowseFilterablePage.objects.filter(title='Browse Filterable Page')
    if not bfp:
        bfp = BrowseFilterablePage(title='Browse Filterable Page',
                                   slug='browse-filterable-page',
                                   owner=admin_user)
    else:
        bfp = bfp[0]
    bfp.header = StreamValue(bfp.header.stream_block, [{
        'type': 'text_introduction',
        'value': {
            'intro': 'this is an intro'
        }
    }], True)
    publish_page(bfp)

    sfp = SublandingFilterablePage.objects.filter(
        title='Sublanding Filterable Page')
    if not sfp:
        sfp = SublandingFilterablePage(title='Sublanding Filterable Page',
                                       slug='sublanding-filterable-page',
                                       owner=admin_user)
    else:
        sfp = sfp[0]
    sfp.header = StreamValue(sfp.header.stream_block, [{
        'type': 'hero',
        'value': {
            'heading': "this is a hero heading"
        }
    }], True)
    publish_page(sfp)

    eap = EventArchivePage.objects.filter(title='Event Archive Page')
    if not eap:
        eap = EventArchivePage(title='Event Archive Page',
                               slug='event-archive-page',
                               owner=admin_user)
    else:
        eap = eap[0]
    publish_page(eap)

    nlp = NewsroomLandingPage.objects.filter(title='Newsroom Landing Page')
    if not nlp:
        nlp = NewsroomLandingPage(title='Newsroom Landing Page',
                                  slug='newsroom-landing-page',
                                  owner=admin_user)
    else:
        nlp = nlp[0]
    publish_page(nlp)

    # Filter Pages
    if not EventPage.objects.filter(title='Event Page'):
        ep = EventPage(title='Event Page', slug='event-page', owner=admin_user)
        publish_page(ep, bfp)

    ddp = DocumentDetailPage.objects.filter(title='Document Detail Page')
    if not ddp:
        ddp = DocumentDetailPage(title='Document Detail Page',
                                 slug='document-detail-page',
                                 owner=admin_user)
    else:
        ddp = ddp[0]
    ddp.sidefoot = StreamValue(ddp.sidefoot.stream_block, [{
        'type': 'related_metadata',
        'value': {
            'content': [{
                'type': 'text',
                'value': {
                    'heading': 'this is a related metadata heading'
                }
            }]
        }
    }], True)
    publish_page(ddp, bfp)

    lp = LearnPage.objects.filter(title='Learn Page')
    if not lp:
        lp = LearnPage(title='Learn Page', slug='learn-page', owner=admin_user)
    else:
        lp = lp[0]
    lp.content = StreamValue(lp.content.stream_block, [{
        'type':
        'full_width_text',
        'value': [{
            'type': 'quote',
            'value': {
                'body': 'this is a quote',
                'citation': 'a citation'
            }
        }]
    }, {
        'type': 'call_to_action',
        'value': {
            'paragraph_text': 'this is a call to action'
        }
    }], True)
    publish_page(lp, bfp)

    if not ActivityLogPage.objects.filter(title='Activity Log Page'):
        alp = ActivityLogPage(title='Activity Log Page',
                              slug='activity-log-page',
                              owner=admin_user)
        publish_page(alp)

    if not NewsroomPage.objects.filter(title='Newsroom Page'):
        np = NewsroomPage(title='Newsroom Page',
                          slug='newsroom-page',
                          owner=admin_user)
        publish_page(np, nlp)

    if not LegacyNewsroomPage.objects.filter(title='Legacy Newsroom Page'):
        lnp = LegacyNewsroomPage(title='Legacy Newsroom Page',
                                 slug='legacy-newsroom-page',
                                 owner=admin_user)
        publish_page(lnp, nlp)

    if not BlogPage.objects.filter(title='Blog Page'):
        bp = BlogPage(title='Blog Page', slug='blog-page', owner=admin_user)
        publish_page(bp, sfp)

    if not LegacyBlogPage.objects.filter(title='Legacy Blog Page'):
        lbp = LegacyBlogPage(title='Legacy Blog Page',
                             slug='legacy-blog-page',
                             owner=admin_user)
        publish_page(lbp, sfp)

    # Demo Page
    dp = DemoPage.objects.filter(title='Demo Page')
    if not dp:
        dp = DemoPage(title='Demo Page', slug='demo-page', owner=admin_user)
    else:
        dp = dp[0]
    dp.sidefoot = StreamValue(dp.sidefoot.stream_block, [{
        'type': 'related_links',
        'value': {
            'links': [{
                'url': '/url',
                'text': 'this is a related link'
            }]
        }
    }], True)
    publish_page(dp)

    # Create and configure pages for testing page states
    draft = DemoPage.objects.filter(slug='draft-page')
    if not draft:
        draft = DemoPage(title='Draft Page',
                         slug='draft-page',
                         owner=admin_user,
                         live=False,
                         shared=False)
        site_root.add_child(instance=draft)
    else:
        draft = draft[0]
    draft.save_revision(user=admin_user)

    shared = DemoPage.objects.filter(slug='shared-page')
    if not shared:
        shared = DemoPage(title='Shared Page',
                          slug='shared-page',
                          owner=admin_user,
                          live=False,
                          shared=True)
        site_root.add_child(instance=shared)
    else:
        shared = shared[0]
    shared.save_revision(user=admin_user)

    shared_draft = DemoPage.objects.filter(slug='shared-draft-page')
    if not shared_draft:
        shared_draft = DemoPage(title='Shared Page',
                                slug='shared-draft-page',
                                owner=admin_user,
                                live=False,
                                shared=True)
        site_root.add_child(instance=shared_draft)
    else:
        shared_draft = shared_draft[0]
    shared_draft.save_revision(user=admin_user)
    shared_draft.title = 'Shared Draft Page'
    shared_draft.save()
    shared_draft.save_revision(user=admin_user)

    live = DemoPage.objects.filter(slug='live-page')
    if not live:
        live = DemoPage(title='Live Page',
                        slug='live-page',
                        owner=admin_user,
                        live=True,
                        shared=True)
    else:
        live = live[0]
    publish_page(live)

    livedraft = DemoPage.objects.filter(slug='live-draft-page')
    if not livedraft:
        livedraft = DemoPage(title='Live Draft Page',
                             slug='live-draft-page',
                             owner=admin_user,
                             live=True,
                             shared=True)
    else:
        livedraft = livedraft[0]
    publish_page(livedraft)
    livedraft.live = False
    livedraft.shared = False
    livedraft.title = 'Live Page'
    livedraft.save_revision(user=admin_user)
Example #11
0
 def test_get_queryset(self):
     test_event = EventPage(title="Testing",
                            start_dt=datetime.now(timezone('UTC')))
     qs = FilterablePagesDocument().get_queryset()
     self.assertFalse(qs.filter(title=test_event.title).exists())