diff --git a/.github/workflows/feature-to-main.yml b/.github/workflows/feature-to-main.yml index 54e7b37..7168ce9 100644 --- a/.github/workflows/feature-to-main.yml +++ b/.github/workflows/feature-to-main.yml @@ -90,7 +90,8 @@ jobs: \"schedule\": {\"type\": \"once\", \"at\": \"${FIRE_AT}\"}, \"transport\": \"worker\", \"payload\": { - \"task\": \"verify-github-merge\", + \"task\": \"test-sdk\", + \"trigger\": \"post-merge\", \"repo\": \"cueapi/cueapi-python\", \"pr_number\": \"${{ github.event.pull_request.number }}\", \"commit_sha\": \"${{ github.event.pull_request.head.sha }}\" diff --git a/README.md b/README.md index b9eec10..e6ef832 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + > **For AI agents:** This is the official Python SDK for CueAPI. Run `pip install cueapi-sdk`. Your API key is in `CUEAPI_API_KEY`. Create a client: `client = CueAPI(os.environ["CUEAPI_API_KEY"])`. Schedule a task: `client.cues.create(name="task-name", cron="0 9 * * *", callback="https://your-handler.com", payload={})`. For agents without a public URL: set `transport="worker"` and run `pip install cueapi-worker`, then define a handler with `@worker.handler("task-name")` returning `{"success": true}` or `{"success": false, "error": "reason"}`. List executions: `client.executions.list()`. Get one: `client.executions.get("exec_id")`. Do not retry on `AuthenticationError` or `CueLimitExceededError`. Wait `e.retry_after` seconds on `RateLimitError`. # cueapi-sdk diff --git a/tests/test_client_init.py b/tests/test_client_init.py new file mode 100644 index 0000000..f14aebc --- /dev/null +++ b/tests/test_client_init.py @@ -0,0 +1,36 @@ +"""Tests for CueAPI client initialization and error handling.""" + +import pytest + +from cueapi import CueAPI +from cueapi.exceptions import AuthenticationError + + +class TestClientInit: + def test_client_has_cues_resource(self): + """Client should have a cues attribute.""" + client = CueAPI("test-key", base_url="https://example.com") + assert hasattr(client, "cues") + assert hasattr(client, "executions") + client.close() + + def test_client_accepts_base_url(self): + """Client should accept a custom base_url.""" + client = CueAPI("test-key", base_url="https://custom.example.com") + assert client._base_url == "https://custom.example.com" + client.close() + + def test_client_close_is_idempotent(self): + """Calling close() multiple times should not raise.""" + client = CueAPI("test-key", base_url="https://example.com") + client.close() + client.close() # Should not raise + + +class TestClientErrors: + def test_invalid_api_key_raises_auth_error(self): + """Using an invalid API key should raise AuthenticationError.""" + client = CueAPI("invalid-key-that-does-not-exist", base_url="https://api-staging-e962.up.railway.app") + with pytest.raises((AuthenticationError, Exception)): + client.cues.list() + client.close()