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

feat: adding support for Django Ninja test client #33

Merged
merged 2 commits into from
Jun 10, 2024

Conversation

maticardenas
Copy link
Owner

@maticardenas maticardenas commented Apr 4, 2024

Context

As specified in Django Ninja documentation, despite being compatible with Django Test Client, using Django Ninja Test Client for Django Ninja APIs ends up being more efficient and faster. Adding therefore support for it in this PR, so that django ninja projects, which already use ninja test client, can switch smoothly to the new client added here.

Changes

  • Adding OpenAPINinjaClient, which extends ninja.testing.TestClient
  • Adding GenericRequest class and adapting schema tester to be compatible with both Django a Django Ninja test clients.
  • Adding decorator for serializing json payloads for Django Test Client, as code was repetitive in each method.

@maticardenas maticardenas self-assigned this Apr 4, 2024
@maticardenas maticardenas linked an issue Apr 4, 2024 that may be closed by this pull request
@maticardenas maticardenas force-pushed the 31-add-django-ninja-test-client branch 2 times, most recently from 72c78a1 to 00a0362 Compare April 4, 2024 15:21
@danut-t
Copy link
Collaborator

danut-t commented Apr 4, 2024

Sorry for invading your PR like this, but I didn't know where to request this 😬. When you have the time, could you create a release for the master? 🙏 (also maybe enabling the Discussions tab would be nice for handling this kind of communication)

@maticardenas maticardenas force-pushed the 31-add-django-ninja-test-client branch from 00a0362 to af18602 Compare April 4, 2024 16:25
@maticardenas
Copy link
Owner Author

maticardenas commented Apr 4, 2024

Sorry for invading your PR like this, but I didn't know where to request this 😬. When you have the time, could you create a release for the master? 🙏 (also maybe enabling the Discussions tab would be nice for handling this kind of communication)

Hi @danut-t, just triggered 1.3.1 release 🚀
Also, enabled discussions tab as suggested. Thanks!

@maticardenas maticardenas force-pushed the 31-add-django-ninja-test-client branch 3 times, most recently from 5454e18 to 2b4f982 Compare April 14, 2024 09:50
@maticardenas maticardenas requested a review from danut-t May 5, 2024 10:38
@maticardenas maticardenas force-pushed the 31-add-django-ninja-test-client branch from 2b4f982 to 7a1c573 Compare June 10, 2024 16:28
@maticardenas maticardenas force-pushed the 31-add-django-ninja-test-client branch from 7a1c573 to c18e928 Compare June 10, 2024 16:32
@maticardenas maticardenas merged commit a2d6691 into master Jun 10, 2024
14 checks passed
@StopMotionCuber
Copy link

Hey, this MR broke my pipeline, as I do not use django ninja but it's imported during my import:

from openapi_tester import SchemaTester

See also the following output:

$ pytest --color=yes --junitxml=report.xml test/
ImportError while loading conftest '/builds/hps/software/jscldap/jumo-django/test/conftest.py'.
test/conftest.py:13: in <module>
    from openapi_tester import SchemaTester
/usr/local/lib/python3.12/site-packages/openapi_tester/__init__.py:4: in <module>
    from .clients import OpenAPIClient
/usr/local/lib/python3.12/site-packages/openapi_tester/clients.py:9: in <module>
    from ninja import NinjaAPI, Router
E   ModuleNotFoundError: No module named 'ninja'

It would be good if an optional import would be done here and to not fail if django-ninja is not installed.

Of course, a few workarounds are possible, e.g. installing django-ninja during our CI or pinning the version to <1.4.0, but it would be nice having this fixed on the library level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Django Ninja Test Client
3 participants