From 87792cd518a5fbc57341bdb7c6d09e1fde12cb93 Mon Sep 17 00:00:00 2001 From: Sergei Kliuikov Date: Fri, 22 Nov 2024 11:23:27 -0800 Subject: [PATCH] Release 5.11.14 ### Changelog: - Fix(backend): Actions shouldn't be routed if they're None. --- test_src/test_proj/tests.py | 10 ++++++++++ test_src/test_proj/views.py | 3 +++ tox.ini | 3 ++- vstutils/__init__.py | 2 +- vstutils/api/base.py | 10 +++++----- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test_src/test_proj/tests.py b/test_src/test_proj/tests.py index ccfc41a1..27883d94 100644 --- a/test_src/test_proj/tests.py +++ b/test_src/test_proj/tests.py @@ -1923,6 +1923,16 @@ def test_openapi_schema_content(self): 'operations_availability', ) + # check None actions + self.assertNotIn( + 'delete', + api['paths']['/hosts_without_auth/{id}/'], + ) + self.assertNotIn( + 'delete', + api['paths']['/cacheable/{id}/host/{host_id}/'], + ) + # Check that's schema is correct and fields are working host_obj = self.get_model_class('test_proj.HostList').objects.create(name='123') results = self.bulk([ diff --git a/test_src/test_proj/views.py b/test_src/test_proj/views.py index 15e2666a..d6d3a5b2 100644 --- a/test_src/test_proj/views.py +++ b/test_src/test_proj/views.py @@ -265,6 +265,8 @@ def new_action_detail(self, request, *args, **kwargs): class HostCreateDummyMixin: + destroy = None + def create(self, request, *args, **kwargs): return responses.HTTP_201_CREATED("OK") @@ -285,6 +287,7 @@ def test_json_serializer(self, request, *_, **__): CacheableView = create_view(CachableProxyModel) +@nested_view('host', 'id', manager_name=lambda *_, **__: Host.objects.all(), view=HostWithoutAuthViewSet) class CacheableViewSet(CacheableView): def get_etag_value(self, model_class, request): return super().get_etag_value((model_class, gui_version), request) diff --git a/tox.ini b/tox.ini index 5a260062..3b465e14 100644 --- a/tox.ini +++ b/tox.ini @@ -46,12 +46,13 @@ allowlist_externals = yarn commands = pip uninstall vstutils -y + pip cache dir install: rm -rfv {envdir}/dist/ install: pip wheel {toxinidir} -w {envdir}/dist/ --no-deps install: bash -ec "pip install -U $(ls {envdir}/dist/*.whl | head -1)[all]" pwd install: python -m {env:EXECUTE_ARGS} {posargs} - coverage: pip install -U -e ..[all] + coverage: pip install -v -U -e ..[all] coverage: python -m test_proj makemigrations vstutils vstutils_api vstutils_webpush --check coverage: coverage erase --rcfile={env:COVRC} coverage: coverage run --rcfile={env:COVRC} {env:EXECUTE_ARGS} --durations 20 {posargs} diff --git a/vstutils/__init__.py b/vstutils/__init__.py index 8de3c6f7..69bf67f7 100644 --- a/vstutils/__init__.py +++ b/vstutils/__init__.py @@ -1,2 +1,2 @@ # pylint: disable=django-not-available -__version__: str = '5.11.13' +__version__: str = '5.11.14' diff --git a/vstutils/api/base.py b/vstutils/api/base.py index 4b7aa165..5f65c4c5 100644 --- a/vstutils/api/base.py +++ b/vstutils/api/base.py @@ -497,15 +497,15 @@ def get_view_methods(cls, detail=False): if methods is not None: return methods methods = [] - if not detail and hasattr(cls, 'create'): + if not detail and getattr(cls, 'create', None): methods.append('post') - if hasattr(cls, 'list') or hasattr(cls, 'retrieve'): + if getattr(cls, 'list', None) or getattr(cls, 'retrieve', None): methods.append('get') - if detail and hasattr(cls, 'update'): + if detail and getattr(cls, 'update', None): methods.append('put') - if detail and hasattr(cls, 'partial_update'): + if detail and getattr(cls, 'partial_update', None): methods.append('patch') - if detail and hasattr(cls, 'destroy'): + if detail and getattr(cls, 'destroy', None): methods.append('delete') setattr(cls, attr_name, methods) return methods