Esempio n. 1
0
class Checkboxes(ActionableElement):
    options = ArrayField(Option)
    initial_options = ArrayField(Option)
    confirm = ObjectField(Confirm)

    def __init__(self, action_id, options, initial_options=None, confirm=None):
        super().__init__("checkboxes", action_id, options, initial_options, confirm)
Esempio n. 2
0
class MultiStaticSelect(StaticSelectBase):
    initial_options = ArrayField(Option, OptionGroup, max_items=100)
    max_selected_items = IntegerField()

    def __init__(
        self,
        placeholder,
        action_id,
        options=None,
        option_groups=None,
        initial_options=None,
        confirm=None,
        max_selected_items=None,
    ):
        if options and option_groups:
            raise ValidationError("You can specify either options or option_groups.")

        super().__init__(
            "multi_static_select",
            action_id,
            placeholder,
            confirm,
            options,
            option_groups,
            initial_options,
            max_selected_items,
        )
Esempio n. 3
0
class MultiConversationsSelect(Select):
    initial_conversations = ArrayField(str)
    default_to_current_conversation = BooleanField()
    max_selected_items = IntegerField()
    filter = ObjectField(Filter)

    def __init__(
        self,
        placeholder,
        action_id,
        initial_conversations=None,
        default_to_current_conversation=None,
        confirm=None,
        max_selected_items=None,
        filter=None,
    ):
        super().__init__(
            "multi_conversations_select",
            action_id,
            placeholder,
            confirm,
            initial_conversations,
            default_to_current_conversation,
            max_selected_items,
            filter,
        )
Esempio n. 4
0
class RadioButtons(ActionableElement):
    options = ArrayField(Option)
    initial_option = ObjectField(Option)
    confirm = ObjectField(Confirm)

    def __init__(self, action_id, options, initial_option=None, confirm=None):
        super().__init__("radio_buttons", action_id, options, initial_option, confirm)
Esempio n. 5
0
def test_array_field_with_incorrect_input_raises_exception():
    class FakeImage:
        pass

    images = [FakeImage() for _ in range(3)]

    with pytest.raises(ValidationError):
        ArrayField(PlainText).validate(images)
Esempio n. 6
0
class MultiChannelsSelect(Select):
    initial_channels = ArrayField(str)
    max_selected_items = IntegerField()

    def __init__(
        self,
        placeholder,
        action_id,
        initial_channels=None,
        confirm=None,
        max_selected_items=None,
    ):
        super().__init__(
            "multi_channels_select",
            action_id,
            placeholder,
            confirm,
            initial_channels,
            max_selected_items,
        )
Esempio n. 7
0
class MultiExternalSelect(ExternalSelectBase):
    initial_options = ArrayField(Option, OptionGroup, max_items=100)
    max_selected_items = IntegerField()

    def __init__(
        self,
        placeholder,
        action_id,
        min_query_length=None,
        initial_options=None,
        confirm=None,
        max_selected_items=None,
    ):
        super().__init__(
            "multi_external_select",
            action_id,
            placeholder,
            confirm,
            min_query_length,
            initial_options,
            max_selected_items,
        )
Esempio n. 8
0
class StaticSelectBase(Select):
    options = ArrayField(Option, max_items=100)
    option_groups = ArrayField(OptionGroup, max_items=100)
Esempio n. 9
0
class Overflow(ActionableElement):
    options = ArrayField(Option, min_items=1, max_items=5)
    confirm = ObjectField(Confirm)

    def __init__(self, action_id, options, confirm=None):
        super().__init__("overflow", action_id, options, confirm)
Esempio n. 10
0
 class FakeComponent(ParentFakeComponent):
     elements = ArrayField(PlainText)
     users = ArrayField(str)
Esempio n. 11
0
def test_array_field_validatates_strings(values):
    texts = [values.text]
    assert ArrayField(Text).validate(texts) == [
        PlainText(values.text, emoji=True)
    ]
Esempio n. 12
0
def test_array_field_validates_input(values):
    texts = [PlainText(values.text) for _ in range(3)]
    assert ArrayField(PlainText).validate(texts)
Esempio n. 13
0
def test_array_field_with_lacking_items_raises_exception(plain_text):
    with pytest.raises(ValidationError):
        ArrayField(PlainText, min_items=2).validate([plain_text])
Esempio n. 14
0
def test_array_field_with_exeeding_items_raises_exception(plain_text):
    with pytest.raises(ValidationError):
        ArrayField(PlainText,
                   max_items=5).validate([plain_text for _ in range(10)])