From 4bf55ccea8a5518f58ea470bd4679e70f48cf359 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 20 Sep 2021 14:50:03 +0200 Subject: [PATCH 13/59] misc: fix len-as-condition pylint error (#56982) --- src/authentic2/api_views.py | 2 +- src/authentic2/middleware.py | 2 +- src/authentic2/views.py | 2 +- tests/test_api.py | 8 ++++---- tests/test_views.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index b2077fe4..98e3e1eb 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -1001,7 +1001,7 @@ class RoleMembershipsAPI(ExceptionHandlerMixin, APIView): except User.DoesNotExist: raise ValidationError(_('No known user for UUID %s') % entry['uuid']) - if not len(self.members) and request.method in ('POST', 'DELETE'): + if not self.members and request.method in ('POST', 'DELETE'): raise ValidationError(_('No valid user UUID')) def post(self, request, *args, **kwargs): diff --git a/src/authentic2/middleware.py b/src/authentic2/middleware.py index 056f8d3f..3235e43a 100644 --- a/src/authentic2/middleware.py +++ b/src/authentic2/middleware.py @@ -233,7 +233,7 @@ class DisplayMessageBeforeRedirectMiddleware(MiddlewareMixin): return response # Check if there is some messages to show storage = messages.get_messages(request) - if not len(storage): + if not storage: return response return utils_misc.redirect(request, 'continue', resolve=True, params={'next': url}) diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 6f4e7c6c..71f87f50 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -1496,7 +1496,7 @@ class DisplayMessageAndContinueView(TemplateView): self.only_info = True storage = messages.get_messages(request) - if not len(storage): + if not storage: return utils_misc.redirect(request, self.url, resolve=False) for message in storage: diff --git a/tests/test_api.py b/tests/test_api.py index b25dd92d..dde22e2f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -455,7 +455,7 @@ def test_api_users_list_search_text(app, superuser): resp = app.get('/api/users/?q=some') results = resp.json['results'] - assert not len(results) + assert len(results) == 0 def test_api_member_users_list_search_text(app, superuser, simple_role): @@ -1304,7 +1304,7 @@ def test_users_email(app, ou1, admin, user_ou1, mailoutbox): def test_api_delete_role(app, admin_ou1, role_ou1): app.authorization = ('Basic', (admin_ou1.username, admin_ou1.username)) app.delete(f'/api/roles/{role_ou1.uuid}/') - assert not len(Role.objects.filter(slug='role_ou1')) + assert not Role.objects.filter(slug='role_ou1').exists() assert_event('manager.role.deletion', user=admin_ou1, api=True, role_name=role_ou1.name) @@ -1338,7 +1338,7 @@ def test_api_patch_role_unauthorized(app, simple_user, role_ou1): app.patch_json(f'/api/roles/{role_ou1.uuid}/', params=role_data, status=404) role_ou1.refresh_from_db() assert role_ou1.slug == 'role_ou1' - assert not len(Role.objects.filter(slug='updated-role')) + assert not Role.objects.filter(slug='updated-role').exists() def test_api_put_role(app, admin_ou1, role_ou1, ou1): @@ -1484,7 +1484,7 @@ def test_api_post_role_unauthorized(app, simple_user, ou1): role_data = {'slug': 'mocca-manager', 'name': 'Mocca Manager', 'ou': 'ou1'} app.post_json('/api/roles/', params=role_data, status=403) - assert not len(Role.objects.filter(slug='mocca-manager')) + assert not Role.objects.filter(slug='mocca-manager').exists() def test_api_get_role_description(app, admin_rando_role, role_random): diff --git a/tests/test_views.py b/tests/test_views.py index ab8475d9..fdda5d3d 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -56,7 +56,7 @@ def test_password_change(app, simple_user): def test_account_delete(app, simple_user, mailoutbox): assert simple_user.is_active - assert not len(mailoutbox) + assert len(mailoutbox) == 0 page = login(app, simple_user, path=reverse('delete_account')) assert simple_user.email in page.text page.form.submit(name='submit').follow() @@ -80,7 +80,7 @@ def test_account_delete(app, simple_user, mailoutbox): def test_account_delete_when_logged_out(app, simple_user, mailoutbox): assert simple_user.is_active - assert not len(mailoutbox) + assert len(mailoutbox) == 0 page = login(app, simple_user, path=reverse('delete_account')) page.form.submit(name='submit').follow() assert len(mailoutbox) == 1 @@ -104,7 +104,7 @@ def test_account_delete_when_logged_out(app, simple_user, mailoutbox): def test_account_delete_by_other_user(app, simple_user, user_ou1, mailoutbox): assert simple_user.is_active assert user_ou1.is_active - assert not len(mailoutbox) + assert len(mailoutbox) == 0 page = login(app, simple_user, path=reverse('delete_account')) page.form.submit(name='submit').follow() assert len(mailoutbox) == 1 -- 2.30.2