snok / drf-openapi-tester

Test utility for validating OpenAPI documentation
https://github.com/snok/django-openapi-tester
BSD 3-Clause "New" or "Revised" License
119 stars 23 forks source link

Allow empty null response #258

Closed radekjg closed 2 years ago

radekjg commented 2 years ago

Empty response worked only if response.json returned something. But if a response data is not json-serializable schema tester raises an error.

codecov[bot] commented 2 years ago

Codecov Report

Merging #258 (a1f810c) into master (53e6b88) will not change coverage. The diff coverage is 100.0%.

@@           Coverage Diff           @@
##           master     #258   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files           8        8           
  Lines         476      476           
  Branches       96       96           
=======================================
  Hits          476      476           
Impacted Files Coverage Ξ”
openapi_tester/schema_tester.py 100.0% <100.0%> (ΓΈ)
sondrelg commented 2 years ago

Trying to review on a very small screen, so need some help understanding the changes made: do you want the library to support a case like this?

schema_tester = SchemaTester()

def my_test(client):
    response = client.get('api/v1/...')
    assert response.status_code == 204
    schema_tester.validate_response(response=response, ...)

will this change allow you to detect a missing response? I.e., will the test fail if response.data is missing and the schema documents an actual response?

Seems like a good change in general πŸ‘

radekjg commented 2 years ago

If schema documents a response, the if before (that gets the content key will fail because response content won't match the spec)

sondrelg commented 2 years ago

This looks good @radowit πŸ‘ Would you mind rebasing on master and updating the version in pyproject.toml to v2.0.1? I'll release a new version shortly after

sondrelg commented 2 years ago

Thanks @radowit!