Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

pytest - Django GraphQL Testing Images

I'm currently performing pytest to test my GraphQL mutations. In this case, I input a test image file to determine if it's working. The following is a sample test in which the SimpleUploadedFile object throws a not JSON serializable error. What could be the cause and how should I fix this?

@pytest.mark.django_db
class TestUploadImage:
    query = """
        mutation uploadImage($input: Upload!) {
          uploadImage(file: $input) {
            __typename
            ... on ResponseErrors {
              errors {
                __typename
                code
                message
              }
            }
            ... on Output {
              url
            }
          }
        }
    """

    file = SimpleUploadedFile(
        name='test_image.jpg',
        content=b'',
        content_type='image/jpeg'
    )

    input_data = {"file": file}

    def test_non_authenticated_request(self, user, client, client_query):
        response = client_query(
            self.query,
            op_name="uploadMessageImage",
            input_data=self.input_data,
        )

        # Verify that there were no unhandled exceptions
        content = json.loads(response.content)
        assert "errors" not in content

        # Verify that AuthenticationError is in the response data
        assert AuthenticationError.__name__ in str(response.content)
question from:https://stackoverflow.com/questions/65896227/django-graphql-testing-images

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...