Beispiel #1
0
def test_successfully_load_from_url_list_with_content_response():
    api_data_set = APIDataSet(
        url=[foo_image_url, bar_image_url],
        method="GET",
        attribute="content",
        pool_config={
            foobar_prefix: {
                "pool_connections": 1,
                "pool_maxsize": 1,
                "max_retries": 0,
                "pool_block": False,
            }
        },
    )
    content_list = api_data_set.load()
    assert isinstance(content_list, list)
    for content in content_list:
        assert content[1:4] == b"PNG"  # part of PNG file signature
Beispiel #2
0
    def test_successfully_load_with_text_response(self, requests_mocker,
                                                  method):
        api_data_set = APIDataSet(
            url=TEST_URL,
            method=method,
            params=TEST_PARAMS,
            headers=TEST_HEADERS,
            attribute="text",
        )
        requests_mocker.register_uri(
            method,
            TEST_URL_WITH_PARAMS,
            headers=TEST_HEADERS,
            text=TEST_TEXT_RESPONSE_DATA,
        )

        response = api_data_set.load()
        assert response == TEST_TEXT_RESPONSE_DATA
Beispiel #3
0
 def test_exists_http_error(self, requests_mocker, method):
     """
     In case of an unexpected HTTP error,
     ``exists()`` should not silently catch it.
     """
     api_data_set = APIDataSet(url=TEST_URL,
                               method=method,
                               params=TEST_PARAMS,
                               headers=TEST_HEADERS)
     requests_mocker.register_uri(
         method,
         TEST_URL_WITH_PARAMS,
         headers=TEST_HEADERS,
         text="Nope, not found",
         status_code=requests.codes.FORBIDDEN,
     )
     with pytest.raises(DataSetError, match="Failed to fetch data"):
         api_data_set.exists()
Beispiel #4
0
def test_successfully_load_from_url_list_with_transforms_by_call():
    api_data_set = APIDataSet(
        pool_config={
            foobar_prefix: {
                "pool_connections": 1,
                "pool_maxsize": 1,
                "max_retries": 0,
                "pool_block": False,
            }
        },
        transforms=[io.BytesIO, PIL.Image.open],
    )
    image_list = api_data_set(
        url=[foo_image_url, bar_image_url],
        method="GET",
        attribute="content",
    )
    for image in image_list:
        assert isinstance(image, PIL.Image.Image)