From d687ff1be084053f08b5e58a895638bb0925c502 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 15 Feb 2017 15:34:14 -0500 Subject: [PATCH 1/2] delete disable_signals fixture that is not being used --- awx/main/tests/functional/conftest.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index 165dfed0d6..3d79ca4c4c 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -56,15 +56,6 @@ def clear_cache(): cache.clear() -@pytest.fixture(scope="session", autouse=False) -def disable_signals(): - ''' - Disable all django model signals. - ''' - mocked = mock.patch('django.dispatch.Signal.send', autospec=True) - mocked.start() - - @pytest.fixture(scope="session", autouse=True) def celery_memory_broker(): ''' From d67dadd64961746adbad97cae158a7eebc8344f4 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 16 Feb 2017 09:44:45 -0500 Subject: [PATCH 2/2] avoid activity stream entries of singleton implicit role associations --- awx/main/signals.py | 12 ++++++++++-- .../tests/functional/models/test_activity_stream.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 awx/main/tests/functional/models/test_activity_stream.py diff --git a/awx/main/signals.py b/awx/main/signals.py index ceda8899b1..d0df7fc2a2 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -180,8 +180,16 @@ def rbac_activity_stream(instance, sender, **kwargs): elif sender.__name__ == 'Role_parents': role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first() # don't record implicit creation / parents - if role is not None and role.content_type is not None: - parent = role.content_type.name + "." + role.role_field + if role is not None: + if role.content_type is None: + if role.is_singleton(): + parent = 'singleton:' + role.singleton_name + else: + # Ill-defined role, may need additional logic in the + # case of future expansions of the RBAC system + parent = str(role.role_field) + else: + parent = role.content_type.name + "." + role.role_field # Get the list of implicit parents that were defined at the class level. # We have to take this list from the class property to avoid including parents # that may have been added since the creation of the ImplicitRoleField diff --git a/awx/main/tests/functional/models/test_activity_stream.py b/awx/main/tests/functional/models/test_activity_stream.py new file mode 100644 index 0000000000..b6e63a4377 --- /dev/null +++ b/awx/main/tests/functional/models/test_activity_stream.py @@ -0,0 +1,13 @@ +import pytest + +# AWX models +from awx.main.models.organization import Organization +from awx.main.models import ActivityStream + + + +@pytest.mark.django_db +def test_activity_stream_create_entries(): + Organization.objects.create(name='test-organization2') + assert ActivityStream.objects.filter(organization__isnull=False).count() == 1 +