Esempio n. 1
0
    def test_auto_unique_slug(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)
        self.assertEqual(project.slug,
                         "the-metro-denver-regional-equity-atlas")
        project2 = create_project(name=name, description=description)
        self.assertEqual(project2.slug,
                         "the-metro-denver-regional-equity-atlas-2")
        self.assertEqual(Project.objects.filter(
            slug="the-metro-denver-regional-equity-atlas").count(), 1)
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')
Esempio n. 3
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))
Esempio n. 4
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)
Esempio n. 5
0
    def test_user_can_view(self):
        proj = create_project(name="Test Project", status='pending')
        ProjectMembership.objects.create(user=self.user1, project=proj,
                member_type='owner')

        # Test owner cannot view their own pending Project
        self.assertFalse(proj.user_can_view(self.user1))

        # Test non-owner cannot view a pending Project
        self.assertFalse(proj.user_can_view(self.user2))

        # Test an admin user can view another user's pending Project
        self.assertTrue(proj.user_can_view(self.admin_user))

        # Test that a super user can view another user's pending Project 
        self.assertTrue(proj.user_can_view(self.superuser))

        # Publish the Project to set up for next tests
        proj.status = 'published'
        proj.save()
        
        # Test that owner can view a published Project 
        self.assertTrue(proj.user_can_view(self.user1))

        # Test that another user can view a published Project 
        self.assertTrue(proj.user_can_view(self.user2))
Esempio n. 6
0
    def test_create_project(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.
            """
        with self.assertRaises(Project.DoesNotExist):
            Project.objects.get(projecttranslation__name=name)
        project = create_project(name=name, description=description)
        self.assertEqual(project.name, name)
        self.assertEqual(project.description, description)
        retrieved_project = Project.objects.get(pk=project.pk)
        self.assertEqual(retrieved_project.name, name)
        self.assertEqual(retrieved_project.description, description)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
0
    def test_anonymoususer_can_view(self):
        proj = create_project(name="Test Project", 
                status='pending')

        # An anonymous user can't view a pending project
        self.assertFalse(proj.anonymoususer_can_view(self.anonymous_user))

        proj.status = 'published'
        proj.save()

        # An anonymous user can view a published project 
        self.assertTrue(proj.anonymoususer_can_view(self.anonymous_user))
Esempio n. 10
0
 def test_normalize_for_view(self):
     user = User.objects.create_user('test', '*****@*****.**', 'test')
     user.first_name = "Test"
     user.last_name = "User"
     user.save()
     project = create_project(name="Test Project", description="Test Description")
     featured_asset = create_external_asset(type='image', title='',
             url='http://fakedomain.com/uploads/image.jpg')
     project.featured_assets.add(featured_asset)
     normalized = project.normalize_for_view(img_width=335)
     self.assertEqual(normalized['title'], "Test Project")
     self.assertNotIn('author', normalized)
     self.assertEqual(normalized['date'], project.created)
     self.assertIn('http://fakedomain.com/uploads/image.jpg',
             normalized['image_html'])
     self.assertEqual(normalized['excerpt'], "Test Description")
     self.assertEqual(normalized['url'], project.get_absolute_url())
Esempio n. 11
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))
Esempio n. 12
0
def projects_in_database(step):
    for project_dict in step.hashes:
        create_project(**project_dict)
Esempio n. 13
0
def project_created(step, name):
    try:
        Project.objects.get(projecttranslation__name=name)
    except Project.DoesNotExist:
        create_project(name)
Esempio n. 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)
Esempio n. 15
0
 def setup_project(self):
     self.project = create_project("Test Project", status='published')
Esempio n. 16
0
 def create_model(self, name):
     return create_project(name=name, status="pending")
def setup_organization_and_project(scenario):
    matching_scenarios = ('An admin can create a story and it\'s core metadata in English')
    if scenario.name in matching_scenarios: 
        create_organization(name="Mile High Connects") 
        create_project(name='The Metro Denver Regional Equity Atlas')
Esempio n. 18
0
def project_created(step, name):
    try:
        Project.objects.get(projecttranslation__name=name)
    except Project.DoesNotExist:
        create_project(name)
Esempio n. 19
0
def project_created(step, name):
    create_project(name)
Esempio n. 20
0
def project_created(step, name):
    create_project(name)
Esempio n. 21
0
def projects_in_database(step):
    for project_dict in step.hashes:
        create_project(**project_dict)
Esempio n. 22
0
def setup_organization_and_project(scenario):
    matching_scenarios = (
        'An admin can create a story and it\'s core metadata in English')
    if scenario.name in matching_scenarios:
        create_organization(name="Mile High Connects")
        create_project(name='The Metro Denver Regional Equity Atlas')