Пример #1
0
    def test_loading_with_paglets(self):
        def top_blue_bar(request):
            return BigpipeResponse(
                HttpResponse(),
                render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                render_source='TestMainPage')

        pagelets = [
            Pagelet(generate_dummy_request(), 'pagelet_top_blue_bar',
                    top_blue_bar, {}),
        ]

        response = BigpipeResponse(
            HttpResponse(),
            render_type=BigpipeResponse.RenderType.JAVASCRIPT,
            render_source='TestMainPage',
            js_dependencies=['simple_js_file'],
            scss_dependencies=['main'],
            i18n_dependencies=[
                "CONST_USER_open_question_placeholder.*",
                "profileboxes_no_more_profiles"
            ],
            pagelets=pagelets)

        response_content = list(response.streaming_content)
        response_len = len(response_content)
        self.assertEqual(response_len, 5)
        self.assertGreater(
            response_content[response_len -
                             1].decode('utf-8').index('</html>'), 1)
def vue_view(request):
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                           render_source='DynamicList',
                           render_options=BigpipeRenderOptions(
                               js_processor_name='vue',
                               js_dom_bind=VueDOMBind()))
Пример #3
0
 def test_js_not_exists_component(self):
     # test will pass only when production mode is on, otherwise bigpipe will render an error message
     response = BigpipeResponse(
         HttpResponse(),
         render_type=BigpipeResponse.RenderType.JAVASCRIPT,
         render_source='TestMainPageNotExists')
     with self.assertRaises(ValueError):
         list(response.streaming_content)
def news_feed(request, param_1, sleep_time):
    sleep(sleep_time)
    activate(
        'he')  # Set language to hebrew, second post is client side translated
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                           render_source='NewsFeed',
                           render_context=demo_dao.get_news_feed(),
                           i18n_dependencies=['post_title_.*'])
def demo(request):

    pagelets = [
        Pagelet(request, 'vue-container', vue_view, {}),
        Pagelet(request, 'markdown-container', markdown_view, {}),
    ]
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.TEMPLATE,
                           render_source='demoMultipleFrameworks.html',
                           pagelets=pagelets,
                           js_dependencies=js_dependencies,
                           scss_dependencies=['@demo_main'])
Пример #6
0
    def test_js_render(self):
        prop_data_string_en = '--i-am-props-data-string---'
        i18n_string_en = "Where you want to be in your next relationship"

        hebrew_translation = DjangoTranslation('he')
        prop_data_string_he = hebrew_translation._catalog[
            'CONST_USER_open_question_placeholder_1']
        i18n_string_he = hebrew_translation._catalog[
            'CONST_USER_open_question_placeholder_4']

        response_en = BigpipeResponse(
            HttpResponse(),
            render_type=BigpipeResponse.RenderType.JAVASCRIPT_RENDER,
            render_source='TestMainPage',
            render_context={'props_data': prop_data_string_en},
            i18n_dependencies=[
                "CONST_USER_open_question_placeholder.*",
                "profileboxes_no_more_profiles"
            ])
        response_str_en = list(response_en)[0].decode("utf-8")
        self.assertEqual(response_str_en[0:5], '<html')
        self.assertGreater(response_str_en.index(prop_data_string_en), 10)
        self.assertGreater(response_str_en.index(i18n_string_en), 10)

        activate('he')

        response_he = BigpipeResponse(
            HttpResponse(),
            render_type=BigpipeResponse.RenderType.JAVASCRIPT_RENDER,
            render_source='TestMainPage',
            render_context={'props_data': prop_data_string_he},
            i18n_dependencies=[
                "CONST_USER_open_question_placeholder.*",
                "profileboxes_no_more_profiles"
            ])
        response_str_he = list(response_he)[0].decode("utf-8")
        self.assertEqual(response_str_he[0:5], '<html')
        self.assertGreater(response_str_he.index(prop_data_string_he), 10)
        self.assertGreater(response_str_he.index(i18n_string_he), 10)
Пример #7
0
    def test_js_manager(self):
        # response_content will return a list of all elements to render + the closing of </body></html>
        # in case of fail to load resources the length of response_content will be 1 due only too the </body></html> only

        response = BigpipeResponse(
            HttpResponse(),
            render_type=BigpipeResponse.RenderType.JAVASCRIPT,
            render_source='TestMainPage',
            js_dependencies=['simple_js_file'],
            scss_dependencies=['main'],
            i18n_dependencies=[
                "CONST_USER_open_question_placeholder.*",
                "profileboxes_no_more_profiles"
            ])

        response_content = list(response.streaming_content)
        response_len = len(response_content)
        self.assertEqual(response_len, 4)
        self.assertGreater(
            response_content[response_len -
                             1].decode('utf-8').index('</html>'), 1)
def demo_piping(request):
    context = {
        'data': {
            'pagelet_news_feed_time':
            random.randrange(demo_dao.config.view_wait_from,
                             demo_dao.config.view_wait_to),
            'pagelet_navigation_menu_time':
            random.randrange(demo_dao.config.view_wait_from,
                             demo_dao.config.view_wait_to),
            'pagelet_information_boxes_time':
            random.randrange(demo_dao.config.view_wait_from,
                             demo_dao.config.view_wait_to)
        }
    }

    pagelets = [
        Pagelet(request, 'pagelet_top_blue_bar', top_blue_bar, {}),
        Pagelet(request, 'pagelet_news_feed', news_feed, {
            'param_1': 0,
            'sleep_time': context['data']['pagelet_news_feed_time']
        }),
        Pagelet(
            request, 'pagelet_navigation_menu', navigation_menu,
            {'sleep_time': context['data']['pagelet_navigation_menu_time']}),
        Pagelet(
            request, 'pagelet_information_boxes', information_boxes,
            {'sleep_time': context['data']['pagelet_information_boxes_time']}),
        Pagelet(request, 'pagelet_chat', chat, {})
    ]
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.TEMPLATE,
                           render_source='demoPipingReact.html',
                           render_context=context,
                           pagelets=pagelets,
                           js_dependencies=['demo_pagelet_timer'] +
                           js_react_dependencies,
                           scss_dependencies=['@demo_main'])
Пример #9
0
 def top_blue_bar(request):
     return BigpipeResponse(
         HttpResponse(),
         render_type=BigpipeResponse.RenderType.JAVASCRIPT,
         render_source='TestMainPage')
def markdown_view(request):
    return BigpipeResponse(
        request,
        render_type=BigpipeResponse.RenderType.JAVASCRIPT_RENDER,
        render_source='markdown_demo',
        render_options=BigpipeRenderOptions(js_processor_name='markdown'))
def demo(request):
    return BigpipeResponse(
        request,
        render_type=BigpipeResponse.RenderType.JAVASCRIPT_RENDER,
        render_source='LandingPage')
def chat(request):
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                           render_source='Chat')
def information_boxes(request, sleep_time):
    sleep(sleep_time)
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                           render_source='ListInformationGenerator',
                           render_context=demo_dao.get_custom_information())
def navigation_menu(request, sleep_time):
    sleep(sleep_time)
    return BigpipeResponse(request,
                           render_type=BigpipeResponse.RenderType.JAVASCRIPT,
                           render_source='NavigationMenuList',
                           render_context=demo_dao.get_navigation_items())
def top_blue_bar(request):
    return BigpipeResponse(
        request,
        render_type=BigpipeResponse.RenderType.JAVASCRIPT_RENDER,
        render_source='TopBlueBar')