Ejemplo n.º 1
0
    def test_publishing_page_to_release_links_new_revision_to_release(
            self, mock_file_service):
        page = create_test_page()

        initial_revision = page.get_latest_revision()

        release = create_test_release()

        page.release = release
        page.title = 'Updated page'
        page.save_revision().publish()

        second_revision = page.get_latest_revision()

        initial_revision_in_release = False
        second_revision_in_release = False

        content = json.loads(release.content.first().content)
        if content[str(
                page.id)]['title'] == initial_revision.as_page_object().title:
            initial_revision_in_release = True
        if content[str(
                page.id)]['title'] == second_revision.as_page_object().title:
            second_revision_in_release = True

        self.assertTrue(second_revision_in_release)
        self.assertIsFalse(initial_revision_in_release)
Ejemplo n.º 2
0
 def test_replace_internal_links_correctly_returns_a_tag_with_hrf(self):
     page = create_test_page()
     rich_text_source = '<p><a id="{}" linktype="page">link 1</a></p>'.format(
         page.id)
     processed_content = process_inlines(rich_text_source)
     self.assertNotEquals(rich_text_source, processed_content)
     self.assertIsTrue('<a' in processed_content)
     self.assertIsTrue('href="' in processed_content)
Ejemplo n.º 3
0
    def test_breadcrumbs_property(self):
        parent_page = create_test_page()
        child_page = create_test_child_page(parent_page)

        self.assertEquals(len(child_page.breadcrumbs), 2)
        self.assertEquals(child_page.breadcrumbs[-1]['name'],
                          parent_page.title)
        self.assertEquals(child_page.breadcrumbs[-1]['url'],
                          parent_page.link_url)
Ejemplo n.º 4
0
    def test_get_serializable_data_for_fields_correctly_serialises_the_page(
            self):
        page = create_test_page()
        field = OneYou2Page._meta.get_field('body')
        page.body = StreamValue(
            field.stream_block,
            [('section_heading_shelf',
              StructValue([('heading', 'This is a section heading'),
                           ('shelf_id', 'shelf1')]))])
        serialized_data = get_serializable_data_for_fields(page)

        self.assertEqual(type(serialized_data), dict)
Ejemplo n.º 5
0
def create_test_oneyou_variant(parent_page=None, title='Test page (variant)', path='11111111', depth=0, theme=None):
    if not parent_page:
        parent_page = create_test_page()
    if not theme:
        theme = parent_page.theme
    if PHEImage.objects.count() == 0:
        create_default_test_image(id=1)

    variant = OneYouVariant(title=title, path=path, depth=depth, theme=theme)
    parent_page.add_child(instance=variant)
    variant.save_revision().publish()
    variant.save()

    return variant
Ejemplo n.º 6
0
    def test_unpublishing_a_page_removes_the_revision_for_that_page_from_the_release(
            self, mock_file_service):
        page = create_test_page()

        release = create_test_release()

        page.release = release
        page.save_revision()

        page_count = OneYou2Page.objects.count()
        live_page_count = OneYou2Page.objects.live().count()

        release_content = release.content.first()
        release_content_dict = json.loads(release_content.content)

        self.assertEquals(page_count, len(release_content_dict))
        self.assertEquals(live_page_count, len(release_content_dict))

        revision_in_release = False
        if str(page.id) in release_content_dict:
            revision_in_release = True

        self.assertTrue(revision_in_release)

        page.release = release
        page.unpublish(release.id)

        page_count = OneYou2Page.objects.count()
        # live_page_count = OneYou2Page.objects.live().count()

        release_content = release.content.first()
        release_content_dict = json.loads(release_content.content)

        self.assertNotEquals(page_count, len(release_content_dict))
        # self.assertEquals(live_page_count, len(release_content_dict))

        revision_in_release = False
        if str(page.id) in release_content_dict:
            revision_in_release = True

        self.assertIsFalse(revision_in_release)
Ejemplo n.º 7
0
    def test_page_serializable_data_function_returns_the_full_content_of_shared_shelves(
            self):
        """
        serializable_data is used in the saving of a revision,
        so to check its working correctly we check the content of the revision.
        """
        shelf = create_test_promo_shelf()
        body_content_string = '[{"type": "simple_page_heading_shelf", "value": {"heading": "Heading", "shelf_id":' \
                              ' "1"}, "id": "b2d5e2e8-ae9d-46ef-92e6-27745a85df8c"},{"type": "promo_shelf", "value": ' \
                              + str(shelf.id) + ', "id": "14dd05e9-1d75-4831-a969-01f5c2c82b55"}]'
        page = create_test_page()
        body_field = [
            field for field in page._meta.fields if field.name == 'body'
        ][0]
        page.body = body_field.to_python(body_content_string)

        page.save_revision()
        body_dict = json.loads(
            json.loads(page.get_latest_revision().content_json)['body'])

        self.assertEqual(len(body_dict), 2)
        self.assertIsTrue('content' in body_dict[1])
        self.assertIsTrue('shelf_id' in body_dict[1]['content'])
        self.assertEqual(body_dict[1]['content']['shelf_id'], shelf.shelf_id)
Ejemplo n.º 8
0
 def test_page_default_preview_mode_returns_the_correct_option(self):
     page = create_test_page()
     default_preview_mode = 'react'
     self.assertEquals(page.default_preview_mode, default_preview_mode)
Ejemplo n.º 9
0
 def test_page_preview_modes_function_returns_the_correct_options(self):
     page = create_test_page()
     self.assertEquals(page.preview_modes,
                       OneYou2Page.DEFAULT_PREVIEW_MODES)