lmcgartland / graphene-file-upload

Enhances Graphene Django GraphQL Server for intuitive file uploads via GraphQL mutations.
MIT License
285 stars 49 forks source link

Generalize testing.file_graphql_query #68

Closed ku-mok closed 2 years ago

ku-mok commented 3 years ago

Generalized django.testing.file_graphql_query to other frameworks than Django

Background

Although graphene_file_upload.django.testing.file_graphql_query is imported in the example of testing for flask, as metioned in issue #59 , file_graphql_query depends on Django for using django.testing.Client as default argument. However, it seems almost all codes in file_graphql_query are not specialized for Django. The only point tightly coupled with Django is the argument structure of django.testing.Client.post method. Test client of other frameworks, such as flask.testing.FlaskClient or fastapi.testclinet.TestClient, also has post method, but their argument is slightly different from Django's one. Examples of differences are below.

Implements

All logics in file_graphql_query which are not coupled with Django ara moved into, testingbase.py, and client argument is changed into client_post argument. client_post argument is a function that abstracts post method of each frameworks' test client post methods. It receives endpoint, data, files, and headers. And testing.py for each frameworks(in /graphene_file_upload/django/testing and /graphene_file_upload/flask/testing) implements client_post using framework specific test client. I only implemented for only Django and Flask, but testingbase.file_graphql_query can be applicable for any other frameworks such as FastAPI.