Ejemplo n.º 1
0
def create_test_page(model, parent=None, title='Test page', path='1111', depth=0, theme=None):
    if not theme:
        theme = create_test_theme()
    if PHEImage.objects.count() == 0:
        create_default_test_image(id=1)

    site = Site.objects.first()
    if not site.site_name:
        site.site_name = 'test'
        site.save()

    site_settings = SiteSettings.objects.filter(site_id=site.id).first()
    if not site_settings:
        site_settings = SiteSettings(site_id=site.id)
    site_settings.menu = create_test_menu()
    site_settings.save()

    if parent is None:
        parent = site.root_page

    page = model(title=title, path=path, depth=depth, page_theme=theme, live=True)
    parent.add_child(instance=page)
    page.save_revision().publish()

    return page
Ejemplo n.º 2
0
def create_test_recipe_page(title='Test Recipe page', path='1111', depth=0, theme=None):
    if not theme:
        theme = create_test_theme()
    if PHEImage.objects.count() == 0:
        create_default_test_image(id=1)

    site = Site.objects.first()
    if not site.site_name:
        site.site_name = 'oneyoutest'
        site.save()

    site_settings = SiteSettings.objects.filter(site_id=site.id).first()
    if not site_settings:
        site_settings = SiteSettings(site_id=site.id)
    site_settings.menu = create_test_menu()
    site_settings.save()

    root_page = site.root_page

    page = RecipePage(title=title, path=path, depth=depth, theme=theme)
    root_page.add_child(instance=page)

    page.save_revision().publish()

    return page
Ejemplo n.º 3
0
    def test_release_content_returns_none_if_the_requested_page_not_in_release(
            self, mock_file_service):
        """
        When a page is requested that isn't included in a release a None object should be returned.
        """
        release = create_test_release()
        site_name = 'oneyou'
        SiteSettings(site_id=release.site_id, uid=site_name).save()
        release_content = release.content.first()
        # release_content = create_test_release_content(release, json.dumps(release.generate_fixed_content()))

        self.assertRaises(KeyError, release_content.get_content_for, '0')
Ejemplo n.º 4
0
    def test_get_site_by_id_or_uuid(self):
        # invalid customsite
        self.assertEquals(get_site_by_id_or_uuid('12'), None)

        # invalid uuid
        site = Site.objects.first()
        site_settings = SiteSettings(site_id=site.id, uid='test')
        site_settings.save()
        self.assertEquals(get_site_by_id_or_uuid('test'), site_settings)
        self.assertEquals(get_site_by_id_or_uuid('test1'), None)

        #correct
        self.assertEquals(get_site_by_id_or_uuid(str(site_settings.id)),
                          site_settings)
Ejemplo n.º 5
0
    def test_release_html_endpoint_returns_an_index_with_substituted_values(
            self, mock_file_service, mock_index_file):
        release_date = timezone.now() + timedelta(days=-1)
        release = create_test_release(release_date=release_date)
        site_name = 'oneyou'
        SiteSettings(site_id=release.site_id, uid=site_name).save()
        http_host = 'phe.nhs.uk'
        request = HttpRequest()
        request.META['HTTP_HOST'] = http_host

        response = release_html(request, site_name)
        response_content_string = response.content.decode('utf-8')

        self.assertIsFalse('{{ api_url }}' in response_content_string)
        self.assertIsFalse('{{ site_setting.uid }}' in response_content_string)
        self.assertIsFalse('{{ release_id }}' in response_content_string)
        self.assertIsTrue(release.uuid in response_content_string)