Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mix django unittest client and ninja unittest api to start a custom d… #8

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions tests/testcase.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from django.test import TestCase
from django.test import TestCase, Client
from main.api import api
from django.contrib.auth import get_user_model
from ninja.testing import TestClient


class NinjaClient(Client, TestClient):
pass


class NinjaTestCase(TestCase):
client_class = NinjaClient

def create_client_helper(self):
"""Create test user and log them to dedicated client."""
self.user = get_user_model().objects.create_user(
Expand All @@ -12,9 +19,9 @@ def create_client_helper(self):
self.admin_user = get_user_model().objects.create_superuser(
username="admin", password="admin"
)
self.user_client = self.client_class()
self.user_client = self.client_class(api)
self.user_client.force_login(self.user)
self.admin_client = self.client_class()
self.admin_client = self.client_class(api)
self.admin_client.force_login(self.admin_user)

def link_api_helper(self):
Expand Down