Created
October 26, 2025 12:02
-
-
Save niccolomineo/a7b4b071efe23a74d0224763b31d1c03 to your computer and use it in GitHub Desktop.
Quickly test Django endpoints locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth import get_user_model | |
| from django.test import Client | |
| def call_endpoint(url: str, verb: str, credentials: dict | None): | |
| """Call the endpoint providing a url, a verb and optional credentials.""" | |
| client = Client() | |
| if credentials is not None: | |
| user = get_user_model().objects.get(**credentials) | |
| client.force_login(user) | |
| return getattr(client, verb)(url, SERVER_NAME="localhost") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment