def setup(config): serializers = deepcopy(config.get(SERIALIZERS_CONFIG_KEY, {})) for name, kwargs in serializers.items(): encoder = import_from_path(kwargs.pop('encoder')) decoder = import_from_path(kwargs.pop('decoder')) kombu.serialization.register(name, encoder=encoder, decoder=decoder, **kwargs) serializer = config.get(SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER) accept = config.get(ACCEPT_CONFIG_KEY, [serializer]) for name in [serializer] + accept: try: kombu.serialization.registry.name_to_type[name] except KeyError: raise ConfigurationError( 'Please register a serializer for "{}" format'.format(name)) return serializer, accept
def test_import_function(self): assert import_from_path("nameko.rpc.rpc") is rpc
def test_import_module(self): assert import_from_path("nameko.rpc") is nameko.rpc
def test_import_class(self): assert import_from_path("nameko.rpc.Rpc") is Rpc
def test_import_error(self): with pytest.raises(ImportError) as exc_info: import_from_path("foo.bar.Baz") assert ( "`foo.bar.Baz` could not be imported" in str(exc_info.value) )
def test_path_is_none(self): assert import_from_path(None) is None
def get_container_cls(config): class_path = config.get('SERVICE_CONTAINER_CLS') return import_from_path(class_path) or ServiceContainer