def test_to_json(): field = to_test_type(Field('title val', 'value val', True)) assert field == { 'title': 'title val', 'value': 'value val', 'short': '1', } attachment = to_test_type( Attachment( fallback='fallback val', title='title val', fields=[Field('field title1', 'field value1', False)], actions=[ Action( name='action1 name', text='action1 text', type='button', data_source='external', options=[ OptionField(text='a1 o1 text', value='a1 o1 value') ], style='danger', min_query_length=100, confirm=Confirmation(text='confirm text'), selected_options=[ OptionField(text='a1 so1 text', value='a1 so1 value',) ], value='action1 value', url='action1 url', ), Action( name='action2 name', text='action2 text', type='select', option_groups=[ OptionFieldGroup( text='a2 og1 text', options=[ OptionField( text='a2 og1 o1 text', value='a2 og1 o1 value', ), ], ) ], ), ], ) ) assert attachment == { 'fallback': 'fallback val', 'title': 'title val', 'fields': [ {'title': 'field title1', 'value': 'field value1', 'short': '0'} ], 'actions': [ { 'name': 'action1 name', 'text': 'action1 text', 'type': 'button', 'data_source': 'external', 'options': [{'text': 'a1 o1 text', 'value': 'a1 o1 value'}], 'style': 'danger', 'min_query_length': 100, 'confirm': {'text': 'confirm text'}, 'selected_options': [ {'text': 'a1 so1 text', 'value': 'a1 so1 value'}, ], 'value': 'action1 value', 'url': 'action1 url', }, { 'name': 'action2 name', 'text': 'action2 text', 'type': 'select', 'option_groups': [ { 'text': 'a2 og1 text', 'options': [ { 'text': 'a2 og1 o1 text', 'value': 'a2 og1 o1 value', }, ], }, ], }, ], }
def test_to_json(): field = to_test_type(Field("title val", "value val", True)) assert field == { "title": "title val", "value": "value val", "short": "1", } attachment = to_test_type( Attachment( fallback="fallback val", title="title val", fields=[Field("field title1", "field value1", False)], actions=[ Action( name="action1 name", text="action1 text", type="button", data_source="external", options=[ OptionField(text="a1 o1 text", value="a1 o1 value") ], style="danger", min_query_length=100, confirm=Confirmation(text="confirm text"), selected_options=[ OptionField( text="a1 so1 text", value="a1 so1 value", ) ], value="action1 value", url="action1 url", ), Action( name="action2 name", text="action2 text", type="select", option_groups=[ OptionFieldGroup( text="a2 og1 text", options=[ OptionField( text="a2 og1 o1 text", value="a2 og1 o1 value", ), ], ) ], ), ], )) assert attachment == { "fallback": "fallback val", "title": "title val", "fields": [{ "title": "field title1", "value": "field value1", "short": "0" }], "actions": [ { "name": "action1 name", "text": "action1 text", "type": "button", "data_source": "external", "options": [{ "text": "a1 o1 text", "value": "a1 o1 value" }], "style": "danger", "min_query_length": 100, "confirm": { "text": "confirm text" }, "selected_options": [ { "text": "a1 so1 text", "value": "a1 so1 value" }, ], "value": "action1 value", "url": "action1 url", }, { "name": "action2 name", "text": "action2 text", "type": "select", "option_groups": [ { "text": "a2 og1 text", "options": [ { "text": "a2 og1 o1 text", "value": "a2 og1 o1 value", }, ], }, ], }, ], }
def test_action_class(): id = None confirm = Confirmation( dismiss_text='dismiss', ok_text='ok', text='some text', title='some title', ) data_source = 'default' min_query_length = 100 name = 'Test Button' options = [OptionField( text='test', value='test', )] selected_options = [OptionField( text='text', value='value', description='some description', )] style = 'danger' text = 'Test Text' type = 'button' value = '' url = 'https://item4.github.io' action = Action( id=id, confirm=confirm, data_source=data_source, min_query_length=min_query_length, name=name, options=options, selected_options=selected_options, style=style, text=text, type=type, value=value, url=url, ) assert action.id == id assert action.confirm == confirm assert action.data_source == ActionDataSource(data_source) assert action.min_query_length is None assert action.name == name assert action.options == options assert action.selected_options == selected_options assert action.style == ActionStyle(style) assert action.text == text assert action.type == ActionType(type) assert action.value == value assert action.url == url action = Action( name=name, text=text, type=type, options=[OptionField( text='test', value='test', )], option_groups=[OptionFieldGroup(text='text', options=[ OptionField( text='test2', value='test2', ), ])], ) assert action.options is None assert action.option_groups == [ OptionFieldGroup(text='text', options=[ OptionField( text='test2', value='test2', ), ]), ]
def test_action_class(): id = None confirm = Confirmation( dismiss_text="dismiss", ok_text="ok", text="some text", title="some title", ) data_source = "default" min_query_length = 100 name = "Test Button" options = [OptionField( text="test", value="test", )] selected_options = [ OptionField( text="text", value="value", description="some description", ) ] style = "danger" text = "Test Text" type = "button" value = "" url = "https://item4.github.io" action = Action( id=id, confirm=confirm, data_source=data_source, min_query_length=min_query_length, name=name, options=options, selected_options=selected_options, style=style, text=text, type=type, value=value, url=url, ) assert action.id == id assert action.confirm == confirm assert action.data_source == ActionDataSource(data_source) assert action.min_query_length is None assert action.name == name assert action.options == options assert action.selected_options == selected_options assert action.style == ActionStyle(style) assert action.text == text assert action.type == ActionType(type) assert action.value == value assert action.url == url action = Action( name=name, text=text, type=type, options=[OptionField( text="test", value="test", )], option_groups=[ OptionFieldGroup( text="text", options=[OptionField(text="test2", value="test2")], ) ], ) assert action.options is None assert action.option_groups == [ OptionFieldGroup(text="text", options=[OptionField(text="test2", value="test2")]), ]