Exemple #1
0
    def test_socket_error(self, requests_mocker, method):
        api_data_set = APIDataSet(url=TEST_URL,
                                  method=method,
                                  params=TEST_PARAMS,
                                  headers=TEST_HEADERS)
        requests_mocker.register_uri(method,
                                     TEST_URL_WITH_PARAMS,
                                     exc=socket.error)

        with pytest.raises(DataSetError, match="Failed to connect"):
            api_data_set.load()
Exemple #2
0
def test_attribute_not_found():
    attribute = "wrong_attribute"
    api_data_set = APIDataSet(
        url=
        "https://raw.githubusercontent.com/quantumblacklabs/kedro/develop/img/kedro_banner.png",
        method="GET",
        attribute=attribute,
    )
    pattern = r"Response has no attribute: {}".format(attribute)

    with pytest.raises(DataSetError, match=pattern):
        api_data_set.load()
Exemple #3
0
    def test_http_error(self, requests_mocker, method):
        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.load()
Exemple #4
0
def test_successfully_load_with_content_response():
    api_data_set = APIDataSet(
        url=
        "https://raw.githubusercontent.com/quantumblacklabs/kedro/develop/img/kedro_banner.png",
        method="GET",
        attribute="content",
    )
    content = api_data_set.load()
    assert content[1:4] == b"PNG"  # part of PNG file signature
Exemple #5
0
    def test_successfully_load_with_json_response(self, requests_mocker,
                                                  method):
        api_data_set = APIDataSet(
            url=TEST_URL,
            method=method,
            params=TEST_PARAMS,
            headers=TEST_HEADERS,
            attribute="json",
        )
        requests_mocker.register_uri(
            method,
            TEST_URL_WITH_PARAMS,
            headers=TEST_HEADERS,
            json=TEST_JSON_RESPONSE_DATA,
        )

        response = api_data_set.load()
        assert response == TEST_JSON_RESPONSE_DATA
Exemple #6
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