Skip to content

create_test: accept test_environment_id (API requires it) - #1

Open
jochen-testingbot wants to merge 1 commit into
masterfrom
fix/create-test-environment-id
Open

jochen-testingbot wants to merge 1 commit into
masterfrom
fix/create-test-environment-id

Conversation

@jochen-testingbot

Copy link
Copy Markdown
Contributor

Part of https://testingbot-team.atlassian.net/browse/TB-1008 (docs audit: run every SDK README snippet).

Problem

Every method in the README works against the live API except one (30/31, checked on both PyPI 0.2.0 and master):

tb.tests.create_test("tb1008-readme-check", success=True, status_message="...", build="tb1008")
TestingBotException: 400: {"error":"test[test_environment_id] is missing"}

POST /v1/tests requires test[test_environment_id], but create_test had no way to send it. The web API reference (config/api_examples/tests.yml) leaves out the Python tab for this reason.

Change

  • create_test(..., test_environment_id=None): optional keyword, so existing calls keep working. It is sent as test.test_environment_id when given.
  • Unit test for the new field.
  • README: documents the parameter and where the id comes from (browser_id in tb.information.get_browsers()).

Verification (python:3.12-slim, package installed from this branch)

python -m unittest tests.test_unit           -> Ran 108 tests ... OK
browser_id = tb.information.get_browsers()[0]["browser_id"]
tb.tests.create_test("tb1008-create-test", test_environment_id=browser_id, success=True, ...)
  -> {'success': True, 'test': {..., 'test_environment_id': 32166, ...}}
tb.tests.update_test(sid, name=..., passed=True) -> True
tb.tests.get_test(sid)["name"] == "tb1008-create-test-updated"
tb.tests.delete_test(sid) -> True

The full README walkthrough script (31 calls: tests, builds, storage upload/replace/remove of the sample APK, information, screenshots, lab, labsuites, tunnel, team, configuration, user, share link) passes on both PyPI 0.2.0 and this branch, except create_test without the new argument.

Release needed: the PyPI page only changes with a new release (0.2.1), which is needs-jochen.

POST /v1/tests rejects requests without test[test_environment_id]
(400 'test[test_environment_id] is missing'), so tb.tests.create_test
as documented always failed. Add the optional keyword, a unit test and
document it in the README.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues remain: the README example uses an undefined browserId, and the client still permits missing required data that the API will reject.

2 open issues
What changed in this PR

Adds support for passing the API-required test_environment_id when creating tests, with unit coverage and README documentation.

Changes:

  • Extends create_test() to accept and serialize test_environment_id.
  • Adds unit coverage for the new request field.
  • Documents how to obtain and use the browser environment ID.

This pull request requires changes.

File Summary
tests/​test_unit.py Verifies that test_environment_id is included in the create-test request payload.
testingbotclient.py Adds test_environment_id support to create_test(); the current optional default still permits invalid requests without the required field.
README.md Documents the new parameter, but the example uses an undefined browserId variable.

Review effort: Lite

Comment thread testingbotclient.py
extra: Optional[str] = None, build: Optional[str] = None) -> Any:
"""Create a test record (for logging manual or external test results)."""
extra: Optional[str] = None, build: Optional[str] = None,
test_environment_id: Optional[Union[int, str]] = None) -> Any:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. Making test_environment_id positional/required would break existing positional calls (create_test(name, success, status_message, ...)), and a client-side None check would just duplicate the server's validation, which already returns a clear message ('test[test_environment_id] is missing'). The parameter is optional so the signature stays backwards compatible. The docstring and README now say the API needs it.

Comment thread README.md
Comment on lines +88 to +91
tb.tests.create_test(name, test_environment_id=browserId, success=None,
status_message=None, extra=None, build=None)
# test_environment_id is required by the API: the `browser_id` of the browser/device
# the test ran on, from tb.information.get_browsers()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping it as a placeholder. This README section lists every method with placeholder arguments (sessionId, buildId, app_url, testId, ...), none of which are defined in the snippet. The comment right below the call says where browserId comes from (the browser_id field of tb.information.get_browsers()).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants