Skip to content

Commit

Permalink
Assert bodies in sync tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Sep 23, 2024
1 parent f9aee3b commit e657b3d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/test_registration/cases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from . import (
base,
cloud_branch_env,
in_sync_invalid_sig,
in_sync_missing_sig,
in_band_invalid_sig,
in_band_missing_sig,
out_of_band,
server_kind_mismatch,
)

_modules = (
cloud_branch_env,
in_sync_invalid_sig,
in_sync_missing_sig,
in_band_invalid_sig,
in_band_missing_sig,
out_of_band,
server_kind_mismatch,
)
Expand Down
59 changes: 59 additions & 0 deletions tests/test_registration/cases/cloud_branch_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,65 @@ def fn(
str,
)

assert json.loads(res.body.decode("utf-8")) == {
"app_id": "flask-cloud_branch_env",
"env": "my-env",
"framework": "flask",
"functions": [
{
"batchEvents": None,
"cancel": None,
"concurrency": None,
"debounce": None,
"id": "flask-cloud_branch_env-foo",
"idempotency": None,
"name": "foo",
"priority": None,
"rateLimit": None,
"steps": {
"step": {
"id": "step",
"name": "step",
"retries": {"attempts": 0},
"runtime": {
"type": "http",
"url": "http://test.local?fnId=flask-cloud_branch_env-foo&stepId=step",
},
}
},
"throttle": None,
"triggers": [{"event": "app/foo", "expression": None}],
}
],
"inspection": {
"schema_version": "2024-05-24",
"api_origin": "https://api.inngest.com/",
"app_id": "flask-cloud_branch_env",
"authentication_succeeded": True,
"capabilities": {"in_band_sync": "v1", "trust_probe": "v1"},
"env": "my-env",
"event_api_origin": "https://inn.gs/",
"event_key_hash": None,
"framework": "flask",
"function_count": 1,
"has_event_key": False,
"has_signing_key": True,
"has_signing_key_fallback": False,
"mode": "cloud",
"sdk_language": "py",
"sdk_version": "0.4.13a1",
"serve_origin": None,
"serve_path": None,
"signing_key_fallback_hash": None,
"signing_key_hash": "709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c",
},
"platform": None,
"sdk_author": "inngest",
"sdk_language": "py",
"sdk_version": "0.4.13a1",
"url": "http://test.local",
}

return base.Case(
name=_TEST_NAME,
run_test=run_test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def fn(
assert res.headers["x-inngest-expected-server-kind"] == "cloud"
assert "x-inngest-sync-kind" not in res.headers

assert json.loads(res.body.decode("utf-8")) == {
"code": "sig_verification_failed",
"message": "",
"name": "SigVerificationFailedError",
}

return base.Case(
name=_TEST_NAME,
run_test=run_test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def fn(
assert res.headers["x-inngest-expected-server-kind"] == "cloud"
assert "x-inngest-sync-kind" not in res.headers

assert json.loads(res.body.decode("utf-8")) == {
"code": "header_missing",
"message": "cannot validate signature in production mode without a x-inngest-signature header",
"name": "HeaderMissingError",
}

return base.Case(
name=_TEST_NAME,
run_test=run_test,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_registration/cases/out_of_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def fn(
f"inngest-py:v{const.VERSION}"
]

assert json.loads(res.body.decode("utf-8")) == {}

return base.Case(
name=_TEST_NAME,
run_test=run_test,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_registration/cases/server_kind_mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ async def fn(
}
res = self.put(body={}, headers=headers)
assert res.status_code == 400
res_body = json.loads(res.body)
assert isinstance(res_body, dict)
assert (
res_body["code"] == server_lib.ErrorCode.SERVER_KIND_MISMATCH.value
)

assert json.loads(res.body.decode("utf-8")) == {
"code": "server_kind_mismatch",
"message": "Sync rejected since it's from a Dev Server but expected Cloud",
}

return base.Case(
name=_TEST_NAME,
Expand Down

0 comments on commit e657b3d

Please sign in to comment.