Ejemplo n.º 1
0
def test_error_message_for_invalid_style():
    class Foo:
        pass

    style = Style(
        ClassThatDoesNotExist__foo='',
        ClassThatDoesNotExist2__foo='',
        Foo__shortcuts__does_not_exist__foo='',
        Foo__shortcuts__does_not_exist2__foo='',
    )

    with pytest.raises(InvalidStyleConfigurationException) as e:
        validate_styles(additional_classes=[Foo],
                        default_classes=[],
                        styles=dict(foo=style))

    assert str(e.value) == '''
Invalid class names:
    Style: foo - class: ClassThatDoesNotExist
    Style: foo - class: ClassThatDoesNotExist2

Invalid shortcut names:
    Style: foo - class: Foo - shortcut: does_not_exist
    Style: foo - class: Foo - shortcut: does_not_exist2
'''.strip()
Ejemplo n.º 2
0
    Field,
    Form,
    choice_parse,
)
from iommi.style import validate_styles
from tri_struct import Struct

from .models import (
    Bar,
    Foo,
    TBar,
    TFoo,
)

# Use this function in your code to check that the style is configured correctly. Pass in all stylable classes in your system. For example if you have subclasses for Field, pass these here.
validate_styles()


def ensure_objects():
    for i in range(100 - Foo.objects.count()):
        Foo.objects.create(name=f'X{i}', a=i, b=True)


def index(request):
    class AdminPage(Page):
        admin_header = html.h2('Admin example')

        admin_a = html.a('Admin', attrs__href="iommi-admin/")

    class IndexPage(Page):
        header = html.h1('iommi examples')
Ejemplo n.º 3
0
def test_validate_default_styles():
    validate_styles()