Exemplo n.º 1
0
    def create_event(group=None,
                     project=None,
                     event_id=None,
                     normalize=True,
                     **kwargs):
        # XXX: Do not use this method for new tests! Prefer `store_event`.
        if event_id is None:
            event_id = uuid4().hex
        kwargs.setdefault('project', project if project else group.project)
        kwargs.setdefault('data', copy.deepcopy(DEFAULT_EVENT_DATA))
        kwargs.setdefault('platform', kwargs['data'].get('platform', 'python'))
        kwargs.setdefault('message', kwargs['data'].get('message', 'message'))
        if kwargs.get('tags'):
            tags = kwargs.pop('tags')
            if isinstance(tags, dict):
                tags = list(tags.items())
            kwargs['data']['tags'] = tags
        if kwargs.get('stacktrace'):
            stacktrace = kwargs.pop('stacktrace')
            kwargs['data']['stacktrace'] = stacktrace

        user = kwargs.pop('user', None)
        if user is not None:
            kwargs['data']['user'] = user

        kwargs['data'].setdefault('errors', [{
            'type': EventError.INVALID_DATA,
            'name': 'foobar',
        }])

        # maintain simple event Factories by supporting the legacy message
        # parameter just like our API would
        if 'logentry' not in kwargs['data']:
            kwargs['data']['logentry'] = {
                'message': kwargs['message'] or '<unlabeled event>',
            }

        if normalize:
            manager = EventManager(CanonicalKeyDict(kwargs['data']))
            manager.normalize()
            kwargs['data'] = manager.get_data()
            kwargs['data'].update(manager.materialize_metadata())
            kwargs['message'] = manager.get_search_message()

        # This is needed so that create_event saves the event in nodestore
        # under the correct key. This is usually dont in EventManager.save()
        kwargs['data'].setdefault(
            'node_id', Event.generate_node_id(kwargs['project'].id, event_id))

        event = Event(event_id=event_id, group=group, **kwargs)
        if group:
            EventMapping.objects.create(
                project_id=event.project.id,
                event_id=event_id,
                group=group,
            )
        # emulate EventManager refs
        event.data.bind_ref(event)
        event.save()
        return event
Exemplo n.º 2
0
    def create_event(group, event_id=None, normalize=True, **kwargs):
        # XXX: Do not use this method for new tests! Prefer `store_event`.
        if event_id is None:
            event_id = uuid4().hex
        kwargs.setdefault('project', group.project)
        kwargs.setdefault('data', copy.deepcopy(DEFAULT_EVENT_DATA))
        kwargs.setdefault('platform', kwargs['data'].get('platform', 'python'))
        kwargs.setdefault('message', kwargs['data'].get('message', 'message'))
        if kwargs.get('tags'):
            tags = kwargs.pop('tags')
            if isinstance(tags, dict):
                tags = list(tags.items())
            kwargs['data']['tags'] = tags
        if kwargs.get('stacktrace'):
            stacktrace = kwargs.pop('stacktrace')
            kwargs['data']['stacktrace'] = stacktrace

        user = kwargs.pop('user', None)
        if user is not None:
            kwargs['data']['user'] = user

        kwargs['data'].setdefault(
            'errors', [{
                'type': EventError.INVALID_DATA,
                'name': 'foobar',
            }]
        )

        # maintain simple event Factories by supporting the legacy message
        # parameter just like our API would
        if 'logentry' not in kwargs['data']:
            kwargs['data']['logentry'] = {
                'message': kwargs['message'] or '<unlabeled event>',
            }

        if normalize:
            manager = EventManager(CanonicalKeyDict(kwargs['data']))
            manager.normalize()
            kwargs['data'] = manager.get_data()
            kwargs['data'].update(manager.materialize_metadata())
            kwargs['message'] = manager.get_search_message()

        # This is needed so that create_event saves the event in nodestore
        # under the correct key. This is usually dont in EventManager.save()
        kwargs['data'].setdefault(
            'node_id',
            Event.generate_node_id(kwargs['project'].id, event_id)
        )

        event = Event(event_id=event_id, group=group, **kwargs)
        EventMapping.objects.create(
            project_id=event.project.id,
            event_id=event_id,
            group=group,
        )
        # emulate EventManager refs
        event.data.bind_ref(event)
        event.save()
        return event
Exemplo n.º 3
0
    def create_event(group=None,
                     project=None,
                     event_id=None,
                     normalize=True,
                     **kwargs):
        # XXX: Do not use this method for new tests! Prefer `store_event`.
        if event_id is None:
            event_id = uuid4().hex
        kwargs.setdefault("project", project if project else group.project)
        kwargs.setdefault("data", copy.deepcopy(DEFAULT_EVENT_DATA))
        kwargs.setdefault("platform", kwargs["data"].get("platform", "python"))
        kwargs.setdefault("message", kwargs["data"].get("message", "message"))
        if kwargs.get("tags"):
            tags = kwargs.pop("tags")
            if isinstance(tags, dict):
                tags = list(tags.items())
            kwargs["data"]["tags"] = tags
        if kwargs.get("stacktrace"):
            stacktrace = kwargs.pop("stacktrace")
            kwargs["data"]["stacktrace"] = stacktrace

        user = kwargs.pop("user", None)
        if user is not None:
            kwargs["data"]["user"] = user

        kwargs["data"].setdefault("errors", [{
            "type": EventError.INVALID_DATA,
            "name": "foobar"
        }])

        # maintain simple event Factories by supporting the legacy message
        # parameter just like our API would
        if "logentry" not in kwargs["data"]:
            kwargs["data"]["logentry"] = {
                "message": kwargs["message"] or "<unlabeled event>"
            }

        if normalize:
            manager = EventManager(CanonicalKeyDict(kwargs["data"]))
            manager.normalize()
            kwargs["data"] = manager.get_data()
            kwargs["data"].update(manager.materialize_metadata())
            kwargs["message"] = manager.get_search_message()

        # This is needed so that create_event saves the event in nodestore
        # under the correct key. This is usually dont in EventManager.save()
        kwargs["data"].setdefault(
            "node_id", Event.generate_node_id(kwargs["project"].id, event_id))

        event = Event(event_id=event_id, group=group, **kwargs)
        # emulate EventManager refs
        event.data.bind_ref(event)
        event.save()
        event.data.save()
        return event
Exemplo n.º 4
0
    def create_event(self, event_id=None, normalize=True, **kwargs):
        # XXX: Do not use this method for new tests! Prefer `store_event`.
        if event_id is None:
            event_id = uuid4().hex
        if 'group' not in kwargs:
            kwargs['group'] = self.group
        kwargs.setdefault('project', kwargs['group'].project)
        kwargs.setdefault('data', copy.deepcopy(DEFAULT_EVENT_DATA))
        kwargs.setdefault('platform', kwargs['data'].get('platform', 'python'))
        kwargs.setdefault('message', kwargs['data'].get('message', 'message'))
        if kwargs.get('tags'):
            tags = kwargs.pop('tags')
            if isinstance(tags, dict):
                tags = list(tags.items())
            kwargs['data']['tags'] = tags
        if kwargs.get('stacktrace'):
            stacktrace = kwargs.pop('stacktrace')
            kwargs['data']['stacktrace'] = stacktrace

        user = kwargs.pop('user', None)
        if user is not None:
            kwargs['data']['user'] = user

        kwargs['data'].setdefault('errors', [{
            'type': EventError.INVALID_DATA,
            'name': 'foobar',
        }])

        # maintain simple event fixtures by supporting the legacy message
        # parameter just like our API would
        if 'logentry' not in kwargs['data']:
            kwargs['data']['logentry'] = {
                'message': kwargs['message'] or '<unlabeled event>',
            }

        if normalize:
            manager = EventManager(CanonicalKeyDict(kwargs['data']),
                                   for_store=False)
            manager.normalize()
            kwargs['data'] = manager.get_data()
            kwargs['data'].update(manager.materialize_metadata())
            kwargs['message'] = manager.get_search_message()

        event = Event(event_id=event_id, **kwargs)
        EventMapping.objects.create(
            project_id=event.project.id,
            event_id=event_id,
            group=event.group,
        )
        # emulate EventManager refs
        event.data.bind_ref(event)
        event.save()
        return event