-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import pytest | ||
import warnings | ||
|
||
from urllib3 import BaseHTTPResponse, HTTPResponse | ||
|
||
from datetime import datetime, date | ||
|
||
from pinecone.core_ea.openapi.db_data.api.bulk_operations_api import BulkOperationsApi | ||
from pinecone.core_ea.openapi.db_data.models import ImportModel, StartImportResponse | ||
from pinecone.core_ea.openapi.shared.api_client import ApiClient | ||
from pinecone.core_ea.openapi.shared.exceptions import PineconeApiException | ||
|
||
from pinecone.data.features.bulk_import import ImportFeatureMixin | ||
|
||
|
||
def build_api_w_faked_response(mocker, body: str, status: int = 200) -> BaseHTTPResponse: | ||
response = mocker.Mock() | ||
response.headers = {"content-type": "application/json"} | ||
response.status = status | ||
response.data = body.encode("utf-8") | ||
|
||
api_client = ApiClient() | ||
mocker.patch.object(api_client.rest_client.pool_manager, "request", return_value=response) | ||
return BulkOperationsApi(api_client=api_client) | ||
|
||
|
||
def build_client_w_faked_response(mocker, body: str, status: int = 200): | ||
api_client = build_api_w_faked_response(mocker, body, status) | ||
return ImportFeatureMixin(__import_operations_api=api_client, api_key="asdf", host="asdf") | ||
|
||
|
||
class TestBulkImportStartImport: | ||
def test_start_import(self, mocker): | ||
body = """ | ||
{ | ||
"id": "1" | ||
} | ||
""" | ||
client = build_client_w_faked_response(mocker, body) | ||
|
||
with pytest.warns(UserWarning, match="prerelease"): | ||
my_import = client.start_import("s3://path/to/file.parquet") | ||
assert my_import.id == "1" | ||
assert my_import["id"] == "1" | ||
assert my_import.to_dict() == {"id": "1"} | ||
assert my_import.__class__ == StartImportResponse | ||
|
||
def test_start_import_with_kwargs(self, mocker): | ||
body = """ | ||
{ | ||
"id": "1" | ||
} | ||
""" | ||
client = build_client_w_faked_response(mocker, body) | ||
|
||
with pytest.warns(UserWarning, match="prerelease"): | ||
my_import = client.start_import(uri="s3://path/to/file.parquet") | ||
assert my_import.id == "1" | ||
assert my_import["id"] == "1" | ||
assert my_import.to_dict() == {"id": "1"} | ||
assert my_import.__class__ == StartImportResponse | ||
|
||
def test_start_invalid_uri(self, mocker): | ||
body = """ | ||
{ | ||
"code": "3", | ||
"message": "Bulk import URIs must start with the scheme of a supported storage provider", | ||
"details": [] | ||
} | ||
""" | ||
client = build_client_w_faked_response(mocker, body, 400) | ||
|
||
with pytest.warns(UserWarning, match="prerelease"): | ||
with pytest.raises(PineconeApiException) as e: | ||
my_import = client.start_import(uri="invalid path") | ||
|
||
assert e.value.status == 400 | ||
assert e.value.body == body | ||
assert "Bulk import URIs must start with the scheme of a supported storage provider" in str(e.value) | ||
|
||
def test_no_arguments(self, mocker): | ||
client = build_client_w_faked_response(mocker, "") | ||
|
||
with pytest.warns(UserWarning, match="prerelease"): | ||
with pytest.raises(TypeError) as e: | ||
my_import = client.start_import() | ||
|
||
assert "missing 1 required positional argument" in str(e.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters