Example #1
0
class Image(Element):
    type = StringField()
    image_url = UrlField()
    alt_text = StringField()

    def __init__(self, image_url, alt_text):
        super().__init__("image", image_url, alt_text)
Example #2
0
class PlainTextInput(ActionableElement):
    placeholder = TextField(plain=True, max_length=150)
    initial_value = StringField()
    multiline = BooleanField()
    min_length = IntegerField(max_value=3000)
    max_length = IntegerField()

    def __init__(
        self,
        action_id,
        placeholder=None,
        initial_value=None,
        multiline=None,
        min_length=None,
        max_length=None,
    ):
        super().__init__(
            "plain_text_input",
            action_id,
            placeholder,
            initial_value,
            multiline,
            min_length,
            max_length,
        )
Example #3
0
class Button(ActionableElement):
    primary = "primary"
    danger = "danger"

    text = TextField(plain=True, max_length=75)
    url = UrlField(max_length=3000)
    value = StringField(max_length=2000)
    style = StringField(options=[primary, danger])
    confirm = ObjectField(Confirm)

    def __init__(
        self, text, action_id=None, url=None, value=None, style=None, confirm=None
    ):
        if not any((action_id, url)):
            raise ValidationError("You should provide either action_id or url")

        super().__init__("button", action_id, text, url, value, style, confirm)
Example #4
0
class ChannelsSelect(Select):
    initial_channel = StringField()

    def __init__(
        self, placeholder, action_id, initial_channel=None, confirm=None,
    ):
        super().__init__(
            "channels_select", action_id, placeholder, confirm, initial_channel,
        )
Example #5
0
class UsersSelect(Select):
    initial_user = StringField()

    def __init__(
        self, placeholder, action_id, initial_user=None, confirm=None,
    ):
        super().__init__(
            "users_select", action_id, placeholder, confirm, initial_user,
        )
Example #6
0
class ConversationsSelect(Select):
    initial_conversation = StringField()
    filter = ObjectField(Filter)

    def __init__(
        self,
        placeholder,
        action_id,
        initial_conversation=None,
        confirm=None,
        filter=None,
    ):
        super().__init__(
            "conversations_select",
            action_id,
            placeholder,
            confirm,
            initial_conversation,
            filter,
        )
Example #7
0
class ActionableElement(Element):
    action_id = StringField(max_length=255)
Example #8
0
class Element(Component):
    type = StringField()
Example #9
0
 class FakeComponent(Component):
     title = StringField()
Example #10
0
 class ParentFakeComponent(Component):
     title = StringField()
     text = TextField()
Example #11
0
 class FakeComponent(Component):
     title = StringField()
     text = StringField()
     not_field = NotField()
Example #12
0
def test_string_field_with_incorrect_option_raises_exception():
    with pytest.raises(ValidationError):
        StringField(options=["foo", "bar"]).validate("bad_option")
Example #13
0
def test_string_field_with_exeeding_length_raises_exception():
    with pytest.raises(ValidationError):
        StringField(max_length=5).validate("foobar")
Example #14
0
def test_string_field_with_incorrect_type_raises_exception():
    with pytest.raises(ValidationError):
        StringField().validate(5)
Example #15
0
def test_string_field_validates_input():
    assert StringField().validate("input") == "input"