Update auditor tests with tracker and activity logs subscription cases
-from unittest.mock import patch
-
# pylint:disable=ungrouped-imports
+from unittest.mock import patch
+
+import activitylogs
import auditor
import tracker
+from activitylogs import ActivityLogService
from clusters.models import Cluster
from event_manager.events.cluster import CLUSTER_CREATED
+from event_manager.events.user import USER_ACTIVATED
+from factories.factory_users import UserFactory
from tests.utils import BaseTest
from tracker.publisher import TrackerService
@@ -14,13 +18,27 @@ from tracker.publisher import TrackerService
class AuditorTest(BaseTest):
def setUp(self):
self.cluster = Cluster.load()
+ self.admin = UserFactory(is_staff=True, is_superuser=True)
+ self.user = UserFactory()
auditor.validate()
auditor.setup()
tracker.validate()
tracker.setup()
+ activitylogs.validate()
+ activitylogs.setup()
+
+ def test_record_calls_only_subscribed_services(self):
+ with patch.object(TrackerService, 'record_event') as mock_tracker_record:
+ with patch.object(ActivityLogService, 'record_event') as mock_activitylog_record:
+ auditor.record(event_type=USER_ACTIVATED,
+ instance=self.user,
+ actor_id=self.admin.id)
+
+ assert mock_tracker_record.call_count == 1
+ assert mock_activitylog_record.call_count == 1
- def test_record_calls_other_services(self):
- with patch.object(TrackerService, 'record_event') as mock_record:
+ with patch.object(TrackerService, 'record_event') as mock_tracker_record:
+ with patch.object(ActivityLogService, 'record_event') as mock_activitylog_record:
auditor.record(event_type=CLUSTER_CREATED,
instance=self.cluster,
namespace='test',
@@ -42,4 +60,5 @@ class AuditorTest(BaseTest):
memory=0,
gpu=0)
- assert mock_record.call_count == 1
+ assert mock_tracker_record.call_count == 1
+ assert mock_activitylog_record.call_count == 0
