def test_pjax_block_no_result(): resp = pjax_block(lambda *a, **kw: None)(base_view)(pjax_request, test_template) result = resp.rendered_content assert result == ("Block Title" "Some text outside the main block." "I'm wearing orange galoshes" "Some secondary content." "More text outside the main block.")
def test_pjax_block_no_result(): resp = pjax_block(lambda *a, **kw: None)(base_view)(pjax_request, test_template) result = resp.rendered_content assert result == ("Block Title" "Some text outside the main block." "I'm wearing orange galoshes" "Some secondary content." "More text outside the main block.")
def test_pjax_overridden_block(): view_secondary_block = pjax_block("secondary")(base_view) response = view_secondary_block(pjax_request, extends_template, {'base_template': base_template}) assert response.rendered_content == "overridden secondary block content"
def test_pjax_block_title_conflict(): with pytest.raises(ValueError): pjax_block("main", title_variable="title", title_block="title")(None)
def test_pjax_block_title_block_error(): view = pjax_block("main", title_block="title_missing")(base_view) resp = view(pjax_request, test_template) with pytest.raises(TemplateSyntaxError): _ = resp.rendered_content
def test_pjax_block_none_arg(): pjax_block(None)
def test_pjax_block_title_block_error(): view = pjax_block("main", title_block="title_missing")(base_view) resp = view(pjax_request, test_template) _ = resp.rendered_content
def test_pjax_block_title_variable_error(): view = pjax_block("main", title_variable="title_missing")(base_view) resp = view(pjax_request, test_template, {'title': 'Variable Title'}) _ = resp.rendered_content
def test_pjax_block_auto_title(): view = pjax_block(title_block="title")(base_view) resp = view(pjax_request, test_template) result = resp.rendered_content assert result == ("<title>Block Title</title>\n" "Some secondary content.")
def test_registry(): wrapped_classes = sorted(cls.__name__ for cls in djpj.template._wrapped_class_registry) assert wrapped_classes == ['ExtendsNode', 'NodeList', 'Template', 'TemplateResponse'] def test_object_wrapping_direct_instantiation(): response = base_view(pjax_request, test_template) with pytest.raises(NotImplementedError): PJAXTemplateResponse(response, None, None) # The test "views" themselves. def base_view(request, template, extra_context=None): extra_context = extra_context or dict() extra_context.update({"colour": "orange"}) return TemplateResponse(request, template, extra_context) view_pjax_block = pjax_block("main")(base_view) view_pjax_block_auto = pjax_block()(base_view) @pjax_block() def view_pjax_block_redirect(_): return HttpResponseRedirect('/redirected/') @pjax_block() def view_pjax_block_not_deferred(_): return HttpResponse("Some text!")
def test_pjax_block_none_arg(): pjax_block(None)
def test_pjax_block_title_conflict(): pjax_block("main", title_variable="title", title_block="title")(None)
def test_pjax_block_title_block_error(): view = pjax_block("main", title_block="title_missing")(base_view) resp = view(pjax_request, test_template) _ = resp.rendered_content
def test_pjax_overridden_block(): view_secondary_block = pjax_block("secondary")(base_view) response = view_secondary_block(pjax_request, extends_template, {'base_template': base_template}) assert response.rendered_content == "overridden secondary block content"
def test_pjax_block_title_conflict(): with pytest.raises(ValueError): pjax_block("main", title_variable="title", title_block="title")(None)
def test_pjax_block_none_arg(): with pytest.raises(ValueError): pjax_block(None)
] @raises(NotImplementedError) def test_object_wrapping_direct_instantiation(): response = base_view(pjax_request, test_template) PJAXTemplateResponse(response, None, None) # The test "views" themselves. def base_view(request, template, extra_context=None): extra_context = extra_context or dict() extra_context.update({"colour": "orange"}) return TemplateResponse(request, template, extra_context) view_pjax_block = pjax_block("main")(base_view) view_pjax_block_auto = pjax_block()(base_view) @pjax_block() def view_pjax_block_redirect(_): return HttpResponseRedirect('/redirected/') @pjax_block() def view_pjax_block_not_deferred(_): return HttpResponse("Some text!")
def test_pjax_block_auto_title(): view = pjax_block(title_block="title")(base_view) resp = view(pjax_request, test_template) result = resp.rendered_content assert result == ("<title>Block Title</title>\n" "Some secondary content.")
def test_pjax_block_title_variable(): view = pjax_block("main", title_variable="title")(base_view) resp = view(pjax_request, test_template, {'title': 'Variable Title'}) result = resp.rendered_content assert result == "<title>Variable Title</title>\nI'm wearing orange galoshes"
def test_pjax_block_title_variable(): view = pjax_block("main", title_variable="title")(base_view) resp = view(pjax_request, test_template, {'title': 'Variable Title'}) result = resp.rendered_content assert result == "<title>Variable Title</title>\nI'm wearing orange galoshes"
def test_pjax_block_title_block(): view = pjax_block("main", title_block="title")(base_view) resp = view(pjax_request, test_template) result = resp.rendered_content assert result == "<title>Block Title</title>\nI'm wearing orange galoshes"
def test_pjax_block_title_variable_error(): view = pjax_block("main", title_variable="title_missing")(base_view) resp = view(pjax_request, test_template, {'title': 'Variable Title'}) with pytest.raises(KeyError): _ = resp.rendered_content
def test_pjax_block_title_conflict(): pjax_block("main", title_variable="title", title_block="title")(None)
def test_pjax_block_title_block(): view = pjax_block("main", title_block="title")(base_view) resp = view(pjax_request, test_template) result = resp.rendered_content assert result == "<title>Block Title</title>\nI'm wearing orange galoshes"
def test_pjax_block_title_block_error(): view = pjax_block("main", title_block="title_missing")(base_view) resp = view(pjax_request, test_template) with pytest.raises(TemplateSyntaxError): _ = resp.rendered_content
def test_pjax_block_none_arg(): with pytest.raises(ValueError): pjax_block(None)