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)
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)
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
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