Merge pull request #9 from FlipsideCrypto/python-package-name-and-version

Add SDK Package Info to Better Assist with Debugging the PythonSDK
This commit is contained in:
Jim Myers 2022-10-31 14:40:50 -04:00 committed by GitHub
commit 03de65053f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 10 deletions

View File

@ -20,5 +20,5 @@ More Details at [ShroomDK](https://sdk.flipsidecrypto.xyz)
| Language | Version | Status |
| ------------------------ | ------- | ---------------------------------------------------------------------------------- |
| ✅ [JS/TypeScript](./js) | 1.1.1 | ![tests](https://github.com/flipsidecrypto/sdk/actions/workflows/ci_js.yml/badge.svg) |
| ✅ [Python](./python/) | 1.0.1 | [![tests](https://github.com/FlipsideCrypto/sdk/actions/workflows/ci_python.yml/badge.svg)](https://github.com/FlipsideCrypto/sdk/actions/workflows/ci_python.yml) |
| ✅ [Python](./python/) | 1.0.2 | [![tests](https://github.com/FlipsideCrypto/sdk/actions/workflows/ci_python.yml/badge.svg)](https://github.com/FlipsideCrypto/sdk/actions/workflows/ci_python.yml) |
| ✅ [R](./r/shroomDK/) | 0.1.1 | available on CRAN |

View File

@ -1 +1 @@
1.0.1
1.0.2

View File

@ -5,12 +5,24 @@ from pydantic import BaseModel, Field
class Query(BaseModel):
sql: str = Field(None, description="SQL query to execute")
ttl_minutes: Optional[int] = Field(None, description="The number of minutes to cache the query results")
timeout_minutes: Optional[int] = Field(None, description="The number of minutes to timeout the query")
retry_interval_seconds: Optional[Union[int, float]] = Field(1, description="The number of seconds to use between retries")
ttl_minutes: Optional[int] = Field(
None, description="The number of minutes to cache the query results"
)
timeout_minutes: Optional[int] = Field(
None, description="The number of minutes to timeout the query"
)
retry_interval_seconds: Optional[Union[int, float]] = Field(
1, description="The number of seconds to use between retries"
)
cached: Optional[bool] = Field(
None,
description="An override on the cache. A value of true will Re-Execute the query.",
)
page_size: int = Field(None, description="The number of results to return per page")
page_number: int = Field(None, description="The page number to return")
sdk_package: Optional[str] = Field(
None, description="The SDK package used for the query"
)
sdk_version: Optional[str] = Field(
None, description="The SDK version used for the query"
)

View File

@ -4,6 +4,9 @@ from shroomdk.models import Query
API_BASE_URL = "https://api.flipsidecrypto.com"
SDK_VERSION = "1.0.2"
SDK_PACKAGE = "python"
class ShroomDK(object):
def __init__(self, api_key: str, api_base_url: str = API_BASE_URL):
@ -30,5 +33,7 @@ class ShroomDK(object):
page_size=page_size,
page_number=page_number,
cached=cached,
sdk_package=SDK_PACKAGE,
sdk_version=SDK_VERSION,
)
)

View File

@ -13,6 +13,9 @@ from shroomdk.integrations.query_integration.query_integration import DEFAULTS
from shroomdk.models import Query, QueryStatus
from shroomdk.models.api import QueryResultJson
SDK_VERSION = "1.0.2"
SDK_PACKAGE = "python"
def get_api():
return API("https://api.flipsidecrypto.xyz", "api_key")
@ -22,17 +25,19 @@ def test_query_defaults():
qi = QueryIntegration(get_api())
# Test that the defaults are semi-overridden
q = Query(sql="", ttl_minutes=5, page_number=5, page_size=10) # type: ignore
q = Query(sql="", ttl_minutes=5, page_number=5, page_size=10, sdk_package=SDK_PACKAGE, sdk_version=SDK_VERSION) # type: ignore
next_q = qi._set_query_defaults(q)
assert next_q.page_number == 5
assert next_q.page_size == 10
assert next_q.ttl_minutes == 5
assert next_q.sdk_package == SDK_PACKAGE
assert next_q.sdk_version == SDK_VERSION
assert next_q.cached == DEFAULTS.cached
assert next_q.timeout_minutes == DEFAULTS.timeout_minutes
# Test that the defaults are not overridden
q = Query(sql="") # type: ignore
q = Query(sql="", sdk_package=SDK_PACKAGE, sdk_version=SDK_VERSION) # type: ignore
next_q = qi._set_query_defaults(q)
assert next_q.page_number == DEFAULTS.page_number
@ -40,6 +45,8 @@ def test_query_defaults():
assert next_q.ttl_minutes == DEFAULTS.ttl_minutes
assert next_q.cached == DEFAULTS.cached
assert next_q.timeout_minutes == DEFAULTS.timeout_minutes
assert next_q.sdk_package == SDK_PACKAGE
assert next_q.sdk_version == SDK_VERSION
def test_run_failed_to_create_query(requests_mock):
@ -47,7 +54,7 @@ def test_run_failed_to_create_query(requests_mock):
qi = QueryIntegration(api)
# Test 400 error
q = Query(sql="", ttl_minutes=5, page_number=5, page_size=10) # type: ignore
q = Query(sql="", ttl_minutes=5, page_number=5, page_size=10, sdk_package=SDK_PACKAGE, sdk_version=SDK_VERSION) # type: ignore
requests_mock.post(
api.get_url("queries"),
text=json.dumps({"errors": "user_error"}),
@ -103,7 +110,9 @@ def test_get_query_result_server_errors(requests_mock):
query_id = "test_query_id"
# User Error
requests_mock.get(api.get_url(f"queries/{query_id}"), status_code=400, reason="user_error")
requests_mock.get(
api.get_url(f"queries/{query_id}"), status_code=400, reason="user_error"
)
try:
qi._get_query_results("test_query_id")
@ -111,7 +120,9 @@ def test_get_query_result_server_errors(requests_mock):
assert type(e) == UserError
# Server Error
requests_mock.get(api.get_url(f"queries/{query_id}"), status_code=500, reason="server error")
requests_mock.get(
api.get_url(f"queries/{query_id}"), status_code=500, reason="server error"
)
try:
qi._get_query_results("test_query_id")