def test_get_event_object_context(self): mock_object = MagicMock() event_spec = EventItemContextSpec(None, None, None) assert event_context.get_event_object_context( None, 'event_type') == event_spec # Experiment mock_object.id = 1 mock_object.unique_name = 'user.project.1' event_spec = EventItemContextSpec( mock_object.unique_name, 'app{}'.format(get_experiment_url(mock_object.unique_name)), 1) assert event_context.get_event_object_context( mock_object, 'experiment') == event_spec # Experiment inside group mock_object.unique_name = 'user.project.2.1' event_spec = EventItemContextSpec( mock_object.unique_name, 'app{}'.format(get_experiment_url(mock_object.unique_name)), 1) assert event_context.get_event_object_context( mock_object, 'experiment') == event_spec # Experiment group mock_object.unique_name = 'user.project.1' event_spec = EventItemContextSpec( mock_object.unique_name, 'app{}'.format(get_experiment_group_url(mock_object.unique_name)), 1) assert event_context.get_event_object_context( mock_object, 'experiment_group') == event_spec # Job mock_object.unique_name = 'user.project.1' event_spec = EventItemContextSpec( mock_object.unique_name, 'app{}'.format(get_job_url(mock_object.unique_name)), 1) assert event_context.get_event_object_context(mock_object, 'job') == event_spec # Project mock_object.unique_name = 'user.project' event_spec = EventItemContextSpec( mock_object.unique_name, 'app{}'.format(get_project_url(mock_object.unique_name)), 1) assert event_context.get_event_object_context(mock_object, 'project') == event_spec
def build_attachment(event): logo_url = '' # TODO: add logo url text = build_attachment_text(event) or '' fields = [] # Use build_field event_object_context = event_context.get_event_object_context( event_content_object=event.instance, event_type=event.event_type) ts = event.created_at if event: event_ts = event.datetime ts = max(ts, event_ts) payload = { 'fallback': u'[{}] {}', 'title': build_attachment_title(event), 'title_link': add_notification_referrer_param(event_object_context.url, 'slack'), 'text': text, 'fields': fields, 'mrkdwn_in': ['text'], 'footer_icon': logo_url, 'footer': get_footer(), 'color': EventColor.get_for_event(event_content_object=event.instance, event_type=event.event_type), } if ts: payload['ts'] = to_timestamp(ts)
def get_object_name(self, obj): return event_context.get_event_object_context( event_content_object=obj.content_object, event_type=obj.event_type).name
def get_object_name(self, obj: 'ActivityLog') -> str: return event_context.get_event_object_context( event_content_object=obj.content_object, event_type=obj.event_type).name