You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The patching of get with stubTreq.get is also janky, since you'd have to patch the other methods, to, so there's some thinking let to do there. (Fixing #244 would help, I suspect.)
This allows one to write a test like the example below, where one can read it and maybe understand what the values are, and you don't have to normalize a method name that should be text to lowercase (?!) bytes, etc.
deftest_ping_noToken(self) ->None:
""" Ping when a token is not present does not send an Authorization header. """client=Client()
expectedRequestsAndResponses=ExpectedRequestsAndResponses(
(
(
ExpectedRequest(
method="GET",
url=client._endpoint.api,
headers=Headers({
"Connection": ["close"],
"Accept-Encoding": ["gzip"],
"Host": ["registry-1.docker.io"],
}),
body=b"",
),
CannedResponse(
code=UNAUTHORIZED,
headers=Headers({
"WWW-Authenticate": [
'Bearer realm="foo",service="bar"'
],
}),
body=b"",
),
),
),
exceptionClass=self.failureException,
)
withexpectedRequestsAndResponses.testing():
self.successResultOf(client.ping())
The text was updated successfully, but these errors were encountered:
Indeed, the tuples are bad. I've found wrapping treq.testing in a "builder" class works really well — the builder can make the test pretty succinct and also check that the types are reasonable (i.e. #191).
Sequences of tuples in
treq.testing
are a terrible idea. Some classes with names attributes would be more appropriate.Here's an attempt at that:
The patching of
get
withstubTreq.get
is also janky, since you'd have to patch the other methods, to, so there's some thinking let to do there. (Fixing #244 would help, I suspect.)This allows one to write a test like the example below, where one can read it and maybe understand what the values are, and you don't have to normalize a method name that should be text to lowercase (?!) bytes, etc.
The text was updated successfully, but these errors were encountered: