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

Generalize testing.file_graphql_query #68

Closed
wants to merge 4 commits into from

Conversation

ku-mok
Copy link

@ku-mok ku-mok commented Sep 18, 2021

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.

  • In Django data is a positional argument but in Flask data is a keyword argument.
  • In Django and Flask, files should be contain data argument, but in FastApi files is separated argument (Not client.post("/graphql", data=data) but client.post("/graphql", data=data, files=files) works)
    It would be useful to modify file_graphql_query to be able to absorb framework's test client differences.

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.

pass
class GraphQLFileUploadTestCase(testingbase.GraphQLFileUploadTestMixin, TestCase):
def setUp(self) -> None:
self.client_post = create_client_post(self.client)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll argue that a base class shouldn't implement a setUp method.

@ku-mok ku-mok closed this Apr 11, 2022
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.

2 participants