Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/functions/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
tests: pytest
help::
@echo "Available commands"
@echo " help -- (default) print this message"

tests: mypy pytest
help::
@echo " tests -- run all tests for supabase_functions package"

pytest:
uv run --package supabase_functions pytest --cov=./ --cov-report=xml --cov-report=html -vv
help::
@echo " pytest -- run pytest on supabase_functions package"

mypy:
uv run --package supabase_functions mypy src/supabase_functions tests
help::
@echo " mypy -- run mypy on supabase_functions package"

unasync:
uv run --package supabase_functions run-unasync.py
help::
@echo " unasync -- invoke run-unasync.py helper"

build-sync: unasync
sed -i '0,/SyncMock, /{s/SyncMock, //}' tests/_sync/test_function_client.py
sed -i 's/SyncMock/Mock/g' tests/_sync/test_function_client.py
sed -i 's/SyncClient/Client/g' src/supabase_functions/_sync/functions_client.py tests/_sync/test_function_client.py
help::
@echo " build-sync -- generate _sync from _async implementation"

clean:
rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache
rm -f .coverage coverage.xml
help::
@echo " clean -- clean intermediary files"

build:
uv build --package supabase_functions
help::
@echo " build -- invoke uv build on supabase_functions package"
5 changes: 4 additions & 1 deletion src/functions/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ tests = [
lints = [
"unasync>=0.6.0",
"ruff >=0.12.1",
"pre-commit >=3.4,<5.0"
"pre-commit >=3.4,<5.0",
"python-lsp-server (>=1.12.2,<2.0.0)",
"pylsp-mypy (>=0.7.0,<0.8.0)",
"python-lsp-ruff (>=2.2.2,<3.0.0)",
]
dev = [{ include-group = "lints" }, {include-group = "tests" }]

Expand Down
2 changes: 1 addition & 1 deletion src/functions/run-unasync.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unasync
from pathlib import Path

paths = Path("src/functions").glob("**/*.py")
paths = Path("src/supabase_functions").glob("**/*.py")
tests = Path("tests").glob("**/*.py")

rules = (unasync._DEFAULT_RULE,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ async def _request(
headers: Optional[Dict[str, str]] = None,
json: Optional[Dict[Any, Any]] = None,
) -> Response:
user_data = {"data": json} if isinstance(json, str) else {"json": json}
response = await self._client.request(method, url, **user_data, headers=headers)

response = (
await self._client.request(method, url, data=json, headers=headers)
if isinstance(json, str)
else await self._client.request(method, url, json=json, headers=headers)
)
try:
response.raise_for_status()
except HTTPError as exc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ def _request(
headers: Optional[Dict[str, str]] = None,
json: Optional[Dict[Any, Any]] = None,
) -> Response:
user_data = {"data": json} if isinstance(json, str) else {"json": json}
response = self._client.request(method, url, **user_data, headers=headers)

response = (
self._client.request(method, url, data=json, headers=headers)
if isinstance(json, str)
else self._client.request(method, url, json=json, headers=headers)
)
try:
response.raise_for_status()
except HTTPError as exc:
Expand Down
Empty file.
13 changes: 6 additions & 7 deletions src/functions/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ def test_error_initialization(
error_class: Type[FunctionsError], expected_name: str, expected_status: int
):
test_message = "Test error message"

if error_class is FunctionsError:
if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)):
error: FunctionsError = error_class(test_message)
elif error_class is FunctionsError:
error = error_class(test_message, expected_name, expected_status)
else:
error = error_class(test_message)

assert str(error) == test_message
assert error.message == test_message
Expand All @@ -48,10 +47,10 @@ def test_error_to_dict(
):
test_message = "Test error message"

if error_class is FunctionsError:
if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)):
error: FunctionsError = error_class(test_message)
elif error_class is FunctionsError:
error = error_class(test_message, expected_name, expected_status)
else:
error = error_class(test_message)

error_dict = error.to_dict()

Expand Down