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
but no luck, mypy warns of [import-not-found] for django_stubs.test.client, while the example with TypedModel from README works, so my configuration seems to be ok.
I suppose it is some kind of private type I'm not supposed to use, but what should I use instead?
that's how I'm using it, if that'll help 👀
classFormTestCase(TestCase):
# I know that assertFormError exists, but it requires a fieldname, and that's# a weird limitation imo, so here's my version instead.defassertFormContainsErrorCode(
self, response, error_code: str
):
"""Check that form errors contain the error with error_code"""form: Form=response.context["form"]
errors=form.errors.get_json_data()
# flatmap and find the code for each message for each field# NOTE: eagerly evaluate the iterable for better error messages, but# it'd work without it as wellerror_codes=list(
map(lambdae: e["code"], chain.from_iterable(errors.values()))
)
self.assertIn(error_code, error_codes)
The text was updated successfully, but these errors were encountered:
juliancoffee
changed the title
How do I write typehint test response?
How do I write a type hint for a test Response?
Jan 21, 2025
Hi, first of all, thank you for this awesome project, but I have some questions.
I see there's _MonkeyPatchedWSGIResponse, but I've no idea how I'm supposed to use it
I tried
but no luck, mypy warns of
[import-not-found]
fordjango_stubs.test.client
, while the example with TypedModel from README works, so my configuration seems to be ok.I suppose it is some kind of private type I'm not supposed to use, but what should I use instead?
that's how I'm using it, if that'll help 👀
The text was updated successfully, but these errors were encountered: