Skip to content

Instantly share code, notes, and snippets.

@niccolomineo
Created October 26, 2025 12:02
Show Gist options
  • Save niccolomineo/a7b4b071efe23a74d0224763b31d1c03 to your computer and use it in GitHub Desktop.
Save niccolomineo/a7b4b071efe23a74d0224763b31d1c03 to your computer and use it in GitHub Desktop.
Quickly test Django endpoints locally
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