Skip to content

Commit 9e7cca4

Browse files
authored
chore(tests): fix failing tests (#563)
1 parent 8c552c7 commit 9e7cca4

File tree

4 files changed

+88
-62
lines changed

4 files changed

+88
-62
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ build_sync: run_unasync remove_pytest_asyncio_from_sync
3535

3636
remove_pytest_asyncio_from_sync:
3737
sed -i 's/@pytest.mark.asyncio//g' tests/_sync/test_client.py
38+
sed -i 's/_async/_sync/g' tests/_sync/test_client.py
39+
sed -i 's/Async/Sync/g' tests/_sync/test_client.py
3840

3941
sleep:
4042
sleep 2

poetry.lock

+37-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_async/test_client.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,30 @@ async def test_params_purged_after_execute(postgrest_client: AsyncPostgrestClien
8282

8383
@pytest.mark.asyncio
8484
async def test_response_status_code_outside_ok(postgrest_client: AsyncPostgrestClient):
85-
with pytest.raises(APIError) as exc_info:
86-
await postgrest_client.from_("test").select("a", "b").eq(
87-
"c", "d"
88-
).execute() # gives status_code = 400
89-
exc_response = exc_info.value.json()
90-
assert not exc_response.get("success")
91-
assert isinstance(exc_response.get("errors"), list)
92-
assert (
93-
isinstance(exc_response["errors"][0], dict)
94-
and "code" in exc_response["errors"][0]
95-
)
96-
assert exc_response["errors"][0].get("code") == 400
85+
with patch(
86+
"postgrest._async.request_builder.AsyncSelectRequestBuilder.execute",
87+
side_effect=APIError(
88+
{
89+
"message": "mock error",
90+
"code": "400",
91+
"hint": "mock",
92+
"details": "mock",
93+
"errors": [{"code": 400}],
94+
}
95+
),
96+
):
97+
with pytest.raises(APIError) as exc_info:
98+
await postgrest_client.from_("test").select("a", "b").eq(
99+
"c", "d"
100+
).execute() # gives status_code = 400
101+
exc_response = exc_info.value.json()
102+
assert not exc_response.get("success")
103+
assert isinstance(exc_response.get("errors"), list)
104+
assert (
105+
isinstance(exc_response["errors"][0], dict)
106+
and "code" in exc_response["errors"][0]
107+
)
108+
assert exc_response["errors"][0].get("code") == 400
97109

98110

99111
@pytest.mark.asyncio

tests/_sync/test_client.py

+25-13
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,35 @@ def test_params_purged_after_execute(postgrest_client: SyncPostgrestClient):
7979

8080

8181
def test_response_status_code_outside_ok(postgrest_client: SyncPostgrestClient):
82-
with pytest.raises(APIError) as exc_info:
83-
postgrest_client.from_("test").select("a", "b").eq(
84-
"c", "d"
85-
).execute() # gives status_code = 400
86-
exc_response = exc_info.value.json()
87-
assert not exc_response.get("success")
88-
assert isinstance(exc_response.get("errors"), list)
89-
assert (
90-
isinstance(exc_response["errors"][0], dict)
91-
and "code" in exc_response["errors"][0]
92-
)
93-
assert exc_response["errors"][0].get("code") == 400
82+
with patch(
83+
"postgrest._sync.request_builder.SyncSelectRequestBuilder.execute",
84+
side_effect=APIError(
85+
{
86+
"message": "mock error",
87+
"code": "400",
88+
"hint": "mock",
89+
"details": "mock",
90+
"errors": [{"code": 400}],
91+
}
92+
),
93+
):
94+
with pytest.raises(APIError) as exc_info:
95+
postgrest_client.from_("test").select("a", "b").eq(
96+
"c", "d"
97+
).execute() # gives status_code = 400
98+
exc_response = exc_info.value.json()
99+
assert not exc_response.get("success")
100+
assert isinstance(exc_response.get("errors"), list)
101+
assert (
102+
isinstance(exc_response["errors"][0], dict)
103+
and "code" in exc_response["errors"][0]
104+
)
105+
assert exc_response["errors"][0].get("code") == 400
94106

95107

96108
def test_response_maybe_single(postgrest_client: SyncPostgrestClient):
97109
with patch(
98-
"postgrest._async.request_builder.AsyncSingleRequestBuilder.execute",
110+
"postgrest._sync.request_builder.SyncSingleRequestBuilder.execute",
99111
side_effect=APIError(
100112
{"message": "mock error", "code": "400", "hint": "mock", "details": "mock"}
101113
),

0 commit comments

Comments
 (0)