Skip to content

Unit Tests - Python#738

Open
mvarendorff wants to merge 10 commits intoappwrite:masterfrom
mvarendorff:feat-680-add-unit-tests-python
Open

Unit Tests - Python#738
mvarendorff wants to merge 10 commits intoappwrite:masterfrom
mvarendorff:feat-680-add-unit-tests-python

Conversation

@mvarendorff
Copy link
Copy Markdown
Contributor

@mvarendorff mvarendorff commented Nov 4, 2023

What does this PR do?

This PR adds generated unit tests to the Python SDK.

Test Plan

Generate the SDK, weave hands to get the dependencies installed (my IDE did it for me, I have no clue about Python, I am sorry!), then run python3 -m unittest.

Related PRs and Issues

#680

Have you read the Contributing Guidelines on issues?

Yup


Discord username for swag as requested by Tessa: yestheory

@mvarendorff mvarendorff marked this pull request as draft November 19, 2023 14:33
@mvarendorff mvarendorff force-pushed the feat-680-add-unit-tests-python branch from 0528146 to ebc8868 Compare November 19, 2023 15:40
@mvarendorff mvarendorff marked this pull request as ready for review November 19, 2023 15:40
@abnegate
Copy link
Copy Markdown
Member

Are you make these test run automatically with the existing tests?

@lohanidamodar
Copy link
Copy Markdown
Member

Are you make these test run automatically with the existing tests?

@abnegate I don't think we can do that yet. But we want to use these test to run in the appwrite/sdk-for-python with github acitons.

@lohanidamodar
Copy link
Copy Markdown
Member

@abnegate let's get this merged in a different branch and sync

@ChiragAgg5k
Copy link
Copy Markdown
Member

Quick triage check: is this PR still active? It has been inactive for a long time and there is newer testing work in the repo now. If you still plan to continue, please share status/rebase plan; otherwise we can close it for now.

@mvarendorff mvarendorff force-pushed the feat-680-add-unit-tests-python branch from ebc8868 to 864a059 Compare April 1, 2026 06:37
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR adds generated unit tests for the Python SDK, covering Query, Role, Permission, ID, and Operator classes as standalone test modules, plus a per-service test template that stubs HTTP responses with requests_mock. The getResponseModelExample helper in Python.php correctly handles the PHP→Python literal conversion (replacing true/false/null with True/False/None) and the round-trip through json.dumps in the test setup is consistent because the SDK itself types integers as float.

The CI workflow update (pip install -e .[test] + python -m unittest) is the right way to wire this in.

Confidence Score: 4/5

Safe to merge with one template escaping gap to address — the single-quote issue in the service test template could silently produce a syntax error if a spec example ever includes a single quote.

Overall implementation is correct and well-structured. The responseModelExample filter correctly handles true/false/null conversion, and the round-trip data flow in the service test template is sound. One P1 finding: the escapeDollarSign filter does not escape single quotes, while string parameter examples are placed inside single-quoted Python string literals.

templates/python/test/services/test_service.py.twig — single-quote escaping gap on the string parameter example line.

Important Files Changed

Filename Overview
.github/workflows/sdk-build-validation.yml Adds pip install -e .[test] to pull in test extras and python -m unittest to run tests; straightforward and correct.
src/SDK/Language/Python.php Adds getResponseModelExample helper and responseModelExample Twig filter (correctly replacing true/false/null), plus new getFiles() entries for all test templates. Integer properties are cast to float matching the SDK's own type mapping.
templates/python/test/services/test_service.py.twig Generates per-service test files using requests_mock; handles webAuth, location (bytes), and JSON response models. Single-quote escaping gap in string parameter examples.
templates/python/pyproject.toml.twig Adds [project.optional-dependencies] test section with requests_mock==1.11.0; exact-version pin mirrors the same choice in requirements.txt.twig.
templates/python/requirements.txt.twig Adds requests_mock dependency pinned to exactly 1.11.0, inconsistent with range-based pins for other packages (flagged in prior review thread).
templates/python/test/test_query.py.twig Comprehensive Query test covering all filter methods; parameterized tests with typed examples including booleans and doubles. Test expectations are correct Python f-string format.
templates/python/test/test_permission.py.twig Simple, correct unit tests for all Permission methods.
templates/python/test/test_role.py.twig Complete unit tests for Role class covering all variants (any, user, users, guests, team, member, label).
templates/python/test/test_id.py.twig Tests ID.unique() length and ID.custom(); straightforward and correct.
templates/python/test/test_operator.py.twig Comprehensive operator tests with correct expected JSON strings.

Reviews (4): Last reviewed commit: "chore: move mock dependency as optional ..." | Re-trigger Greptile

@mvarendorff mvarendorff marked this pull request as draft April 1, 2026 06:43
@mvarendorff mvarendorff force-pushed the feat-680-add-unit-tests-python branch from 864a059 to 6f4f990 Compare April 10, 2026 13:41
@mvarendorff mvarendorff marked this pull request as ready for review April 10, 2026 15:02
@mvarendorff
Copy link
Copy Markdown
Contributor Author

@ChiragAgg5k took me a little while to get to it but this one is finally ready as well 🤞 Let me know if I missed anything :)

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 10, 2026

Tip:

Greploop — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.

Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

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.

4 participants