예제 #1
0
def test_get_breeds_failure(bot, responses):
    responses.add(responses.GET, LIST_BREEDS_URI, json=build_breeds(success=False))
    clazz = DogPhotos(bot)
    with pytest.raises(RuntimeError):
        clazz.get_breeds()
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == LIST_BREEDS_URI
예제 #2
0
def test_get_dog_image_any_breed_success(bot, responses):
    responses.add(responses.GET, RANDOM_IMAGE_URI, json=build_dog("dog", success=True))
    clazz = DogPhotos(bot)
    response = clazz.get_dog_image()
    assert response == "dog"
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == RANDOM_IMAGE_URI
예제 #3
0
def test_get_breeds_success(bot, responses):
    responses.add(responses.GET, LIST_BREEDS_URI, json=build_breeds(success=True))
    clazz = DogPhotos(bot)
    response = clazz.get_breeds()
    assert response == ["collie", "border collie", "dog"]
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == LIST_BREEDS_URI
예제 #4
0
def test_get_dog_image_no_message(bot, responses):
    responses.add(responses.GET, RANDOM_IMAGE_URI, json=build_dog("", success=True))
    clazz = DogPhotos(bot)
    with pytest.raises(RuntimeError):
        clazz.get_dog_image()
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == RANDOM_IMAGE_URI
예제 #5
0
def test_get_dog_image_given_breed_success(bot, responses, breed, path):
    responses.add(responses.GET, f"https://dog.ceo/api/breed/{path}/images/random", json=build_dog(f"{breed} result", success=True))
    clazz = DogPhotos(bot)
    response = clazz.get_dog_image(breed)
    assert response == f"{breed} result"
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == f"https://dog.ceo/api/breed/{path}/images/random"
예제 #6
0
async def test_dog_no_breed(bot, context, responses):
    responses.add(responses.GET, RANDOM_IMAGE_URI, json=build_dog("result", success=True))
    clazz = DogPhotos(bot)
    await clazz.dog(context, None)
    context.send.assert_called_once_with("result")
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == RANDOM_IMAGE_URI
예제 #7
0
async def test_dog_unknown_breed(bot, context, responses):
    responses.add(responses.GET, LIST_BREEDS_URI, json=build_breeds(success=True))
    responses.add(responses.GET, RANDOM_IMAGE_URI, json=build_dog("flup", success=True))
    clazz = DogPhotos(bot)
    await clazz.dog(context, "who?")
    context.send.assert_called_once_with("flup")
    assert len(responses.calls) == 2
    assert responses.calls[0].request.url == LIST_BREEDS_URI
    assert responses.calls[1].request.url == RANDOM_IMAGE_URI
예제 #8
0
async def test_dog_known_breed(bot, context, responses):
    responses.add(responses.GET, LIST_BREEDS_URI, json=build_breeds(success=True))
    responses.add(responses.GET, "https://dog.ceo/api/breed/collie/images/random", json=build_dog("pup", success=True))
    clazz = DogPhotos(bot)
    await clazz.dog(context, "collie")
    context.send.assert_called_once_with("pup")
    assert len(responses.calls) == 2
    assert responses.calls[0].request.url == LIST_BREEDS_URI
    assert responses.calls[1].request.url == "https://dog.ceo/api/breed/collie/images/random"