def confirm_object() -> ConfirmObject: return ConfirmObject( title=PlainTextObject(text="Confirmation"), text=PlainTextObject(text="Confirmation"), confirm=PlainTextObject(text="Confirm"), deny=PlainTextObject(text="Deny"), )
def actions_block() -> ActionsBlock: return ActionsBlock( elements=[ RadioButtonGroupElement( action_id="action-block", options=[ OptionObject( PlainTextObject(text="Action block 1"), value="action1" ), OptionObject( PlainTextObject(text="Action block 2"), value="action2" ), ], ), PlainTextInputElement( action_id="input1", placeholder=PlainTextObject(text="Input"), initial_value="Input", ), OverflowElement( action_id="overflow1", options=[ OptionObject( PlainTextObject(text="Overflow block 1"), value="overflow1" ), OptionObject( PlainTextObject(text="Overflow block 2"), value="overflow2" ), ], ), ] )
def input_block() -> InputBlock: return InputBlock( label=PlainTextObject(text="Input Block"), element=ButtonElement(text=PlainTextObject(text="Element"), action_id="element1"), hint=PlainTextObject(text="This is a hint"), optional=True, )
def datepicker_element() -> DatepickerElement: return DatepickerElement( action_id="datepicker-vhs-event", placeholder=PlainTextObject("Date"), confirm=ConfirmObject( title=PlainTextObject(text="Confirmation"), text=PlainTextObject(text="Confirmation"), confirm=PlainTextObject(text="Confirm"), deny=PlainTextObject(text="Deny"), ), )
def button_element() -> ButtonElement: return ButtonElement( text="Login", action_id="17a", url="https://codededevils.org/cas/login/", value="Login", confirm=ConfirmObject( title=PlainTextObject(text="Confirmation"), text=PlainTextObject(text="Confirmation"), confirm=PlainTextObject(text="Confirm"), deny=PlainTextObject(text="Deny"), ), )
def context_block() -> ContextBlock: return ContextBlock(elements=[ PlainTextInputElement(action_id="plaintext1", placeholder=PlainTextObject(text="Context")), RadioButtonGroupElement( action_id="radiobutton1", options=[ OptionObject(PlainTextObject(text="Radio button 1"), value="radio1"), OptionObject(PlainTextObject(text="Radio button 2"), value="radio2"), ], ), ])
def section_block() -> SectionBlock: return SectionBlock( text=PlainTextObject(text="Section"), fields=[ TextObject(btype=TextObject.BTYPE_MARKDOWN, text="Section part 1"), TextObject(btype=TextObject.BTYPE_MARKDOWN, text="section part 2"), TextObject(btype=TextObject.BTYPE_MARKDOWN, text="section part 3"), ], accessory=ImageBlock( image_url="https://codedevils.org/static/img/logo.png", alt_text="Logo", title=PlainTextObject(text="Logo"), ), )
def option_object() -> OptionObject: option = str(random.randint(0, 10)) return OptionObject( text=PlainTextObject(text="Option {}".format(option)), value=option, url="https://codedevils.org/{}".format(option), )
def view_payload() -> ViewPayload: return ViewPayload( btype=ViewPayload.BTYPE_HOME, title=TextObject(btype=TextObject.BTYPE_PLAINTEXT, text="Home page"), blocks=get_blocks(PlainTextObject(text="This block"), DividerBlock()), close=TextObject(btype=TextObject.BTYPE_PLAINTEXT, text="Close?"), )
def default_button_element() -> DefaultButtonElement: return DefaultButtonElement( text=PlainTextObject(text="Default button"), action_id="default-action-1002", url="https://codedevils.org/default", value="Default", )
def danger_button_element() -> DangerButtonElement: return DangerButtonElement( text=PlainTextObject(text="Danger button"), action_id="danger-action-1002", url="https://codedevils.org/danger", value="Danger", )
def primary_button_element() -> PrimaryButtonElement: return PrimaryButtonElement( text=PlainTextObject(text="Primary button"), action_id="primary-action-1002", url="https://codedevils.org/primary", value="Primary", )
def header_block() -> HeaderBlock: return HeaderBlock(text=PlainTextObject(text="This is a header block"),)
def option_group_object() -> OptionGroupObject: return OptionGroupObject( label=PlainTextObject(text="Option"), options=_get_options_list() )
def plain_text_object() -> PlainTextObject: return PlainTextObject(text="Plain text object")
def _get_options_list() -> typing.List[OptionObject]: return [ OptionObject(text=PlainTextObject(text="Option"), value="Option") for _ in range(0, random.randint(3, 5)) ]
def plaintext_input_element() -> PlainTextInputElement: return PlainTextInputElement( action_id="input-logo", placeholder=PlainTextObject(text="Input"), initial_value="Logo", )
def image_block() -> ImageBlock: return ImageBlock( image_url="https://codedevils.org/static/img/logo.png", alt_text="Logo", title=PlainTextObject(text="Logo"), )
def test_plain_text_object(plain_text_object: PlainTextObject): assert plain_text_object.render() == { "type": TextObject.BTYPE_PLAINTEXT, "text": plain_text_object.text, "emoji": plain_text_object.emoji }
def test_get_blocks(): text1 = PlainTextObject(text="Text 1") text2 = PlainTextObject(text="Text 2") text3 = PlainTextObject(text="Text 3") blocks = get_blocks(text1, text2, text3) assert blocks == [text1.render(), text2.render(), text3.render()]