Example #1
0
def test_render_root_view(themabaster_registry):
    rendered = render_view(themabaster_registry,
                           resource=root,
                           singletons=((page_context, PageContext), ))
    this_html = BeautifulSoup(rendered, 'html.parser')
    title = this_html.select_one('title').text
    assert 'Themester Site - Themester SiteConfig' == title
Example #2
0
def test_render_view_with_singletons():
    registry = make_registry()
    singletons = ((DummySingleton(), DummySingleton),)
    result = render_view(
        registry, DummyView2,
        singletons=singletons,
    )
    assert result == '<div>Hello Dummy Singleton</div>'
Example #3
0
def test_render_view():
    registry = make_registry()
    context = resource = DummyContext()
    result = render_view(
        registry, DummyView,
        context=context,
        resource=resource,
    )
    assert result == '<div>Hello DC from DC</div>'
Example #4
0
def test_render_registered_view():
    """ Instead of passing in the view, it is in the registry already"""

    registry = make_registry()
    context = resource = DummyContext()
    register_view(registry, DummyView, context=DummyContext)
    result = render_view(
        registry,
        context=context,
        resource=resource,
    )
    assert result == '<div>Hello DC from DC</div>'
Example #5
0
    def render(self, template: str, context: Dict) -> str:  # type: ignore
        # The container is prepared upstream inside inject_context

        registry: ServiceRegistry = context['themester_registry']
        page_context = context['page_context']

        # Alas, need to get the context, which means a container
        container = registry.create_container()
        container.register_singleton(page_context, PageContext)
        context = container.get(Resource)

        # Now render
        result = render_view(
            registry,
            context=context,
            singletons=(
                (page_context, PageContext),
            )
        )
        return result
Example #6
0
def test_render_view(nullster_registry):
    resource = root['d1']
    html = render_view(nullster_registry, resource=resource)
    expected = '<div><h1>Resource: D1</h1><span>Hello Nullster</span></div>'
    assert expected == html