Example #1
0
 def test_ready_to_send(self):
     story1 = create_story(title="Test Story 1",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     story2 = create_story(title="Test Story 2",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     story3 = create_story(title="Test Story 3",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     notification1 = StoryNotification.objects.get(story=story1)
     notification2 = StoryNotification.objects.get(story=story2)
     notification3 = StoryNotification.objects.get(story=story3)
     send_on = notification2.send_on
     ready_qs = StoryNotificationQuerySet(
         model=StoryNotification).ready_to_send(send_on)
     self.assertEqual(ready_qs.count(), 2)
     self.assertIn(notification1, ready_qs)
     self.assertIn(notification2, ready_qs)
     ready_qs = StoryNotificationQuerySet(
         model=StoryNotification).ready_to_send()
     self.assertEqual(ready_qs.count(), 0)
Example #2
0
    def test_ordered_stories_by_weight(self):
        """ Tests that ordered_stories will order first by weight """
        name = "The Metro Denver Regional Equity Atlas"
        description = """
            The Denver Regional Equity Atlas is a product of Mile High
            Connects (MHC), which came together in 2011 to ensure that 
            the region\'s significant investment in new rail and bus
            service will provide greater access to opportunity and a
            higher quality of life for all of the region\'s residents, but
            especially for economically disadvantaged populations who
            would benefit the most from safe, convenient transit service.

            The Atlas visually documents the Metro Denver region\'s
            demographic, educational, employment, health and housing
            characteristics in relation to transit, with the goal of
            identifying areas of opportunity as well as challenges to
            creating and preserving quality communities near transit.
            """
        project = create_project(name=name, description=description)
        story1 = create_story(title='Story 1', summary='', byline='')
        story2 = create_story(title='Story 2', summary='', byline='')
        project.add_story(story1, 5)
        sleep(2)
        project.add_story(story2, 25)
        stories = project.ordered_stories()
        self.assertEqual(stories.count(), 2)
        self.assertEqual(stories[0], story1)
        self.assertEqual(stories[1], story2)
Example #3
0
    def test_send_emails(self):
        self.check_backend()

        story1 = create_story(title="Test Story 1", summary="Test Summary",
                                  byline="Test Byline", status='draft',
                                  author=self.user)
        story2 = create_story(title="Test Story 2", summary="Test Summary",
                                  byline="Test Byline", status='draft',
                                  author=self.user)
        story3 = create_story(title="Test Story 3", summary="Test Summary",
                                  byline="Test Byline", status='draft',
                                  author=self.user)
        story1.status = 'published'
        story2.status = 'published'
        story1.save()
        story2.save()
        # At this point there should be two "unpublished" notifications ready
        # to be sent.
        StoryNotification.objects.send_emails()
        self.assertEqual(len(self.get_sent_emails()), 2)
        self.assertInSentSubjects(story1.title)
        self.assertInSentSubjects(story2.title)
        # Now there should be no notifications ready to send
        self.assertEqual(StoryNotification.objects.all().ready_to_send().count(), 0)
        # The notification items we sent should have their ``sent``
        # timestamp set
        self.assertNotEqual(StoryNotification.objects.get(
            story=story1, notification_type='published').sent,
            None)
        self.assertNotEqual(StoryNotification.objects.get(
            story=story2, notification_type='published').sent,
            None)
Example #4
0
 def test_get_context(self):
     story1 = create_story(title="test story 1",
                           summary="test summary",
                           byline="test byline",
                           status='draft',
                           author=self.user)
     story2 = create_story(title="test story 2",
                           summary="test summary",
                           byline="test byline",
                           status='draft',
                           author=self.user)
     story3 = create_story(title="test story 3",
                           summary="test summary",
                           byline="test byline",
                           status='published',
                           author=self.user)
     notification = StoryNotification.objects.get(
         story=story2, notification_type='unpublished')
     # StoryNotification._common_context is cached per-thread. Clobber
     # it so we get fresh values
     StoryNotification._common_context = None
     context = notification.get_context()
     self.assertEqual(context['story'], story2)
     self.assertIn(story1, context['unpublished_stories'])
     self.assertIn(story3, context['recent_stories'])
Example #5
0
 def test_ordered_stories_by_weight(self):
     """ Tests that ordered_stories will order first by weight """
     organization = create_organization(name='Mile High Connects')
     story1 = create_story(title='Story 1', summary='', byline='')
     story2 = create_story(title='Story 2', summary='', byline='')
     organization.add_story(story1, 5)
     sleep(2)
     organization.add_story(story2, 25)
     stories = organization.ordered_stories()
     self.assertEqual(stories.count(), 2)
     self.assertEqual(stories[0], story1)
     self.assertEqual(stories[1], story2)
Example #6
0
 def test_emails(self):
     story1 = create_story(title="Test Story 1", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     story2 = create_story(title="Test Story 2", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     story3 = create_story(title="Test Story 3", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     qs = StoryNotificationQuerySet(model=StoryNotification)
     emails = qs.order_by('story__created').emails()
     self.assertEqual(len(emails), 3)
     self.assertIn(story1.title, emails[1].body)
def setup(scenario):
    matching_scenarios = ('Associate multiple stories to a project',)
    if scenario.name in matching_scenarios: 
        create_project('The Metro Denver Regional Equity Atlas')
        story_summary = """
            Many families in the Denver metro area use public
            transportation instead of a school bus because for them, a
            quality education is worth hours of daily commuting. Colorado's
            school choice program is meant to foster educational equity,
            but the families who benefit most are those who have time and
            money to travel. Low-income families are often left in a lurch.
            """
        create_story(title='Transportation Challenges Limit Education Choices for Denver Parents', summary=story_summary)
        create_story(title='Connecting the Dots Between Transit And Other Regional Priorities')
Example #8
0
    def test_get_list_for_section(self):
        section_help = create_help(title="Test section help item",
                                   body="Test section help item body")
        nonsection_help = create_help(title="Test non-section help item",
                                      body="Test non-section help item body",
                                      slug='test-nonsection')
        story = create_story(title="Test Story",
                             summary="Test Summary",
                             byline="Test Byline",
                             status="published",
                             language="en")
        section = create_section(title="Test Section 1",
                                 story=story,
                                 help=section_help)

        uri = '/api/0.1/help/sections/%s/' % (section.section_id)
        resp = self.api_client.get(uri)
        self.assertValidJSONResponse(resp)
        self.assertEqual(len(self.deserialize(resp)['objects']), 1)
        self.assertEqual(
            self.deserialize(resp)['objects'][0]['title'],
            "Test section help item")
        self.assertEqual(
            self.deserialize(resp)['objects'][0]['body'],
            "Test section help item body")
Example #9
0
 def test_featured_items(self):
     image_filename = "test_image.jpg"
     app_dir = os.path.dirname(os.path.abspath(__file__))
     img_path = os.path.join(app_dir, "test_files", image_filename)
     with open(img_path) as image:
         # Create news item
         news_item = create_news_item(title="Test News Item",
                 body="<p>This is a test news item</p>",
                 image=image,
                 image_filename=image_filename,
                 status='published',
                 on_homepage=True,
                 author=self.admin_user)
         self.add_file_to_cleanup(news_item.image.file.path)
     story = create_story(title="Test Story",
             summary="Test story summary", byline="Test byline",
             status='published', author=self.user1,
             on_homepage=True)
     project = create_project(name="Test Project",
             description='Test project description',
             status='published',
             on_homepage=True)
     t = Template("{% load storybase_featured %}{% featured_items %}")
     c = Context()
     rendered = t.render(c)
     # Check that item titles are present
     self.assertIn(story.title, rendered)
     self.assertIn(news_item.title, rendered)
     self.assertIn(project.name, rendered)
     # Check ordering of items is Story, News, Project
     self.assertTrue(rendered.find(story.title) < rendered.find(news_item.title))
     self.assertTrue(rendered.find(news_item.title) < rendered.find(project.name))
Example #10
0
def create_connected_story_template():
    """
    Create the connected stories template

    This is essentially a programatic fixture for creating the 
    connected story template
    """
    story = create_story(title="Connected Story Template",
                         language="en",
                         status="published",
                         is_template=True)
    layout = SectionLayout.objects.get(
        sectionlayouttranslation__name="Side by Side")
    section = create_section(title="Photo and Image",
                             language="en",
                             story=story,
                             layout=layout)
    asset1 = create_external_asset(title="Mock Image Asset",
                                   type='image',
                                   url='http://exampledomain.com/fake.png')
    asset2 = create_html_asset(title="Mock Text Asset", type='text')
    left = Container.objects.get(name='left')
    right = Container.objects.get(name='right')
    SectionAsset.objects.create(section=section, asset=asset1, container=left)
    SectionAsset.objects.create(section=section, asset=asset2, container=right)
    return create_story_template(
        title="Connected Story",
        story=story,
        slug=settings.STORYBASE_CONNECTED_STORY_TEMPLATE)
Example #11
0
 def setUp(self):
     super(LocationResourceTest, self).setUp()
     self.ap_client = TestApiClient()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, '*****@*****.**',
                                          self.password)
     self.user2 = User.objects.create_user("test2", "*****@*****.**",
                                           "test2")
     self.story = create_story(title="Test Story",
                               summary="Test Summary",
                               byline="Test Byline",
                               status="published",
                               language="en",
                               author=self.user)
     self.location_attrs = [{
         "name": "The Piton Foundation",
         "address": "370 17th St",
         "address2": "#5300",
         "city": "Denver",
         "state": "CO",
         "postcode": "80202",
     }, {
         'name': "The Hull House",
         'address': "800 S. Halsted St.",
         "city": "Chicago",
         "state": "IL",
         "postcode": "60607",
     }, {
         'name': "Bucktown-Wicker Park Library",
         'address': "1701 North Milwaukee Ave.",
         'city': "Chicago",
         'state': "IL",
         'postcode': "60647",
     }]
Example #12
0
 def setUp(self):
     super(TagResourceTest, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, '*****@*****.**',
                                          self.password)
     self.user2 = User.objects.create_user("test2", "*****@*****.**",
                                           "test2")
     self.story = create_story(title="Test Story",
                               summary="Test Summary",
                               byline="Test Byline",
                               status="published",
                               language="en",
                               author=self.user)
     self.tag_attrs = [
         {
             'name': 'Schools'
         },
         {
             'name': 'Housing'
         },
         {
             'name': 'education'
         },
         {
             'name': 'neighborhood'
         },
         {
             'name': 'food'
         },
     ]
Example #13
0
    def test_add_story(self):
        name = "The Metro Denver Regional Equity Atlas"
        description = """
            The Denver Regional Equity Atlas is a product of Mile High
            Connects (MHC), which came together in 2011 to ensure that 
            the region\'s significant investment in new rail and bus
            service will provide greater access to opportunity and a
            higher quality of life for all of the region\'s residents, but
            especially for economically disadvantaged populations who
            would benefit the most from safe, convenient transit service.

            The Atlas visually documents the Metro Denver region\'s
            demographic, educational, employment, health and housing
            characteristics in relation to transit, with the goal of
            identifying areas of opportunity as well as challenges to
            creating and preserving quality communities near transit.
            """
        project = create_project(name=name, description=description)
        title = "Transportation Challenges Limit Education Choices for Denver Parents"
        summary = """
            Many families in the Denver metro area use public
            transportation instead of a school bus because for them, a
            quality education is worth hours of daily commuting. Colorado's
            school choice program is meant to foster educational equity,
            but the families who benefit most are those who have time and
            money to travel. Low-income families are often left in a lurch.
            """
        byline = "Mile High Connects"
        story = create_story(title=title, summary=summary, byline=byline)
        weight = 15
        project.add_story(story, weight) 
        self.assertTrue(story in project.curated_stories.all())
        ProjectStory.objects.get(project=project, story=story,
                                 weight=weight)
Example #14
0
    def test_featured_items_preview(self):
        image_filename = "test_image.jpg"
        app_dir = os.path.dirname(os.path.abspath(__file__))
        img_path = os.path.join(app_dir, "test_files", image_filename)
        with open(img_path) as image:
            # Create a staged news item
            news_item = create_news_item(title="Test News Item",
                    body="<p>This is a test news item</p>",
                    image=image,
                    image_filename=image_filename,
                    status='staged',
                    on_homepage=True,
                    author=self.admin_user)
            self.add_file_to_cleanup(news_item.image.file.path)
        story = create_story(title="Test Story",
                summary="Test story summary", byline="Test byline",
                status='published', author=self.user1,
                on_homepage=True)
        project = create_project(name="Test Project",
                description='Test project description',
                status='published',
                on_homepage=True)
        t = Template("{% load storybase_featured %}{% featured_items %}")

        # Check that the news item isn't present for an anonymous user
        c = Context({
            'user': self.anonymous_user,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertNotIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item isn't present for a normal user 
        c = Context({
            'user': self.user1,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertNotIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item is present for an admin user
        c = Context({
            'user': self.admin_user,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item is present for a super user
        c = Context({
            'user': self.superuser,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)
Example #15
0
 def test_get_context(self):
     story1 = create_story(title="test story 1", summary="test summary",
                               byline="test byline", status='draft',
                               author=self.user)
     story2 = create_story(title="test story 2", summary="test summary",
                               byline="test byline", status='draft',
                               author=self.user)
     story3 = create_story(title="test story 3", summary="test summary",
                               byline="test byline", status='published',
                               author=self.user)
     notification = StoryNotification.objects.get(story=story2, notification_type='unpublished')
     # StoryNotification._common_context is cached per-thread. Clobber
     # it so we get fresh values
     StoryNotification._common_context = None
     context = notification.get_context()
     self.assertEqual(context['story'], story2)
     self.assertIn(story1, context['unpublished_stories'])
     self.assertIn(story3, context['recent_stories'])
Example #16
0
 def test_unpublished_notification_send_on_updated(self):
     """Test that the send_on date is updated when a story is re-saved"""
     story = create_story(title="Test Story", summary="Test Summary",
                          byline="Test Byline", status='draft',
                          author=self.user)
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     original_send_on = notification.send_on
     story.save()
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     self.assertTrue(original_send_on < notification.send_on)
Example #17
0
 def test_get_body_template(self):
     """Test loading body template for a specific story notification message"""
     story = create_story(title="Test Story", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     try:
         notification.get_body_template("text")
     except TemplateDoesNotExist:
         self.fail("Template not returned")
Example #18
0
 def test_ready_to_send(self):
     story1 = create_story(title="Test Story 1", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     story2 = create_story(title="Test Story 2", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     story3 = create_story(title="Test Story 3", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     notification1 = StoryNotification.objects.get(story=story1)
     notification2 = StoryNotification.objects.get(story=story2)
     notification3 = StoryNotification.objects.get(story=story3)
     send_on = notification2.send_on
     ready_qs = StoryNotificationQuerySet(model=StoryNotification).ready_to_send(send_on)
     self.assertEqual(ready_qs.count(), 2)
     self.assertIn(notification1, ready_qs)
     self.assertIn(notification2, ready_qs)
     ready_qs = StoryNotificationQuerySet(model=StoryNotification).ready_to_send()
     self.assertEqual(ready_qs.count(), 0)
Example #19
0
 def test_emails(self):
     story1 = create_story(title="Test Story 1",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     story2 = create_story(title="Test Story 2",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     story3 = create_story(title="Test Story 3",
                           summary="Test Summary",
                           byline="Test Byline",
                           status='draft',
                           author=self.user)
     qs = StoryNotificationQuerySet(model=StoryNotification)
     emails = qs.order_by('story__created').emails()
     self.assertEqual(len(emails), 3)
     self.assertIn(story1.title, emails[1].body)
Example #20
0
    def test_unpublished_notification_created(self):
        """Test that a notification model instance is created when a story is saved"""
        story = create_story(title="Test Story", summary="Test Summary",
                                  byline="Test Byline", status='draft',
                                  author=self.user)

        five_days = timedelta(days=5)
        send_on = datetime.now() + five_days 
        notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
        self.assertEqual(notification.sent, None)
        self.assertTimesEqualish(notification.send_on, send_on)
Example #21
0
 def test_unpublished_notification_deleted_on_publish(self):
     """
     Test that any unsent notification is deleted when the story is 
     published
     """
     story = create_story(title="Test Story", summary="Test Summary",
                          byline="Test Byline", status='draft',
                          author=self.user)
     story.status = 'published'
     story.save()
     self.assertEqual(StoryNotification.objects.filter(story=story, notification_type='unpublished').count(), 0)
Example #22
0
    def test_send_emails(self):
        self.check_backend()

        story1 = create_story(title="Test Story 1",
                              summary="Test Summary",
                              byline="Test Byline",
                              status='draft',
                              author=self.user)
        story2 = create_story(title="Test Story 2",
                              summary="Test Summary",
                              byline="Test Byline",
                              status='draft',
                              author=self.user)
        story3 = create_story(title="Test Story 3",
                              summary="Test Summary",
                              byline="Test Byline",
                              status='draft',
                              author=self.user)
        story1.status = 'published'
        story2.status = 'published'
        story1.save()
        story2.save()
        # At this point there should be two "unpublished" notifications ready
        # to be sent.
        StoryNotification.objects.send_emails()
        self.assertEqual(len(self.get_sent_emails()), 2)
        self.assertInSentSubjects(story1.title)
        self.assertInSentSubjects(story2.title)
        # Now there should be no notifications ready to send
        self.assertEqual(
            StoryNotification.objects.all().ready_to_send().count(), 0)
        # The notification items we sent should have their ``sent``
        # timestamp set
        self.assertNotEqual(
            StoryNotification.objects.get(story=story1,
                                          notification_type='published').sent,
            None)
        self.assertNotEqual(
            StoryNotification.objects.get(story=story2,
                                          notification_type='published').sent,
            None)
Example #23
0
def get_or_create_story(title, username=None, **extra_create_kwargs):
    lookup_kwargs = {
        'storytranslation_title': title,
    }

    create_kwargs = {
        'title': title,
    }

    if username:
        user = User.objects.get(username=username)
        lookup_kwargs['author'] = user
        create_kwargs['author'] = user
    else:
        user = None

    try:
        Story.objects.get(**lookup_kwargs)
    except Story.DoesNotExist:
        create_kwargs.update(extra_create_kwargs)
        create_story(**create_kwargs)
Example #24
0
def get_or_create_story(title, username=None, **extra_create_kwargs):
    lookup_kwargs = {
        'storytranslation_title': title,
    }

    create_kwargs = {
        'title': title,
    }

    if username:
        user = User.objects.get(username=username)
        lookup_kwargs['author'] = user
        create_kwargs['author'] = user
    else:
        user = None

    try:
        Story.objects.get(**lookup_kwargs)
    except Story.DoesNotExist:
        create_kwargs.update(extra_create_kwargs)
        create_story(**create_kwargs)
Example #25
0
 def test_get_language_choices(self):
     """Test retrieving languages for message templates"""
     expected_language = "en-us"
     expected_languages = [expected_language]
     if settings.LANGUAGE_CODE != expected_language:
         expected_languages.append(settings.LANGUAGE_CODE)
     story = create_story(title="Test Story", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     activate(expected_language)
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     self.assertEqual(notification.get_language_choices(), expected_languages)
Example #26
0
 def test_get_subject_template(self):
     """Test loading subject template for a specific story notification message"""
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     try:
         notification.get_subject_template()
     except TemplateDoesNotExist:
         self.fail("Template not returned")
Example #27
0
 def test_get_text_content(self):
     story = create_story(title="Test Story", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     # The template text is likely to change, so to make the tests
     # flexible, just check that the content is nonempty 
     content = notification.get_text_content()
     self.assertNotEqual(content, "")
     story.status = 'published'
     story.save()
     notification = StoryNotification.objects.get(story=story, notification_type='published')
     content = notification.get_text_content()
     self.assertNotEqual(content, "")
Example #28
0
 def test_unpublished_notification_send_on_updated(self):
     """Test that the send_on date is updated when a story is re-saved"""
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     original_send_on = notification.send_on
     story.save()
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     self.assertTrue(original_send_on < notification.send_on)
Example #29
0
    def test_unpublished_notification_created(self):
        """Test that a notification model instance is created when a story is saved"""
        story = create_story(title="Test Story",
                             summary="Test Summary",
                             byline="Test Byline",
                             status='draft',
                             author=self.user)

        five_days = timedelta(days=5)
        send_on = datetime.now() + five_days
        notification = StoryNotification.objects.get(
            story=story, notification_type='unpublished')
        self.assertEqual(notification.sent, None)
        self.assertTimesEqualish(notification.send_on, send_on)
Example #30
0
 def test_get_subject(self):
     story = create_story(title="Test Story", summary="Test Summary",
                               byline="Test Byline", status='draft',
                               author=self.user)
     notification = StoryNotification.objects.get(story=story, notification_type='unpublished')
     # The template text is likely to change, so to make the tests
     # flexible, check for the key elements instead of matching entire strings
     # For the unpublished notification, make sure the subject is nonempty
     self.assertNotEqual(notification.get_subject(), "")
     story.status = 'published'
     story.save()
     notification = StoryNotification.objects.get(story=story, notification_type='published')
     # For the published notification, make sure the story title is in the subject
     self.assertIn(story.title, notification.get_subject())
Example #31
0
 def test_no_publish_button_for_never_published(self):
     """
     Test that no publish button shows up when a story has never been
     published.
     """
     story = create_story(title='Story 1', summary='', byline='',
             author=self.user)
     publish_url = urlresolvers.reverse('story_publish', kwargs={
         'slug': story.slug }) 
     unpublish_url = urlresolvers.reverse('story_unpublish', kwargs={
         'slug': story.slug }) 
     resp = self.client.get(self.path)
     self.assertNotIn(unpublish_url, resp.content)
     self.assertNotIn(publish_url, resp.content)
Example #32
0
 def test_unpublished_notification_deleted_on_publish(self):
     """
     Test that any unsent notification is deleted when the story is 
     published
     """
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     story.status = 'published'
     story.save()
     self.assertEqual(
         StoryNotification.objects.filter(
             story=story, notification_type='unpublished').count(), 0)
Example #33
0
 def test_unpublished_button_for_published(self):
     """
     Test that an unpublish button is available for published stories
     """
     story = create_story(title='Story 1', summary='', byline='',
             author=self.user)
     story.status = 'published'
     story.save()
     publish_url = urlresolvers.reverse('story_publish', kwargs={
         'slug': story.slug }) 
     unpublish_url = urlresolvers.reverse('story_unpublish', kwargs={
         'slug': story.slug }) 
     resp = self.client.get(self.path)
     self.assertNotIn(publish_url, resp.content)
     self.assertIn(unpublish_url, resp.content)
Example #34
0
 def test_get_language_choices(self):
     """Test retrieving languages for message templates"""
     expected_language = "en-us"
     expected_languages = [expected_language]
     if settings.LANGUAGE_CODE != expected_language:
         expected_languages.append(settings.LANGUAGE_CODE)
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     activate(expected_language)
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     self.assertEqual(notification.get_language_choices(),
                      expected_languages)
Example #35
0
    def test_get_list_for_section(self):
        section_help = create_help(title="Test section help item", body="Test section help item body")
        nonsection_help = create_help(
            title="Test non-section help item", body="Test non-section help item body", slug="test-nonsection"
        )
        story = create_story(
            title="Test Story", summary="Test Summary", byline="Test Byline", status="published", language="en"
        )
        section = create_section(title="Test Section 1", story=story, help=section_help)

        uri = "/api/0.1/help/sections/%s/" % (section.section_id)
        resp = self.api_client.get(uri)
        self.assertValidJSONResponse(resp)
        self.assertEqual(len(self.deserialize(resp)["objects"]), 1)
        self.assertEqual(self.deserialize(resp)["objects"][0]["title"], "Test section help item")
        self.assertEqual(self.deserialize(resp)["objects"][0]["body"], "Test section help item body")
Example #36
0
 def test_communication_preferences_honored(self):
     """
     Test that a user's communication preferences are honored and
     a notification is not created if a user turns them off
     """
     profile = self.user.get_profile()
     profile.notify_story_unpublished = False
     profile.notify_story_published = False
     profile.save()
     story = create_story(title="Test Story", summary="Test Summary",
                          byline="Test Byline", status='draft',
                          author=self.user)
     self.assertEqual(StoryNotification.objects.count(), 0)
     story.status = 'published'
     story.save()
     self.assertEqual(StoryNotification.objects.count(), 0)
Example #37
0
 def test_publish_button_for_once_published(self):
     """
     Test that a publish button appears when a story was published
     at one time, but is now unpublished.
     """
     story = create_story(title='Story 1', summary='', byline='',
             author=self.user)
     story.status = 'published'
     story.save()
     story.status = 'draft'
     story.save()
     publish_url = urlresolvers.reverse('story_publish', kwargs={
         'slug': story.slug }) 
     unpublish_url = urlresolvers.reverse('story_unpublish', kwargs={
         'slug': story.slug }) 
     resp = self.client.get(self.path)
     self.assertNotIn(unpublish_url, resp.content)
     self.assertIn(publish_url, resp.content)
Example #38
0
 def setUp(self):
     super(TagResourceTest, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, 
         '*****@*****.**', self.password)
     self.user2 = User.objects.create_user("test2", "*****@*****.**",
                                           "test2")
     self.story = create_story(title="Test Story", summary="Test Summary",
         byline="Test Byline", status="published", language="en", 
         author=self.user)
     self.tag_attrs = [
         { 'name': 'Schools' },
         { 'name': 'Housing' },
         { 'name': 'education' },
         { 'name': 'neighborhood' },
         { 'name': 'food' },
     ]
Example #39
0
 def test_add_story(self):
     organization = create_organization(name='Mile High Connects')
     title = "Transportation Challenges Limit Education Choices for Denver Parents"
     summary = """
         Many families in the Denver metro area use public
         transportation instead of a school bus because for them, a
         quality education is worth hours of daily commuting. Colorado's
         school choice program is meant to foster educational equity,
         but the families who benefit most are those who have time and
         money to travel. Low-income families are often left in a lurch.
         """
     byline = "Mile High Connects"
     story = create_story(title=title, summary=summary, byline=byline)
     weight = 15
     organization.add_story(story, weight) 
     self.assertTrue(story in organization.curated_stories.all())
     OrganizationStory.objects.get(organization=organization, story=story,
                              weight=weight)
Example #40
0
 def test_get_subject(self):
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     # The template text is likely to change, so to make the tests
     # flexible, check for the key elements instead of matching entire strings
     # For the unpublished notification, make sure the subject is nonempty
     self.assertNotEqual(notification.get_subject(), "")
     story.status = 'published'
     story.save()
     notification = StoryNotification.objects.get(
         story=story, notification_type='published')
     # For the published notification, make sure the story title is in the subject
     self.assertIn(story.title, notification.get_subject())
Example #41
0
 def test_get_text_content(self):
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     notification = StoryNotification.objects.get(
         story=story, notification_type='unpublished')
     # The template text is likely to change, so to make the tests
     # flexible, just check that the content is nonempty
     content = notification.get_text_content()
     self.assertNotEqual(content, "")
     story.status = 'published'
     story.save()
     notification = StoryNotification.objects.get(
         story=story, notification_type='published')
     content = notification.get_text_content()
     self.assertNotEqual(content, "")
Example #42
0
 def test_communication_preferences_honored(self):
     """
     Test that a user's communication preferences are honored and
     a notification is not created if a user turns them off
     """
     profile = self.user.get_profile()
     profile.notify_story_unpublished = False
     profile.notify_story_published = False
     profile.save()
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status='draft',
                          author=self.user)
     self.assertEqual(StoryNotification.objects.count(), 0)
     story.status = 'published'
     story.save()
     self.assertEqual(StoryNotification.objects.count(), 0)
Example #43
0
 def test_post_list_for_section_unauthorized_unauthenticated(self):
     """
     Test that anonymous users cannot set the help item for a section
     """
     section_help = create_help(title="Test section help item",
                                body="Test section help item body")
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status="published",
                          language="en",
                          author=self.user)
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {'help_id': section_help.help_id}
     uri = '/api/0.1/help/sections/%s/' % (section.section_id)
     resp = self.api_client.post(uri, format='json', data=post_data)
     self.assertHttpUnauthorized(resp)
Example #44
0
def bulk_create(hashes):
    """Bulk create stories from a list of dictionaries

    This is meant to be passed a csv.DictWriter object or steps.hashes in a
    lettuce step

    Arguments:
    hashes -- List of dictionaries containing story attributes

    """
    def _nonempty(names):
        return [name for name in names if name]

    def _parse_names(names):
        return _nonempty(re.split(',\W+', names))

    for story_dict in hashes:
        title = story_dict['title']
        summary = story_dict['summary']
        byline = story_dict['byline']
        org_names = _parse_names(story_dict['organizations'])
        proj_names = _parse_names(story_dict['projects'])
        topic_names = _parse_names(story_dict['topics'])
        place_names = _parse_names(story_dict['places'])
        loc_names = _parse_names(story_dict['locations'])
        orgs = list(
            Organization.objects.filter(
                organizationtranslation__name__in=org_names))
        projects = list(
            Project.objects.filter(projecttranslation__name__in=proj_names))
        topics = list(
            Category.objects.filter(categorytranslation__name__in=topic_names))
        places = list(Place.objects.filter(name__in=place_names))
        locations = list(Location.objects.filter(name__in=loc_names))
        story = create_story(title=title,
                             summary=summary,
                             byline=byline,
                             status='published')
        story.organizations.add(*orgs)
        story.projects.add(*projects)
        story.topics.add(*topics)
        story.places.add(*places)
        story.locations.add(*locations)
        story.save()
Example #45
0
 def test_post_list_for_section_unauthorized_unauthenticated(self):
     """
     Test that anonymous users cannot set the help item for a section
     """
     section_help = create_help(title="Test section help item", body="Test section help item body")
     story = create_story(
         title="Test Story",
         summary="Test Summary",
         byline="Test Byline",
         status="published",
         language="en",
         author=self.user,
     )
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {"help_id": section_help.help_id}
     uri = "/api/0.1/help/sections/%s/" % (section.section_id)
     resp = self.api_client.post(uri, format="json", data=post_data)
     self.assertHttpUnauthorized(resp)
Example #46
0
 def test_post_list_for_section(self):
     section_help = create_help(title="Test section help item", body="Test section help item body")
     story = create_story(
         title="Test Story",
         summary="Test Summary",
         byline="Test Byline",
         status="published",
         language="en",
         author=self.user,
     )
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {"help_id": section_help.help_id}
     uri = "/api/0.1/help/sections/%s/" % (section.section_id)
     self.api_client.client.login(username=self.username, password=self.password)
     resp = self.api_client.post(uri, format="json", data=post_data)
     self.assertHttpCreated(resp)
     updated_section = Section.objects.get(pk=section.pk)
     self.assertEqual(updated_section.help, section_help)
Example #47
0
 def test_post_list_for_section(self):
     section_help = create_help(title="Test section help item",
                                body="Test section help item body")
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status="published",
                          language="en",
                          author=self.user)
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {'help_id': section_help.help_id}
     uri = '/api/0.1/help/sections/%s/' % (section.section_id)
     self.api_client.client.login(username=self.username,
                                  password=self.password)
     resp = self.api_client.post(uri, format='json', data=post_data)
     self.assertHttpCreated(resp)
     updated_section = Section.objects.get(pk=section.pk)
     self.assertEqual(updated_section.help, section_help)
Example #48
0
 def test_post_list_for_section_unauthorized_other_user(self):
     """
     Test that a user can't set the help text for another user's section
     """
     user2 = User.objects.create(username="******", email="*****@*****.**", password="******")
     section_help = create_help(title="Test section help item", body="Test section help item body")
     story = create_story(
         title="Test Story",
         summary="Test Summary",
         byline="Test Byline",
         status="published",
         language="en",
         author=user2,
     )
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {"help_id": section_help.help_id}
     self.api_client.client.login(username=self.username, password=self.password)
     uri = "/api/0.1/help/sections/%s/" % (section.section_id)
     resp = self.api_client.post(uri, format="json", data=post_data)
     self.assertHttpUnauthorized(resp)
Example #49
0
def bulk_create(hashes):
    """Bulk create stories from a list of dictionaries

    This is meant to be passed a csv.DictWriter object or steps.hashes in a
    lettuce step

    Arguments:
    hashes -- List of dictionaries containing story attributes

    """
    def _nonempty(names):
        return [name for name in names if name]

    def _parse_names(names):
        return _nonempty(re.split(',\W+', names))

    for story_dict in hashes:
        title = story_dict['title']
        summary = story_dict['summary']
        byline = story_dict['byline']
        org_names = _parse_names(story_dict['organizations'])
        proj_names = _parse_names(story_dict['projects'])
        topic_names = _parse_names(story_dict['topics'])
        place_names = _parse_names(story_dict['places'])
        loc_names = _parse_names(story_dict['locations'])
        orgs = list(Organization.objects.filter(organizationtranslation__name__in=org_names))
        projects = list(Project.objects.filter(projecttranslation__name__in=proj_names))
        topics = list(Category.objects.filter(categorytranslation__name__in=topic_names))
        places = list(Place.objects.filter(name__in=place_names))
        locations = list(Location.objects.filter(name__in=loc_names))
        story = create_story(title=title, summary=summary, byline=byline,
                             status='published')
        story.organizations.add(*orgs)
        story.projects.add(*projects)
        story.topics.add(*topics)
        story.places.add(*places)
        story.locations.add(*locations)
        story.save()
Example #50
0
 def test_post_list_for_section_unauthorized_other_user(self):
     """
     Test that a user can't set the help text for another user's section
     """
     user2 = User.objects.create(username="******",
                                 email="*****@*****.**",
                                 password="******")
     section_help = create_help(title="Test section help item",
                                body="Test section help item body")
     story = create_story(title="Test Story",
                          summary="Test Summary",
                          byline="Test Byline",
                          status="published",
                          language="en",
                          author=user2)
     section = create_section(title="Test Section 1", story=story)
     self.assertEqual(section.help, None)
     post_data = {'help_id': section_help.help_id}
     self.api_client.client.login(username=self.username,
                                  password=self.password)
     uri = '/api/0.1/help/sections/%s/' % (section.section_id)
     resp = self.api_client.post(uri, format='json', data=post_data)
     self.assertHttpUnauthorized(resp)
Example #51
0
 def test_featured_items(self):
     image_filename = "test_image.jpg"
     app_dir = os.path.dirname(os.path.abspath(__file__))
     img_path = os.path.join(app_dir, "test_files", image_filename)
     with open(img_path) as image:
         # Create news item
         news_item = create_news_item(
             title="Test News Item",
             body="<p>This is a test news item</p>",
             image=image,
             image_filename=image_filename,
             status='published',
             on_homepage=True,
             author=self.admin_user)
         self.add_file_to_cleanup(news_item.image.file.path)
     story = create_story(title="Test Story",
                          summary="Test story summary",
                          byline="Test byline",
                          status='published',
                          author=self.user1,
                          on_homepage=True)
     project = create_project(name="Test Project",
                              description='Test project description',
                              status='published',
                              on_homepage=True)
     t = Template("{% load storybase_featured %}{% featured_items %}")
     c = Context()
     rendered = t.render(c)
     # Check that item titles are present
     self.assertIn(story.title, rendered)
     self.assertIn(news_item.title, rendered)
     self.assertIn(project.name, rendered)
     # Check ordering of items is Story, News, Project
     self.assertTrue(
         rendered.find(story.title) < rendered.find(news_item.title))
     self.assertTrue(
         rendered.find(news_item.title) < rendered.find(project.name))
Example #52
0
 def setUp(self):
     super(LocationResourceTest, self).setUp()
     self.ap_client = TestApiClient()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, 
         '*****@*****.**', self.password)
     self.user2 = User.objects.create_user("test2", "*****@*****.**",
                                           "test2")
     self.story = create_story(title="Test Story", summary="Test Summary",
         byline="Test Byline", status="published", language="en", 
         author=self.user)
     self.location_attrs = [
         {
             "name": "The Piton Foundation",
             "address": "370 17th St",
             "address2": "#5300",
             "city": "Denver",
             "state": "CO",
             "postcode": "80202",
         },
         {
             'name': "The Hull House",
             'address': "800 S. Halsted St.",
             "city": "Chicago",
             "state": "IL",
             "postcode": "60607",
         },
         {
             'name': "Bucktown-Wicker Park Library",
             'address': "1701 North Milwaukee Ave.",
             'city': "Chicago",
             'state': "IL",
             'postcode': "60647",
         }
     ]
Example #53
0
    def test_featured_items_preview(self):
        image_filename = "test_image.jpg"
        app_dir = os.path.dirname(os.path.abspath(__file__))
        img_path = os.path.join(app_dir, "test_files", image_filename)
        with open(img_path) as image:
            # Create a staged news item
            news_item = create_news_item(
                title="Test News Item",
                body="<p>This is a test news item</p>",
                image=image,
                image_filename=image_filename,
                status='staged',
                on_homepage=True,
                author=self.admin_user)
            self.add_file_to_cleanup(news_item.image.file.path)
        story = create_story(title="Test Story",
                             summary="Test story summary",
                             byline="Test byline",
                             status='published',
                             author=self.user1,
                             on_homepage=True)
        project = create_project(name="Test Project",
                                 description='Test project description',
                                 status='published',
                                 on_homepage=True)
        t = Template("{% load storybase_featured %}{% featured_items %}")

        # Check that the news item isn't present for an anonymous user
        c = Context({
            'user': self.anonymous_user,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertNotIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item isn't present for a normal user
        c = Context({
            'user': self.user1,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertNotIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item is present for an admin user
        c = Context({
            'user': self.admin_user,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)

        # Check that the news item is present for a super user
        c = Context({
            'user': self.superuser,
        })
        rendered = t.render(c)
        self.assertIn(story.title, rendered)
        self.assertIn(news_item.title, rendered)
        self.assertIn(project.name, rendered)