def test_get_preview_will_raise_ElementalException_if_preview_unavailable():
    client = ElementalLive(ELEMENTAL_ADDRESS, USER, API_KEY)

    client.generate_headers = mock.Mock()
    client.generate_headers.return_value = {
        'Accept': 'application/xml',
        'Content-Type': 'application/xml'
    }

    client.send_request = mock.Mock()
    client.send_request.return_value = mock_response(
        status=200,
        text=json.dumps({
            "type":
            "error",
            "message":
            "Input is invalid. "
            "Device already in use."
        }))

    with pytest.raises(ElementalException) as exc_info:
        client.generate_preview('1')

    respond_text = json.dumps({
        'type':
        'error',
        'message':
        'Input is invalid. '
        'Device already in use.'
    })
    assert str(exc_info.value).endswith(f"Response: 200\n" f"{respond_text}")
def test_get_preview_will_parse_response_json_as_expect():
    client = ElementalLive(ELEMENTAL_ADDRESS, USER, API_KEY)

    client.generate_headers = mock.Mock()
    client.generate_headers.return_value = {
        'Accept': 'application/xml',
        'Content-Type': 'application/xml'
    }

    client.send_request = mock.Mock()
    client.send_request.return_value = mock_response(
        status=200,
        text=file_fixture('success_response_for_generate_preview.json'))

    response = client.generate_preview('2')

    assert response == {
        'preview_url':
        f'{ELEMENTAL_ADDRESS}/'
        f'images/thumbs/p_1563568669_job_0.jpg'
    }