Ejemplo n.º 1
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)
Ejemplo n.º 2
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")
Ejemplo n.º 3
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")
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)