Open barseghyanartur opened 1 year ago
I think ninja has testing.
Refer to ninja.testing
Proper documentation on testing (ATM - massively missing).
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:
Maybe a DRF-style .data attribute for response json response? I could go either way on this. It would make converting DRF to ninja easier. It's not that hard to use json().
: #1260 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.