resolve payer: read the response's JSON (the stub hid this)
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/push/woodpecker Pipeline was canceled
_oc_graphql_post returns the RESPONSE — it is a retrying wrapper around client.post — so fetch_account_by_slug has to call .json() on it. My unit test stubbed it as a dict, so the test passed and the first live call in the container died with "Response object has no attribute get". The test now stubs the real shape (a response wrapper with .json()). Folding it in here rather than hiding it: a stub that does not match the real return shape certifies nothing.
This commit is contained in:
1 parent
cbf5a6870b
commit
9c10e627fc
2 files changed
+19
-3
No files matched your search
+6
-1
@@ -7414,7 +7414,12 @@ async def fetch_account_by_slug(slug: str) -> dict | None:
|
|||||||
"... on Individual { email isIncognito } } }")
|
"... on Individual { email isIncognito } } }")
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||||
data = await _oc_graphql_post(client, {"query": query, "variables": {"slug": slug}})
|
# _oc_graphql_post returns the RESPONSE (it is a retrying wrapper
|
||||||
|
# around client.post), so the JSON is read here. Getting this wrong
|
||||||
|
# is invisible to a stubbed test and fatal in the container: the
|
||||||
|
# first live run raised 'Response object has no attribute get'.
|
||||||
|
resp = await _oc_graphql_post(client, {"query": query, "variables": {"slug": slug}})
|
||||||
|
data = resp.json()
|
||||||
except Exception as e: # read failure: report, never raise
|
except Exception as e: # read failure: report, never raise
|
||||||
logger.warning("OC account lookup failed for slug %s: %s", slug, e)
|
logger.warning("OC account lookup failed for slug %s: %s", slug, e)
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -49,10 +49,21 @@ def check(cond, msg):
|
|||||||
REAL_POST = m._oc_graphql_post
|
REAL_POST = m._oc_graphql_post
|
||||||
|
|
||||||
|
|
||||||
|
class FakeResponse:
|
||||||
|
"""Mirror httpx.Response: the REAL _oc_graphql_post returns a response, not
|
||||||
|
parsed JSON. An earlier stub returned a dict, the test passed, and the first
|
||||||
|
live call died with 'Response object has no attribute get' — a stub that does
|
||||||
|
not match the real return shape certifies nothing."""
|
||||||
|
def __init__(self, payload):
|
||||||
|
self._payload = payload
|
||||||
|
def json(self):
|
||||||
|
return self._payload
|
||||||
|
|
||||||
|
|
||||||
def fake_post(payload):
|
def fake_post(payload):
|
||||||
"""Stand in for OC's GraphQL endpoint."""
|
"""Stand in for OC's GraphQL endpoint (the response wrapper, not the JSON)."""
|
||||||
async def _post(client, json_body, headers=None, attempts=2):
|
async def _post(client, json_body, headers=None, attempts=2):
|
||||||
return payload
|
return FakeResponse(payload)
|
||||||
return _post
|
return _post
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user