mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
move code linting to a stricter pep8-esque auto-formatting tool, black
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from awx.main.models import Organization, Project
|
||||
from awx.main.access import (
|
||||
NotificationTemplateAccess,
|
||||
NotificationAccess,
|
||||
JobTemplateAccess
|
||||
)
|
||||
from awx.main.access import NotificationTemplateAccess, NotificationAccess, JobTemplateAccess
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -70,10 +66,7 @@ def test_notification_template_access_superuser(notification_template_factory):
|
||||
@pytest.mark.parametrize("role", ["present.admin_role:admin", "present.notification_admin_role:admin"])
|
||||
def test_notification_template_access_admin(role, organization_factory, notification_template_factory):
|
||||
other_objects = organization_factory('other')
|
||||
present_objects = organization_factory('present',
|
||||
users=['admin'],
|
||||
notification_templates=['test-notification'],
|
||||
roles=[role])
|
||||
present_objects = organization_factory('present', users=['admin'], notification_templates=['test-notification'], roles=[role])
|
||||
|
||||
notification_template = present_objects.notification_templates.test_notification
|
||||
other_org = other_objects.organization
|
||||
@@ -133,30 +126,20 @@ def test_notification_access_system_admin(notification, admin):
|
||||
def test_system_auditor_JT_attach(system_auditor, job_template, notification_template):
|
||||
job_template.admin_role.members.add(system_auditor)
|
||||
access = JobTemplateAccess(system_auditor)
|
||||
assert not access.can_attach(
|
||||
job_template, notification_template, 'notification_templates_success',
|
||||
{'id': notification_template.id})
|
||||
assert not access.can_attach(job_template, notification_template, 'notification_templates_success', {'id': notification_template.id})
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("org_role,expect", [
|
||||
('admin_role', True),
|
||||
('notification_admin_role', True),
|
||||
('workflow_admin_role', False),
|
||||
('auditor_role', False),
|
||||
('member_role', False)
|
||||
])
|
||||
def test_org_role_JT_attach(rando, job_template, project, workflow_job_template, inventory_source,
|
||||
notification_template, org_role, expect):
|
||||
@pytest.mark.parametrize(
|
||||
"org_role,expect",
|
||||
[('admin_role', True), ('notification_admin_role', True), ('workflow_admin_role', False), ('auditor_role', False), ('member_role', False)],
|
||||
)
|
||||
def test_org_role_JT_attach(rando, job_template, project, workflow_job_template, inventory_source, notification_template, org_role, expect):
|
||||
nt_organization = Organization.objects.create(name='organization just for the notification template')
|
||||
notification_template.organization = nt_organization
|
||||
notification_template.save()
|
||||
getattr(notification_template.organization, org_role).members.add(rando)
|
||||
kwargs = dict(
|
||||
sub_obj=notification_template,
|
||||
relationship='notification_templates_success',
|
||||
data={'id': notification_template.id}
|
||||
)
|
||||
kwargs = dict(sub_obj=notification_template, relationship='notification_templates_success', data={'id': notification_template.id})
|
||||
permissions = {}
|
||||
expected_permissions = {}
|
||||
organization = Organization.objects.create(name='objective organization')
|
||||
@@ -178,44 +161,33 @@ def test_organization_NT_attach_permission(rando, notification_template):
|
||||
notification_template.organization.notification_admin_role.members.add(rando)
|
||||
target_organization = Organization.objects.create(name='objective organization')
|
||||
target_organization.workflow_admin_role.members.add(rando)
|
||||
assert not rando.can_access(Organization, 'attach', obj=target_organization, sub_obj=notification_template,
|
||||
relationship='notification_templates_success', data={})
|
||||
assert not rando.can_access(
|
||||
Organization, 'attach', obj=target_organization, sub_obj=notification_template, relationship='notification_templates_success', data={}
|
||||
)
|
||||
target_organization.auditor_role.members.add(rando)
|
||||
assert rando.can_access(Organization, 'attach', obj=target_organization, sub_obj=notification_template,
|
||||
relationship='notification_templates_success', data={})
|
||||
assert rando.can_access(
|
||||
Organization, 'attach', obj=target_organization, sub_obj=notification_template, relationship='notification_templates_success', data={}
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_project_NT_attach_permission(rando, notification_template):
|
||||
notification_template.organization.notification_admin_role.members.add(rando)
|
||||
project = Project.objects.create(
|
||||
name='objective project',
|
||||
organization=Organization.objects.create(name='foo')
|
||||
)
|
||||
project = Project.objects.create(name='objective project', organization=Organization.objects.create(name='foo'))
|
||||
project.update_role.members.add(rando)
|
||||
assert not rando.can_access(Project, 'attach', obj=project, sub_obj=notification_template,
|
||||
relationship='notification_templates_success', data={})
|
||||
assert not rando.can_access(Project, 'attach', obj=project, sub_obj=notification_template, relationship='notification_templates_success', data={})
|
||||
project.admin_role.members.add(rando)
|
||||
assert rando.can_access(Project, 'attach', obj=project, sub_obj=notification_template,
|
||||
relationship='notification_templates_success', data={})
|
||||
assert rando.can_access(Project, 'attach', obj=project, sub_obj=notification_template, relationship='notification_templates_success', data={})
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("res_role,expect", [
|
||||
('read_role', True),
|
||||
(None, False)
|
||||
])
|
||||
def test_object_role_JT_attach(rando, job_template, workflow_job_template, inventory_source,
|
||||
notification_template, res_role, expect):
|
||||
@pytest.mark.parametrize("res_role,expect", [('read_role', True), (None, False)])
|
||||
def test_object_role_JT_attach(rando, job_template, workflow_job_template, inventory_source, notification_template, res_role, expect):
|
||||
nt_organization = Organization.objects.create(name='organization just for the notification template')
|
||||
nt_organization.notification_admin_role.members.add(rando)
|
||||
notification_template.organization = nt_organization
|
||||
notification_template.save()
|
||||
kwargs = dict(
|
||||
sub_obj=notification_template,
|
||||
relationship='notification_templates_success',
|
||||
data={'id': notification_template.id}
|
||||
)
|
||||
kwargs = dict(sub_obj=notification_template, relationship='notification_templates_success', data={'id': notification_template.id})
|
||||
permissions = {}
|
||||
expected_permissions = {}
|
||||
|
||||
@@ -227,9 +199,7 @@ def test_object_role_JT_attach(rando, job_template, workflow_job_template, inven
|
||||
if res_role is None or hasattr(permission_resource, res_role):
|
||||
if res_role is not None:
|
||||
getattr(permission_resource, res_role).members.add(rando)
|
||||
permissions[model_name] = rando.can_access(
|
||||
resource.__class__, 'attach', resource, **kwargs
|
||||
)
|
||||
permissions[model_name] = rando.can_access(resource.__class__, 'attach', resource, **kwargs)
|
||||
expected_permissions[model_name] = expect
|
||||
else:
|
||||
permissions[model_name] = None
|
||||
|
||||
Reference in New Issue
Block a user