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

Tests: Improve test coverage 95.91% -> 98.30%. #862

Merged
merged 6 commits into from Jul 19, 2023

Conversation

onegreyonewhite
Copy link
Contributor

Changelog:

  • Add coverage report in review tests for Python 3.9.
  • Moved from runtime execution imports of validation methods.
  • Removed some old code constructions which never be executed.
  • Improved drf_yasg.inspectors.get_related_model() with dotted source.
  • Use get_paginated_response_schema() for paginators.
  • Test coverage up to 98%.
  • Fixed some bugs (RelatedFieldInspector return value, SaneYamlLoader was not used, etc).

@onegreyonewhite
Copy link
Contributor Author

@JoelLefkowitz As I promised)

Previous coverage:

Name                                                   Stmts   Miss Branch BrPart     Cover   Missing
-----------------------------------------------------------------------------------------------------
src/drf_yasg/__init__.py                                   5      0      0      0   100.00%
src/drf_yasg/app_settings.py                              23      0      4      0   100.00%
src/drf_yasg/codecs.py                                    94      7     20      1    92.98%   18, 22-25, 121->123, 209-210
src/drf_yasg/errors.py                                    10      0      6      0   100.00%
src/drf_yasg/generators.py                               273      8    124     10    95.47%   35-36, 67, 82->90, 218, 227, 241->244, 282, 483->478, 521, 526, 530->532
src/drf_yasg/inspectors/__init__.py                        9      0      0      0   100.00%
src/drf_yasg/inspectors/base.py                          150      0     58      0   100.00%
src/drf_yasg/inspectors/field.py                         370     15    176     14    94.32%   74-75, 191, 269-270, 274, 281-284, 300, 365->363, 499-500, 538->541, 591, 664->676, 666->676, 673->676, 685->690, 820-821
src/drf_yasg/inspectors/query.py                          52     16     20      1    62.50%   18-20, 54-58, 62-65, 73-88, 119->122
src/drf_yasg/inspectors/view.py                          177      1     70      2    98.79%   266, 337->341
src/drf_yasg/management/__init__.py                        0      0      0      0   100.00%
src/drf_yasg/management/commands/__init__.py               0      0      0      0   100.00%
src/drf_yasg/management/commands/generate_swagger.py      73      0     20      0   100.00%
src/drf_yasg/middleware.py                                16      0      2      0   100.00%
src/drf_yasg/openapi.py                                  366      4    108      3    98.10%   142, 277->279, 341, 690-692
src/drf_yasg/renderers.py                                 96      1     32      2    97.66%   98, 99->102
src/drf_yasg/utils.py                                    189      4    110      6    96.66%   332, 335-336, 357->355, 360->355, 432->434, 469
src/drf_yasg/views.py                                     72      1     12      2    96.43%   71->73, 75
-----------------------------------------------------------------------------------------------------
TOTAL                                                   1975     57    762     41    95.91%

Current local:

Name                                                   Stmts   Miss Branch BrPart     Cover   Missing
-----------------------------------------------------------------------------------------------------
src/drf_yasg/__init__.py                                   5      0      0      0   100.00%
src/drf_yasg/app_settings.py                              23      0      4      0   100.00%
src/drf_yasg/codecs.py                                    90      0     20      0   100.00%
src/drf_yasg/errors.py                                    10      0      6      0   100.00%
src/drf_yasg/generators.py                               273      0    124      2    99.50%   82->90, 530->532
src/drf_yasg/inspectors/__init__.py                        9      0      0      0   100.00%
src/drf_yasg/inspectors/base.py                          150      0     58      0   100.00%
src/drf_yasg/inspectors/field.py                         378      6    178      9    97.30%   307, 372->370, 506-507, 545->548, 598, 673->683, 680->683, 692->697, 827-828
src/drf_yasg/inspectors/query.py                          62      1     32      1    97.87%   19, 54->57
src/drf_yasg/inspectors/view.py                          177      1     70      2    98.79%   266, 337->341
src/drf_yasg/management/__init__.py                        0      0      0      0   100.00%
src/drf_yasg/management/commands/__init__.py               0      0      0      0   100.00%
src/drf_yasg/management/commands/generate_swagger.py      73      0     20      0   100.00%
src/drf_yasg/middleware.py                                16      0      2      0   100.00%
src/drf_yasg/openapi.py                                  366      4    108      3    98.10%   142, 277->279, 341, 690-692
src/drf_yasg/renderers.py                                 96      1     32      2    97.66%   98, 99->102
src/drf_yasg/utils.py                                    189      4    110      6    96.66%   332, 335-336, 357->355, 360->355, 432->434, 469
src/drf_yasg/views.py                                     72      1     12      2    96.43%   71->73, 75
-----------------------------------------------------------------------------------------------------
TOTAL                                                   1989     18    776     27    98.30%

This cover all critical parts of code.

I have never been able to come up with tests for some of the uncovered branches. But they don't seem to affect anything.

@JoelLefkowitz JoelLefkowitz merged commit 2548298 into axnsan12:1.21.x Jul 19, 2023
5 checks passed
@JoelLefkowitz
Copy link
Collaborator

Thanks @onegreyonewhite this is great

JoelLefkowitz pushed a commit that referenced this pull request Jul 20, 2023
* Add sample code to handle Base64 fields in drf-extra-fields project

* Fix format for .rst

* Update answer to the easier version as suggested in Hipo/drf-extra-fields#66 (comment)

* update readme.rst

`permission_classes` expects tuple but list was provided

* url from DEFAULT_API_URL now works

fix a bug: url from swagger_settings.DEFAULT_API_URL is not working

* Check for allow_null attribute

* Add utf-8 support for generated formats

* Added `many` support to example code.

* serialize pytz object as a string

* simplify if condition

* handle errors rendering with TemplateHTMLRenderer

This change fixes an `OPTIONS` request to the API page which will return
a successful response, but the `TemplateHTMLRender` will not be prepared
to render it since there is no template name provided in either the view
or response [1].

[1]: https://github.com/encode/django-rest-framework/blob/f0a5b958a134e8cd94e3ef3263e8fa623ac9b82f/rest_framework/renderers.py#L178-L189

* Allow specifying response as a reference

* [readme] Fix missing re_path import

* fix map source mapping

* Remove universal wheel, python 2 is unsupported

* Inline allow_unicode parameter

* Update changelog

* Update changelog typos

* Add cspell

* Fix old spelling errors

* Add ref_name to UserSerializer after removing suffix typo

* Set permission classes to a tuple

* Update chagnelog

* Add prepublish twine check

* Fix action version syntax

* Fix indentation in README.rst code blocks

* Add twine to publish dependencies

* Specify toxenv explicitly

* Specify all tox targets

* Add py prefix to toxenvs

* Update changelog

* Update changelog

* Declare Django 3.2 support in README, classifiers

This commit will make sure that `Django :: 3.2` will show up in the
classifiers list on PyPI: https://pypi.org/project/drf-yasg/

(The magic happens because we parse the README to get supported Django):
https://github.com/DavidCain/drf-yasg/blob/ee29412d3cdb311/setup.py#L36

3.2 support should already exist
================================
A closed pull request, #735,
noted support for Django 3.2 in both `tox.ini`, and the README.

That PR was closed in favor of
#741, which edited `tox.ini`
and switched to GitHub Actions.

#735 (comment)

This project has been testing on Django 3.2 for a long time (about a
year). I think we can declare it supported it the README!

* Fix `pip install` command for contributors on zsh

On `zsh` (a popular shell, and the default for macOS), install fails:

    $ pip install -U -e .[validation]
    zsh: no matches found: .[validation]

Quote the arguments so that `bash` or `zsh` will succeed.

* Dont use NullBooleanField if drf version >= 3.14.0

* Swap back BooleanField and NullBooleanField

* Update changelog

* Update README to use path instead of re_path in example

* Run tests with latest dependencies

- Django 4.0 & 4.1
- DRF 3.13 & 3.14
- Python 3.10

* Add python 3.10 in GH actions matrix

* Fix RecursiveField

* Change github actions runner from ubuntu-latest to ubuntu-20.04

* Change github actions runner from ubuntu-latest to ubuntu-20.04

* Remove python 3.6 tests since swagger-spec-validator no longer supports it

* Use a string literal for python versions such as "3.10"

* Add python 3.10 compatibility to README.md

* Update changelog

* Fix: Provide enums support for schema.

* Fix: Tests for Python 3.11.

* Refactoring: Removed old version code.

* Fix: Linting is now working.

* Fix: Provide usage of Enums as dict keys.

* Fix: Docs build with latest sphinx versions.

* keep path parameters in their given order

* Fix: Action build docs with latest tox version.

* Fix: Update python version for dj-master branch.

Django master branch bumped minimal python version
to Python 3.10. In latest version was added check for uniq basename.

* Feature: Migrate to PyYAML for yaml generator. (#845)

* Feature: Migrate to PyYAML for yaml generator.

Closes #833

* Chore: Update swagger ui and redoc dependencies.

* Fix: Remove required coreapi dependency. (#854)

* Feature: Migrate to PyYAML for yaml generator.

Closes #833

* Chore: Update swagger ui and redoc dependencies.

* Fix: Remove required coreapi dependency.

* Update Changelog

* Feature: Add ``drf_yasg.inspectors.query.DrfAPICompatInspector``. (#857)

* Feature: Provide to override default renderers via settings.

* Feature: Enable tests for django 4.2.

* Docs: Add information how to override ``DEFAULT_SPEC_RENDERERS``.

* Feature: Add ``drf_yasg.inspectors.query.DrfAPICompatInspector``.

This inspector should be main and replace ``CoreAPICompatInspector`` in the future.

* [fix] Fixed map source mapping (#859)

* Tests: Improve test coverage 95.91% -> 98.30%. (#862)

* Update Changelog

* Add python3.6 to the actions matrix but exclude it from tests

---------

Co-authored-by: Terry <wasin.th@gmail.com>
Co-authored-by: Sumit Singh <sumit.singh4613@gmail.com>
Co-authored-by: Core-Chan <i@coreja.com>
Co-authored-by: Krista Mae Rectra <krista.rectra@gmail.com>
Co-authored-by: mmurashov <m.murashov@ritm.media>
Co-authored-by: Christoph Beckmann <cbe@colibri-media.de>
Co-authored-by: MilanPecov <mpecov@yahoo.ca>
Co-authored-by: Terence D. Honles <terence@honles.com>
Co-authored-by: Cristi Vîjdea <cristi@cvjd.me>
Co-authored-by: Max Vorobev <vmax0770@gmail.com>
Co-authored-by: Damien Ramelet <damien.ramelet@protonmail.com>
Co-authored-by: Petr Dlouhý <petr.dlouhy@email.cz>
Co-authored-by: gopackgo90 <cbodendein@live.com>
Co-authored-by: David Cain <davidjosephcain@gmail.com>
Co-authored-by: Amir Andohkosh <4315615+amir-bio@users.noreply.github.com>
Co-authored-by: Nikolaos Michas <nikos.mixas@outlook.com>
Co-authored-by: Ignacio Orlandini <ignacioorlandini@gmail.com>
Co-authored-by: Sergey Klyuykov <onegreyonewhite@mail.ru>
Co-authored-by: Gagan Deep <the.one.above.all.titan@gmail.com>
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.

None yet

2 participants