Skip to main content

This library is a wrapper for the TestMo REST API

Project description

TestMo-API

TestMo API wrapper

TestMo REST API Link

Using the ErrorHandling class

The project includes a simple HTTP error handler that raises requests.exceptions.HTTPError for non-success HTTP responses and enriches the message with details from the server response (if available).

Basic usage with requests:

import requests
from pyTestMoApi._utils._errors import ErrorHandling

# Example GET request
res = requests.get("https://example.testmo.net/api/v1/projects", headers={"Authorization": "Bearer <TOKEN>"}, timeout=15)

# Will do nothing if status_code < 300; otherwise raises HTTPError with details
ErrorHandling(res.status_code, response=res).handler()

# If we reach here, the request succeeded
print(res.json())

Catching errors:

import requests
from requests.exceptions import HTTPError
from pyTestMoApi._utils._errors import ErrorHandling

try:
    res = requests.get("https://example.testmo.net/api/v1/projects", headers={"Authorization": "Bearer <TOKEN>"}, timeout=15)
    ErrorHandling(res.status_code, response=res).handler()
except HTTPError as e:
    # e will include status code, a friendly message for known errors (401/403/404/405/422/429),
    # any message/detail sent by the server, and a link to Testmo docs.
    print(f"Request failed: {e}")

Notes:

  • For known status codes (401, 403, 404, 405, 422, 429), the handler prints a friendly message and includes details such as JSON message/detail or Retry-After headers when rate-limited.
  • For any other >= 300 status code, the handler raises an HTTPError with an "Unknown error" message and includes any details it can parse from the response.
  • If you don’t pass the response object, the error will still be raised for non-success codes, just without extra parsed details.

Using together with ApiClient

The included ApiClient wraps GET/POST requests to the Testmo API. After each request it calls the error handler. Example:

from pyTestMoApi.api_client import ApiClient

client = ApiClient(token="<TOKEN>", instance="example")  # or set TESTMO_TOKEN and TESTMO_INSTANCE env vars

# GET projects
res = client.api_get("/projects")
print(res.json())

# POST example
payload = {"name": "My Project"}
res = client.api_post("/projects", json=payload)
print(res.json())
uv sync           # to create/update the environment
uv sync --all-extras --group dev  # to create/update the environment with extras
uv build          # to build the package
uv pip install .  # to install the local package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

testmoapiclient-0.1.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

testmoapiclient-0.1.2-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file testmoapiclient-0.1.2.tar.gz.

File metadata

  • Download URL: testmoapiclient-0.1.2.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for testmoapiclient-0.1.2.tar.gz
Algorithm Hash digest
SHA256 52530cc8c52609514f8eb6ce7e746742ff6af026dfb760e246ca9baaaa14b5e4
MD5 df2c9d8031947e55388faaf1e5ee1106
BLAKE2b-256 18844678081c8d8be060ea54708faef264b52a05d117911ae51aee5121387432

See more details on using hashes here.

File details

Details for the file testmoapiclient-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for testmoapiclient-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 807f99de691fa7580023aa01a292948526487b49b4ff1b908a524dc93afacc0f
MD5 6fbab4b24c8b5db7ca782c63650c44f8
BLAKE2b-256 62110bd255ab5ff240b21d4f652545a332801afc4db59780ff6f9ea3688e494e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page