diff --git a/awx/main/tests/factories/tower.py b/awx/main/tests/factories/tower.py index 2a9d493efe..a72e1ac246 100644 --- a/awx/main/tests/factories/tower.py +++ b/awx/main/tests/factories/tower.py @@ -211,15 +211,38 @@ def create_job_template(name, **kwargs): job_type=job_type) 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 = {} + inventories = {} labels = {} notification_templates = {} persisted = kwargs.get('persisted', True) 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: for p in kwargs['projects']: if type(p) is Project: @@ -253,7 +276,8 @@ def create_organization(name, **kwargs): teams=_Mapped(teams), projects=_Mapped(projects), labels=_Mapped(labels), - notification_templates=_Mapped(notification_templates)) + notification_templates=_Mapped(notification_templates), + inventories=_Mapped(inventories)) def create_notification_template(name, **kwargs): Objects = namedtuple("Objects", "notification_template,organization,users,superusers,teams") diff --git a/awx/main/tests/functional/api/test_activity_streams.py b/awx/main/tests/functional/api/test_activity_streams.py index 43e809afb9..3bcb0f8264 100644 --- a/awx/main/tests/functional/api/test_activity_streams.py +++ b/awx/main/tests/functional/api/test_activity_streams.py @@ -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(team__pk=team.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'