def test_named_objects_from_signal_duplicate(): objects = [ type('Dummy', (object, ), {'name': name}) for name in ('a', 'a', 'b', 'c', 'c') ] signal_response = _make_signal_response(objects) with pytest.raises(RuntimeError) as exc_info: named_objects_from_signal(signal_response) assert str(exc_info.value) == 'Non-unique object names: a, c'
def get_conditions(context, **kwargs): """Get a dict of available conditions. :param context: the context where the conditions are used :param kwargs: arguments specific to the context """ return named_objects_from_signal( signals.get_conditions.send(context, **kwargs))
def get_field_definitions(for_): """Gets a dict containing all field definitions :param for_: The identifier/object passed to the `get_fields` signal to identify which fields to get. """ return named_objects_from_signal(signals.get_fields.send(for_), plugin_attr='plugin')
def test_named_objects_from_signal(name_attr): objects = [ type('Dummy', (object, ), {name_attr: name}) for name in ('a', 'b') ] signal_response = _make_signal_response(objects) assert named_objects_from_signal(signal_response, name_attr=name_attr) == { 'a': objects[0], 'b': objects[1] }
def get_event_cloners(): """Get the dict containing all available event cloners. The returned dict is ordered based on the dependencies of each cloner and when executing the cloners MUST be executed in that order. """ cloners = named_objects_from_signal( signals.event_management.get_cloners.send(), plugin_attr='plugin') return OrderedDict(_resolve_dependencies(cloners))
def test_named_objects_from_signal_plugin_attr(): objects = [ type('Dummy', (object, ), {'name': name}) for name in ('a', 'b') ] signal_response = _make_signal_response(objects) signal_response[-1] = (MagicMock(fossir_plugin='foo'), signal_response[-1][1]) rv = named_objects_from_signal(signal_response, plugin_attr='plugin') assert rv == {'a': objects[0], 'b': objects[1]} assert rv['a'].plugin is None assert rv['b'].plugin == 'foo'
def _get_fossir_plugin_commands(self, ctx): if self._fossir_plugin_commands is not None: return self._fossir_plugin_commands try: from fossir.core import signals from fossir.util.signals import named_objects_from_signal ctx.ensure_object(ScriptInfo).load_app() cmds = named_objects_from_signal(signals.plugin.cli.send(), plugin_attr='_fossir_plugin') rv = {} for name, cmd in cmds.viewitems(): if cmd._fossir_plugin: self._wrap_in_plugin_context(cmd._fossir_plugin, cmd) rv[name] = cmd except Exception as exc: if 'No fossir config found' not in unicode(exc): click.echo( click.style('Loading plugin commands failed:', fg='red', bold=True)) click.echo(click.style(traceback.format_exc(), fg='red')) rv = {} self._fossir_plugin_commands = rv return rv
def get_placeholders(context, **kwargs): return named_objects_from_signal( signals.get_placeholders.send(context, **kwargs))
def get_feature_definitions(): """Gets a dict containing all feature definitions""" return named_objects_from_signal(signals.event.get_feature_definitions.send(), plugin_attr='plugin')
def get_available_roles(type_): """Gets a dict containing all roles for a given object type""" return named_objects_from_signal( signals.acl.get_management_roles.send(type_))
def get_menu_entries_from_signal(): return named_objects_from_signal(signals.event.sidemenu.send(), plugin_attr='plugin')
def get_log_renderers(): return named_objects_from_signal(signals.event.get_log_renderers.send(), plugin_attr='plugin')
def get_request_definitions(): """Returns a dict of request definitions""" return named_objects_from_signal( signals.plugin.get_event_request_definitions.send(), plugin_attr='plugin')
def get_storage_backends(): return named_objects_from_signal(signals.get_storage_backends.send(), plugin_attr='plugin')
def get_agreement_definitions(): return named_objects_from_signal(signals.agreements.get_definitions.send(), plugin_attr='plugin')