Skip to content

Commit e72b20e

Browse files
committed
[qa] Formatted code
1 parent c961730 commit e72b20e

File tree

7 files changed

+88
-88
lines changed

7 files changed

+88
-88
lines changed

openwisp_users/multitenancy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _has_org_permission(self, request, obj, perm_func):
6666
associated with specific organizations.
6767
"""
6868
perm = perm_func(request, obj)
69-
if not request.user.is_superuser and obj and hasattr(obj, 'organization_id'):
69+
if not request.user.is_superuser and obj and hasattr(obj, "organization_id"):
7070
perm = perm and (
7171
obj.organization_id
7272
and str(obj.organization_id) in request.user.organizations_managed
@@ -179,7 +179,7 @@ class MultitenantOrgFilter(AutocompleteFilter):
179179
title = _("organization")
180180
widget_attrs = AutocompleteFilter.widget_attrs.copy()
181181
widget_attrs.update(
182-
{"data-empty-label": SHARED_SYSTEMWIDE_LABEL, 'data-is-filter': 'true'}
182+
{"data-empty-label": SHARED_SYSTEMWIDE_LABEL, "data-is-filter": "true"}
183183
)
184184

185185

openwisp_users/tests/test_api/__init__.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,64 +25,64 @@ def _test_access_shared_object(
2525
expected_count=0,
2626
expected_status_codes=None,
2727
):
28-
auth = dict(HTTP_AUTHORIZATION=f'Bearer {token}')
28+
auth = dict(HTTP_AUTHORIZATION=f"Bearer {token}")
2929
create_payload = create_payload or {}
3030
update_payload = update_payload or {}
3131
expected_status_codes = expected_status_codes or {}
3232

3333
if listview_name or listview_path:
3434
listview_path = listview_path or reverse(listview_name)
35-
with self.subTest('HEAD and OPTION methods'):
35+
with self.subTest("HEAD and OPTION methods"):
3636
response = self.client.head(listview_path, **auth)
37-
self.assertEqual(response.status_code, expected_status_codes['head'])
37+
self.assertEqual(response.status_code, expected_status_codes["head"])
3838

3939
response = self.client.options(listview_path, **auth)
40-
self.assertEqual(response.status_code, expected_status_codes['option'])
40+
self.assertEqual(response.status_code, expected_status_codes["option"])
4141

42-
with self.subTest('Create shared object'):
42+
with self.subTest("Create shared object"):
4343
response = self.client.post(
4444
listview_path,
4545
data=create_payload,
46-
content_type='application/json',
46+
content_type="application/json",
4747
**auth,
4848
)
49-
self.assertEqual(response.status_code, expected_status_codes['create'])
50-
if expected_status_codes['create'] == 400:
49+
self.assertEqual(response.status_code, expected_status_codes["create"])
50+
if expected_status_codes["create"] == 400:
5151
self.assertEqual(
52-
str(response.data['organization'][0]),
53-
'This field may not be null.',
52+
str(response.data["organization"][0]),
53+
"This field may not be null.",
5454
)
5555

56-
with self.subTest('List all shared objects'):
56+
with self.subTest("List all shared objects"):
5757
response = self.client.get(listview_path, **auth)
58-
self.assertEqual(response.status_code, expected_status_codes['list'])
58+
self.assertEqual(response.status_code, expected_status_codes["list"])
5959
data = response.data
6060
if not isinstance(response.data, list):
61-
data = data.get('results', data)
61+
data = data.get("results", data)
6262
self.assertEqual(len(data), expected_count)
6363

6464
if detailview_name or detailview_path:
6565
if not detailview_path and listview_name and expected_count > 0:
66-
detailview_path = reverse(detailview_name, args=[data[0]['id']])
66+
detailview_path = reverse(detailview_name, args=[data[0]["id"]])
6767

68-
with self.subTest('Retrieve shared object'):
68+
with self.subTest("Retrieve shared object"):
6969
response = self.client.get(detailview_path, **auth)
7070
self.assertEqual(
71-
response.status_code, expected_status_codes['retrieve']
71+
response.status_code, expected_status_codes["retrieve"]
7272
)
7373

74-
with self.subTest('Update shared object'):
74+
with self.subTest("Update shared object"):
7575
response = self.client.put(
7676
detailview_path,
7777
data=update_payload,
78-
content_type='application/json',
78+
content_type="application/json",
7979
**auth,
8080
)
81-
self.assertEqual(response.status_code, expected_status_codes['update'])
81+
self.assertEqual(response.status_code, expected_status_codes["update"])
8282

83-
with self.subTest('Delete shared object'):
83+
with self.subTest("Delete shared object"):
8484
response = self.client.delete(detailview_path, **auth)
85-
self.assertEqual(response.status_code, expected_status_codes['delete'])
85+
self.assertEqual(response.status_code, expected_status_codes["delete"])
8686

8787
def _test_org_user_access_shared_object(
8888
self,
@@ -102,16 +102,16 @@ def _test_org_user_access_shared_object(
102102
"""
103103
if not token:
104104
user = self._create_administrator(organizations=[self._get_org()])
105-
token = self._obtain_auth_token(user.username, 'tester')
105+
token = self._obtain_auth_token(user.username, "tester")
106106
if not expected_status_codes:
107107
expected_status_codes = {
108-
'create': 400,
109-
'list': 200,
110-
'retrieve': 200,
111-
'update': 403,
112-
'delete': 403,
113-
'head': 200,
114-
'option': 200,
108+
"create": 400,
109+
"list": 200,
110+
"retrieve": 200,
111+
"update": 403,
112+
"delete": 403,
113+
"head": 200,
114+
"option": 200,
115115
}
116116
self._test_access_shared_object(
117117
token=token,
@@ -142,16 +142,16 @@ def _test_superuser_access_shared_object(
142142
"""
143143
if not token:
144144
user = self._create_admin()
145-
token = self._obtain_auth_token(user.username, 'tester')
145+
token = self._obtain_auth_token(user.username, "tester")
146146
if not expected_status_codes:
147147
expected_status_codes = {
148-
'create': 201,
149-
'list': 200,
150-
'retrieve': 200,
151-
'update': 200,
152-
'delete': 204,
153-
'head': 200,
154-
'option': 200,
148+
"create": 201,
149+
"list": 200,
150+
"retrieve": 200,
151+
"update": 200,
152+
"delete": 204,
153+
"head": 200,
154+
"option": 200,
155155
}
156156
self._test_access_shared_object(
157157
token=token,

openwisp_users/tests/utils.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from openwisp_users.multitenancy import SHARED_SYSTEMWIDE_LABEL
1010

11-
Organization = load_model('openwisp_users', 'Organization')
12-
OrganizationOwner = load_model('openwisp_users', 'OrganizationOwner')
13-
OrganizationUser = load_model('openwisp_users', 'OrganizationUser')
14-
Group = load_model('openwisp_users', 'Group')
11+
Organization = load_model("openwisp_users", "Organization")
12+
OrganizationOwner = load_model("openwisp_users", "OrganizationOwner")
13+
OrganizationUser = load_model("openwisp_users", "OrganizationUser")
14+
Group = load_model("openwisp_users", "Group")
1515
User = get_user_model()
1616

1717

@@ -264,8 +264,8 @@ def _test_org_admin_create_shareable_object(
264264
error_message = error_message or (
265265
'<div class="form-row errors field-organization">\n'
266266
' <ul class="errorlist"{}>'
267-
'<li>This field is required.</li></ul>'
268-
).format(' id="id_organization_error"' if django.VERSION >= (5, 2) else '')
267+
"<li>This field is required.</li></ul>"
268+
).format(' id="id_organization_error"' if django.VERSION >= (5, 2) else "")
269269
self.assertContains(response, error_message)
270270
self.assertEqual(model.objects.count(), expected_count)
271271

@@ -284,9 +284,9 @@ def _test_org_admin_view_shareable_object(
284284
expected_element = (
285285
'<div class="form-row field-organization">\n\n\n<div>\n\n'
286286
'<div class="flex-container">\n\n'
287-
'<label>Organization:</label>\n\n'
287+
"<label>Organization:</label>\n\n"
288288
'<div class="readonly">-</div>\n\n\n'
289-
'</div>\n\n</div>\n\n\n</div>'
289+
"</div>\n\n</div>\n\n\n</div>"
290290
)
291291
self.assertContains(response, expected_element, html=True)
292292

@@ -296,21 +296,21 @@ def _test_object_organization_fk_autocomplete_view(
296296
):
297297
app_label = model._meta.app_label
298298
model_name = model._meta.model_name
299-
path = self._get_autocomplete_view_path(app_label, model_name, 'organization')
299+
path = self._get_autocomplete_view_path(app_label, model_name, "organization")
300300
org = self._get_org()
301301
admin = User.objects.filter(is_superuser=True).first()
302302
if not admin:
303303
admin = self._create_admin()
304304
org_admin = self._create_administrator(organizations=[org])
305305

306-
with self.subTest('Org admin should only see their own org'):
306+
with self.subTest("Org admin should only see their own org"):
307307
self.client.force_login(org_admin)
308308
response = self.client.get(path)
309309
self.assertEqual(response.status_code, 200)
310310
self.assertContains(response, org.name)
311311
self.assertNotContains(response, SHARED_SYSTEMWIDE_LABEL)
312312

313-
with self.subTest('Superuser should see all orgs and shared label'):
313+
with self.subTest("Superuser should see all orgs and shared label"):
314314
self.client.force_login(admin)
315315
response = self.client.get(path)
316316
self.assertEqual(response.status_code, 200)
@@ -320,9 +320,9 @@ def _test_object_organization_fk_autocomplete_view(
320320
def _get_autocomplete_view_path(
321321
self, app_label, model_name, field_name, is_filter=False
322322
):
323-
path = reverse('admin:ow-auto-filter')
323+
path = reverse("admin:ow-auto-filter")
324324
return (
325-
f'{path}?app_label={app_label}'
326-
f'&model_name={model_name}&field_name={field_name}'
327-
'{}'.format('&is_filter=true' if is_filter else '')
325+
f"{path}?app_label={app_label}"
326+
f"&model_name={model_name}&field_name={field_name}"
327+
"{}".format("&is_filter=true" if is_filter else "")
328328
)

openwisp_users/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ def get_empty_label(self):
4343

4444
def get_allow_null(self):
4545
if self.object_list.model == Organization:
46-
return self.request.user.is_superuser or self.request.GET.get('is_filter')
46+
return self.request.user.is_superuser or self.request.GET.get("is_filter")
4747
return super().get_allow_null()

tests/testapp/tests/test_admin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def test_accounts_login(self):
4646

4747
class TestTemplateAdmin(TestMultitenantAdminMixin, TestCase):
4848
def _create_template(self, **kwargs):
49-
if 'organization' not in kwargs:
50-
kwargs['organization'] = self._get_org()
49+
if "organization" not in kwargs:
50+
kwargs["organization"] = self._get_org()
5151
options = {
52-
'name': 'test-template',
52+
"name": "test-template",
5353
}
5454
options.update(kwargs)
5555
template = Template(**options)
@@ -59,10 +59,10 @@ def _create_template(self, **kwargs):
5959

6060
def test_org_admin_create_shareable_template(self):
6161
self._test_org_admin_create_shareable_object(
62-
reverse('admin:testapp_template_add'),
62+
reverse("admin:testapp_template_add"),
6363
payload={
64-
'name': 'test-template',
65-
'organization': '',
64+
"name": "test-template",
65+
"organization": "",
6666
},
6767
model=Template,
6868
)
@@ -75,7 +75,7 @@ def test_template_organization_autocomplete_view(self):
7575
def test_org_admin_view_shared_template(self):
7676
template = self._create_template(organization=None)
7777
self._test_org_admin_view_shareable_object(
78-
reverse('admin:testapp_template_change', args=(template.id,)),
78+
reverse("admin:testapp_template_change", args=(template.id,)),
7979
)
8080

8181
def test_superuser_create_shareable_template(self):

tests/testapp/tests/test_permission_classes.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,20 @@ def test_view_django_model_permission_with_change_perm(self):
234234
def test_superuser_access_shared_object(self):
235235
self._test_superuser_access_shared_object(
236236
token=None,
237-
listview_name='test_template_list',
238-
detailview_name='test_template_detail',
239-
create_payload={'name': 'test', 'organization': ''},
240-
update_payload={'name': 'updated-test'},
237+
listview_name="test_template_list",
238+
detailview_name="test_template_detail",
239+
create_payload={"name": "test", "organization": ""},
240+
update_payload={"name": "updated-test"},
241241
expected_count=1,
242242
)
243243

244244
def test_org_manager_access_shared_object(self):
245245
template = self._create_template(organization=None)
246246
self._test_org_user_access_shared_object(
247-
listview_path=reverse('test_template_list'),
248-
detailview_path=reverse('test_template_detail', args=[template.pk]),
249-
create_payload={'name': 'test', 'organization': ''},
250-
update_payload={'name': 'updated-test'},
247+
listview_path=reverse("test_template_list"),
248+
detailview_path=reverse("test_template_detail", args=[template.pk]),
249+
create_payload={"name": "test", "organization": ""},
250+
update_payload={"name": "updated-test"},
251251
expected_count=1,
252252
)
253253

@@ -258,10 +258,10 @@ def test_org_owner_access_shared_object(self):
258258
token = self._obtain_auth_token(username=org_owner)
259259
template = self._create_template(organization=None)
260260
self._test_org_user_access_shared_object(
261-
listview_path=reverse('test_template_list'),
262-
detailview_path=reverse('test_template_detail', args=[template.pk]),
263-
create_payload={'name': 'test', 'organization': ''},
264-
update_payload={'name': 'updated-test'},
261+
listview_path=reverse("test_template_list"),
262+
detailview_path=reverse("test_template_detail", args=[template.pk]),
263+
create_payload={"name": "test", "organization": ""},
264+
update_payload={"name": "updated-test"},
265265
expected_count=1,
266266
token=token,
267267
)
@@ -275,10 +275,10 @@ def test_org_user_access_shared_object(self):
275275
self._create_org_user(user=user, is_admin=False)
276276
template = self._create_template(organization=None)
277277
self._test_org_user_access_shared_object(
278-
listview_path=reverse('test_template_list'),
279-
detailview_path=reverse('test_template_detail', args=[template.pk]),
280-
create_payload={'name': 'test', 'organization': ''},
281-
update_payload={'name': 'updated-test'},
278+
listview_path=reverse("test_template_list"),
279+
detailview_path=reverse("test_template_detail", args=[template.pk]),
280+
create_payload={"name": "test", "organization": ""},
281+
update_payload={"name": "updated-test"},
282282
expected_count=0,
283283
token=token,
284284
expected_status_codes={

tests/testapp/tests/test_selenium.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,24 @@ def test_organization_autocomplete_filter(self):
153153
The autocomplete_filter should show option to filter
154154
shared objects to non-superuser.
155155
"""
156-
path = reverse('admin:testapp_shelf_changelist')
157-
org1 = self._create_org(name='org1')
156+
path = reverse("admin:testapp_shelf_changelist")
157+
org1 = self._create_org(name="org1")
158158
administrator = self._create_administrator(
159-
organizations=[org1], username='tester', password='tester'
159+
organizations=[org1], username="tester", password="tester"
160160
)
161161
administrator.user_permissions.add(
162162
*Permission.objects.filter(
163-
Q(codename__contains='shelf') | Q(codename='view_organization')
164-
).values_list('id', flat=True),
163+
Q(codename__contains="shelf") | Q(codename="view_organization")
164+
).values_list("id", flat=True),
165165
)
166166
self._test_multitenant_autocomplete_org_field(
167167
path=path,
168-
username='tester',
169-
password='tester',
170-
visible=[org1.name, 'Shared systemwide (no organization)'],
168+
username="tester",
169+
password="tester",
170+
visible=[org1.name, "Shared systemwide (no organization)"],
171171
hidden=list(
172-
Organization.objects.exclude(id=org1.id).values_list('name', flat=True)
172+
Organization.objects.exclude(id=org1.id).values_list("name", flat=True)
173173
),
174-
select2_selector='#select2-id-organization-dal-filter-container',
174+
select2_selector="#select2-id-organization-dal-filter-container",
175175
)
176176
self.logout()

0 commit comments

Comments
 (0)