Esempio n. 1
0
def test_parse_command_parses_command_with_single_arg():
    #arrange
    xkcd = Xkcd()
    #act
    command, args = xkcd.parse_command("xkcd latest")
    #assert
    assert command == "xkcd"
    assert len(args) == 1
Esempio n. 2
0
def test_parse_command_parses_command_with_single_arg_arg_is_corret():
    #arrange
    xkcd = Xkcd()
    #act
    command, args = xkcd.parse_command("xkcd latest")
    #assert
    assert command == "xkcd"
    assert args[0] == "latest"
Esempio n. 3
0
def test_parse_command_parses_command_only():
    #arrange
    xkcd = Xkcd()
    #act
    command, args = xkcd.parse_command("xkcd")
    #assert
    assert command == "xkcd"
    assert len(args) == 0
Esempio n. 4
0
def test_fetch_info_calls_fetch_with_comic_url_if_comicid_is_number():
    #arrange
    api_client = ApiClient()
    api_client.fetch = MagicMock(return_value='data')
    xkcd = Xkcd()
    xkcd.api_client = api_client
    #act
    data = xkcd.fetch_info(123)
    #assert
    api_client.fetch.assert_called_with("https://xkcd.com/123/info.0.json")
Esempio n. 5
0
def test_invoke_call_fetch_info_with_latest_comic_id_if_arg_is_latest():
    #arrange
    xkcd = Xkcd()
    xkcd.fetch_info = MagicMock(return_value={
        'num': 123456,
        'title': 'fake comic',
        'alt': 'fake alt',
        'img': 'fake_img'
    })
    #act
    text, attachment = xkcd.invoke("xkcd latest", "fake_user")
    #assert
    xkcd.fetch_info.assert_called_with(123456)
Esempio n. 6
0
def test_invoke_call_fetch_info_with_random_int_if_no_args(fake_randint):
    #arrange
    fake_randint.return_value = 22
    xkcd = Xkcd()
    xkcd.fetch_info = MagicMock(return_value={
        'num': 123,
        'title': 'fake comic',
        'alt': 'fake alt',
        'img': 'fake_img'
    })
    #act
    text, attachment = xkcd.invoke("xkcd", "fake_user")
    #assert
    xkcd.fetch_info.assert_called_with(22)
Esempio n. 7
0
def test_invoke_text_is_None():
    #arrange
    api_client = ApiClient()
    api_client.fetch = MagicMock(return_value={
        'num': 123,
        'title': 'fake comic',
        'alt': 'fake alt',
        'img': 'fake_img'
    })
    xkcd = Xkcd()
    xkcd.api_client = api_client
    #act
    text, attachment = xkcd.invoke("xkcd", "fake_user")
    #assert
    assert not text
Esempio n. 8
0
def test_invoke_attachment_is_slack_attachment():
    #arrange
    api_client = ApiClient()
    api_client.fetch = MagicMock(return_value={
        'num': 123,
        'title': 'fake comic',
        'alt': 'fake alt',
        'img': 'fake_img'
    })
    xkcd = Xkcd()
    xkcd.api_client = api_client
    #act
    text, attachment = xkcd.invoke("xkcd", "fake_user")
    expected_text, expected_attachment = SlackResponse.attachment(
        title='fake comic', text='fake alt', image_url='fake_img')
    #assert
    assert attachment == expected_attachment
Esempio n. 9
0
def test_available_in_all_channels():
    assert Xkcd().get_channel_id() == "all"
Esempio n. 10
0
def test_commandtext_is_xkcd():
    assert Xkcd().get_command() == "xkcd"