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)
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, )
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, )
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)
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)
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, )
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, )
class StaticSelectBase(Select): options = ArrayField(Option, max_items=100) option_groups = ArrayField(OptionGroup, max_items=100)
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)
class FakeComponent(ParentFakeComponent): elements = ArrayField(PlainText) users = ArrayField(str)
def test_array_field_validatates_strings(values): texts = [values.text] assert ArrayField(Text).validate(texts) == [ PlainText(values.text, emoji=True) ]
def test_array_field_validates_input(values): texts = [PlainText(values.text) for _ in range(3)] assert ArrayField(PlainText).validate(texts)
def test_array_field_with_lacking_items_raises_exception(plain_text): with pytest.raises(ValidationError): ArrayField(PlainText, min_items=2).validate([plain_text])
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)])