-
Notifications
You must be signed in to change notification settings - Fork 199
Unit Tests - Python #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChiragAgg5k
merged 11 commits into
appwrite:master
from
mvarendorff:feat-680-add-unit-tests-python
Apr 20, 2026
Merged
Unit Tests - Python #738
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e046a21
feat: python unit tests
mvarendorff bdc28cd
fix: updated between serialization
mvarendorff 93caad2
feat: run python tests in CI
mvarendorff b544cb6
feat: operator test
mvarendorff 17d7dd7
WIP fix: tests
mvarendorff 6f4f990
fix: example data generator
mvarendorff 1ce4ed8
fix: remaining testcases
mvarendorff 835600c
chore: formatting
mvarendorff 4e03b2b
fix: include request_mock in requirements
mvarendorff 8cd6f24
chore: move mock dependency as optional test, update CI
mvarendorff ea59f6b
chore: fix linting
mvarendorff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| requests>=2.31,<3 | ||
| requests_mock==1.11.0 | ||
| pydantic>=2,<3 | ||
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import json | ||
| import requests_mock | ||
| import unittest | ||
|
|
||
| from appwrite.client import Client | ||
| from appwrite.input_file import InputFile | ||
| from appwrite.models import * | ||
| from appwrite.services.{{ service.name | caseSnake }} import {{ service.name | caseUcfirst }} | ||
|
|
||
| class {{ service.name | caseUcfirst }}ServiceTest(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.client = Client() | ||
| self.{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(self.client) | ||
|
|
||
| {% for method in service.methods %} | ||
| @requests_mock.Mocker() | ||
| def test_{{ method.name | caseSnake }}(self, m): | ||
| {%~ if method.type == 'webAuth' %} | ||
| data = None | ||
| {%~ elseif method.type == 'location' %} | ||
| data = bytearray() | ||
| {%~ else %} | ||
| {%~ if method.responseModel and method.responseModel != 'any' %} | ||
| data = {{ method.responseModel | responseModelExample(spec) | raw }} | ||
| {%~ else %} | ||
| data = '' | ||
| {%~ endif %} | ||
| {%~ endif %} | ||
| headers = {'Content-Type': {% if method.type == 'location' %}'application/octet-stream'{% else %}'application/json'{% endif %}} | ||
| m.request(requests_mock.ANY, requests_mock.ANY, {% if method.type == 'location' %}body=data{% else %}text=json.dumps(data){% endif %}, headers=headers) | ||
|
|
||
| response = self.{{ service.name | caseSnake }}.{{ method.name | caseSnake }}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%} | ||
| {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.from_bytes(bytearray(), "example.file"){% elseif parameter.type == 'boolean' %}True{% elseif parameter.type == 'string' %}'{% if parameter.example is not empty %}{{parameter.example | escapeDollarSign}}{% endif %}'{% elseif parameter.type == 'integer' and parameter['x-example'] is empty %}1{% elseif parameter.type == 'number' and parameter['x-example'] is empty %}1.0{% else %}{{parameter.example}}{%~ endif ~%},{%~ endfor ~%} | ||
| ) | ||
|
|
||
| {%~ if method.type != 'webAuth' and method.responseModel and method.responseModel != 'any' %} | ||
| {%~ if method.responseModel == 'row' or method.responseModel == 'document' or method.responseModel == 'preferences' %} | ||
| data['data'] = {} | ||
| {%~ endif %} | ||
| self.assertEqual(response.to_dict(), data) | ||
| {%~ else %} | ||
| self.assertEqual(response, data) | ||
| {%~ endif %} | ||
|
|
||
| {% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import unittest | ||
|
|
||
| from appwrite.id import ID | ||
|
|
||
| class TestIDMethods(unittest.TestCase): | ||
|
|
||
| def test_unique(self): | ||
| self.assertEqual(len(ID.unique()), 20) | ||
|
|
||
| def test_custom(self): | ||
| self.assertEqual(ID.custom('custom'), 'custom') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import unittest | ||
|
|
||
| from appwrite.operator import Operator, Condition | ||
|
|
||
| class TestOperatorMethods(unittest.TestCase): | ||
|
|
||
| def test_increment(self): | ||
| self.assertEqual(Operator.increment(1), '{"method":"increment","values":[1]}') | ||
|
|
||
| def test_increment_with_max(self): | ||
| self.assertEqual(Operator.increment(5, 100), '{"method":"increment","values":[5,100]}') | ||
|
|
||
| def test_decrement(self): | ||
| self.assertEqual(Operator.decrement(1), '{"method":"decrement","values":[1]}') | ||
|
|
||
| def test_decrement_with_min(self): | ||
| self.assertEqual(Operator.decrement(3, 0), '{"method":"decrement","values":[3,0]}') | ||
|
|
||
| def test_multiply(self): | ||
| self.assertEqual(Operator.multiply(2), '{"method":"multiply","values":[2]}') | ||
|
|
||
| def test_multiply_with_max(self): | ||
| self.assertEqual(Operator.multiply(3, 1000), '{"method":"multiply","values":[3,1000]}') | ||
|
|
||
| def test_divide(self): | ||
| self.assertEqual(Operator.divide(2), '{"method":"divide","values":[2]}') | ||
|
|
||
| def test_divide_with_min(self): | ||
| self.assertEqual(Operator.divide(4, 1), '{"method":"divide","values":[4,1]}') | ||
|
|
||
| def test_modulo(self): | ||
| self.assertEqual(Operator.modulo(5), '{"method":"modulo","values":[5]}') | ||
|
|
||
| def test_power(self): | ||
| self.assertEqual(Operator.power(2), '{"method":"power","values":[2]}') | ||
|
|
||
| def test_power_with_max(self): | ||
| self.assertEqual(Operator.power(3, 100), '{"method":"power","values":[3,100]}') | ||
|
|
||
| def test_array_append(self): | ||
| self.assertEqual(Operator.array_append(['item1', 'item2']), '{"method":"arrayAppend","values":["item1","item2"]}') | ||
|
|
||
| def test_array_prepend(self): | ||
| self.assertEqual(Operator.array_prepend(['first', 'second']), '{"method":"arrayPrepend","values":["first","second"]}') | ||
|
|
||
| def test_array_insert(self): | ||
| self.assertEqual(Operator.array_insert(0, 'newItem'), '{"method":"arrayInsert","values":[0,"newItem"]}') | ||
|
|
||
| def test_array_remove(self): | ||
| self.assertEqual(Operator.array_remove('oldItem'), '{"method":"arrayRemove","values":["oldItem"]}') | ||
|
|
||
| def test_array_unique(self): | ||
| self.assertEqual(Operator.array_unique(), '{"method":"arrayUnique","values":[]}') | ||
|
|
||
| def test_array_intersect(self): | ||
| self.assertEqual(Operator.array_intersect(['a', 'b', 'c']), '{"method":"arrayIntersect","values":["a","b","c"]}') | ||
|
|
||
| def test_array_diff(self): | ||
| self.assertEqual(Operator.array_diff(['x', 'y']), '{"method":"arrayDiff","values":["x","y"]}') | ||
|
|
||
| def test_array_filter(self): | ||
| self.assertEqual(Operator.array_filter(Condition.EQUAL, 'test'), '{"method":"arrayFilter","values":["equal","test"]}') | ||
|
|
||
| def test_string_concat(self): | ||
| self.assertEqual(Operator.string_concat('suffix'), '{"method":"stringConcat","values":["suffix"]}') | ||
|
|
||
| def test_string_replace(self): | ||
| self.assertEqual(Operator.string_replace('old', 'new'), '{"method":"stringReplace","values":["old","new"]}') | ||
|
|
||
| def test_toggle(self): | ||
| self.assertEqual(Operator.toggle(), '{"method":"toggle","values":[]}') | ||
|
|
||
| def test_date_add_days(self): | ||
| self.assertEqual(Operator.date_add_days(7), '{"method":"dateAddDays","values":[7]}') | ||
|
|
||
| def test_date_sub_days(self): | ||
| self.assertEqual(Operator.date_sub_days(3), '{"method":"dateSubDays","values":[3]}') | ||
|
|
||
| def test_date_set_now(self): | ||
| self.assertEqual(Operator.date_set_now(), '{"method":"dateSetNow","values":[]}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import unittest | ||
|
|
||
| from appwrite.permission import Permission | ||
| from appwrite.role import Role | ||
|
|
||
| class TestPermissionMethods(unittest.TestCase): | ||
|
|
||
| def test_read(self): | ||
| self.assertEqual(Permission.read(Role.any()), 'read("any")') | ||
|
|
||
| def test_write(self): | ||
| self.assertEqual(Permission.write(Role.any()), 'write("any")') | ||
|
|
||
| def test_create(self): | ||
| self.assertEqual(Permission.create(Role.any()), 'create("any")') | ||
|
|
||
| def test_update(self): | ||
| self.assertEqual(Permission.update(Role.any()), 'update("any")') | ||
|
|
||
| def test_delete(self): | ||
| self.assertEqual(Permission.delete(Role.any()), 'delete("any")') |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.