-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
[Feature request] Add django-ninja
specific TestCase
#664
Comments
I think ninja has testing. Refer to
Yep this is really problematic..Would you like to do a PR ? Usually this is how i am currently handling testing from django.test import TestCase
from ninja.testing import TestClient
from apps.characters.models import CharacterModel
from apps.api.urls import api
class APITestCase(TestCase):
def setUp(self):
CharacterModel.objects.create(
mal_id=1, kitsu_id=1, anilist_id=1, name="Spike", name_kanji="", about="Hello"
)
def test_character_api_response_given_mal_id(self):
res = self.client.get("/api/v1/characters", {"mal_id": 1})
actual_data = res.json()
actual_items = actual_data["items"][0]
assert actual_items["id"] == 1
assert actual_items["kitsu_id"] == 1
assert actual_items["anilist_id"] == 1 references : |
Any update on official documentation for testing with Django-ninja? |
What features do folks want? Maybe I could work on this. Right now I write my tests very simplistically. I use django TestCase and post with content_type="application/json" I would guess features are:
My opinion would be to make something very small and nice and well documented. Avoid too many features. |
@bufke I came up with something custom for 2 items of this list when implementing the RealWorld Demo App for Django Ninja ( the helper is here and you can check one of the test files here) So I reimplemented those slightly differently as 2 PR, as we don't have exactly the same use case if it ends-up here:
Not sure if this is the right approach, but that's what I ended-up implementing myself in my repo. I'm really not sure we want to have those in Ninja though, I enjoy the framework because it's KISS, as that makes it easier to both learn and adapt to your needs... Anyway, I think splitting this issue into multiple PR to see what gets traction or not may be the right way to do |
Is your feature request related to a problem? Please describe.
A
django-ninja
specificTestCase
is needed. There are simply too many things to consider, when testing. Authentication is being one of them. CSRF tokens - another. It does not work as is (standardDjango
TestCase
fails with4xx
errors ).Describe the solution you'd like
TestCase
that does all heavy lifting.The text was updated successfully, but these errors were encountered: