def test_hosts_are_counted_once(self): mock_event = ProjectUpdateEvent( **{ 'event': 'playbook_on_stats', 'event_data': { 'skipped': { 'localhost': 2, 'fiz': 1, }, 'ok': { 'localhost': 1, 'foo': 2, }, 'changed': { 'localhost': 1, 'bar': 3, }, 'dark': { 'localhost': 2, 'fiz': 2, }, }, }) assert mock_event.get_host_status_counts() == { 'ok': 1, 'changed': 1, 'dark': 2 }
def test_project_update_event_websocket_notifications(emit, project): pu = ProjectUpdate(id=123, project=project) pu.save() ProjectUpdateEvent.create_from_data(project_update_id=pu.pk) assert len(emit.call_args_list) == 1 topic, payload = emit.call_args_list[0][0] assert topic == 'project_update_events-123' assert payload['project_update'] == 123
def test_hosts_are_counted_once(self, project_update, mocker): mock_event = ProjectUpdateEvent( **{ 'event': 'playbook_on_stats', 'event_data': { 'skipped': { 'localhost': 2, 'fiz': 1, }, 'ok': { 'localhost': 1, 'foo': 2, }, 'changed': { 'localhost': 1, 'bar': 3, }, 'dark': { 'localhost': 2, 'fiz': 2, } } }) mock_qs = namedtuple('mock_qs', ['get'])( mocker.MagicMock(return_value=mock_event)) project_update.project_update_events.only = mocker.MagicMock( return_value=mock_qs) serializer = ProjectUpdateDetailSerializer() host_status_counts = serializer.get_host_status_counts(project_update) assert host_status_counts == {'ok': 1, 'changed': 1, 'dark': 2}