mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 02:17:37 -02:30
tests for object2 type when it is a role
This commit is contained in:
@@ -211,15 +211,38 @@ def create_job_template(name, **kwargs):
|
|||||||
job_type=job_type)
|
job_type=job_type)
|
||||||
|
|
||||||
def create_organization(name, **kwargs):
|
def create_organization(name, **kwargs):
|
||||||
Objects = namedtuple("Objects", "organization,teams,users,superusers,projects,labels,notification_templates")
|
artifacts = [
|
||||||
|
"organization",
|
||||||
|
"teams",
|
||||||
|
"users",
|
||||||
|
"superusers",
|
||||||
|
"projects",
|
||||||
|
"labels",
|
||||||
|
"notification_templates",
|
||||||
|
"inventories",
|
||||||
|
]
|
||||||
|
|
||||||
|
for k in kwargs.keys():
|
||||||
|
if k not in artifacts:
|
||||||
|
raise RuntimeError('{} is not a valid argument'.format(k))
|
||||||
|
|
||||||
|
Objects = namedtuple("Objects", ",".join(artifacts))
|
||||||
|
|
||||||
projects = {}
|
projects = {}
|
||||||
|
inventories = {}
|
||||||
labels = {}
|
labels = {}
|
||||||
notification_templates = {}
|
notification_templates = {}
|
||||||
persisted = kwargs.get('persisted', True)
|
persisted = kwargs.get('persisted', True)
|
||||||
|
|
||||||
org = mk_organization(name, '%s-desc'.format(name), persisted=persisted)
|
org = mk_organization(name, '%s-desc'.format(name), persisted=persisted)
|
||||||
|
|
||||||
|
if 'inventories' in kwargs:
|
||||||
|
for i in kwargs['inventories']:
|
||||||
|
if type(i) is Inventory:
|
||||||
|
inventories[i.name] = i
|
||||||
|
else:
|
||||||
|
inventories[i] = mk_inventory(i, organization=org, persisted=persisted)
|
||||||
|
|
||||||
if 'projects' in kwargs:
|
if 'projects' in kwargs:
|
||||||
for p in kwargs['projects']:
|
for p in kwargs['projects']:
|
||||||
if type(p) is Project:
|
if type(p) is Project:
|
||||||
@@ -253,7 +276,8 @@ def create_organization(name, **kwargs):
|
|||||||
teams=_Mapped(teams),
|
teams=_Mapped(teams),
|
||||||
projects=_Mapped(projects),
|
projects=_Mapped(projects),
|
||||||
labels=_Mapped(labels),
|
labels=_Mapped(labels),
|
||||||
notification_templates=_Mapped(notification_templates))
|
notification_templates=_Mapped(notification_templates),
|
||||||
|
inventories=_Mapped(inventories))
|
||||||
|
|
||||||
def create_notification_template(name, **kwargs):
|
def create_notification_template(name, **kwargs):
|
||||||
Objects = namedtuple("Objects", "notification_template,organization,users,superusers,teams")
|
Objects = namedtuple("Objects", "notification_template,organization,users,superusers,teams")
|
||||||
|
|||||||
@@ -131,3 +131,22 @@ def test_stream_queryset_hides_shows_items(
|
|||||||
assert queryset.filter(host__pk=host.pk, operation='create').count() == 1
|
assert queryset.filter(host__pk=host.pk, operation='create').count() == 1
|
||||||
assert queryset.filter(team__pk=team.pk, operation='create').count() == 1
|
assert queryset.filter(team__pk=team.pk, operation='create').count() == 1
|
||||||
assert queryset.filter(notification_template__pk=notification_template.pk, operation='create').count() == 1
|
assert queryset.filter(notification_template__pk=notification_template.pk, operation='create').count() == 1
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_stream_user_direct_role_updates(get, post, organization_factory):
|
||||||
|
objects = organization_factory('test_org',
|
||||||
|
superusers=['admin'],
|
||||||
|
users=['test'],
|
||||||
|
inventories=['inv1'])
|
||||||
|
|
||||||
|
url = reverse('api:user_roles_list', args=(objects.users.test.pk,))
|
||||||
|
post(url, dict(id=objects.inventories.inv1.read_role.pk), objects.superusers.admin)
|
||||||
|
|
||||||
|
activity_stream = ActivityStream.objects.filter(
|
||||||
|
inventory__pk=objects.inventories.inv1.pk,
|
||||||
|
user__pk=objects.users.test.pk).first()
|
||||||
|
url = reverse('api:activity_stream_detail', args=(activity_stream.pk,))
|
||||||
|
response = get(url, objects.users.test)
|
||||||
|
|
||||||
|
assert response.data['object1'] == 'user'
|
||||||
|
assert response.data['object2'] == 'inventory'
|
||||||
|
|||||||
Reference in New Issue
Block a user