def setUp(self): self.manager = manager = mock.Mock( name='Manager', ) self.served_manager_instance = smi = mock.Mock( name='SMI', spec=ServedManagerInstance, manager=manager ) self.rw = ResourceWrapper(manager, '123', {'mpm': 'prefork'}) smi.validate_id.side_effect = validate_id smi.get_resource.return_value = self.rw manager.serialize.side_effect = serialize self.url = url = URL(['abc', None]) self.cs = mock.Mock( name='CS', spec=CollectionService, lock=None, collection=manager, resource_url=url) self.context = mock.Mock( spec=CollectionContext, service=self.cs, method='GET', parameters={}, data=mock.Mock(name='data'), ) self.context.get_manager_instance.return_value = smi
def __init__(self, collection, namespace, configuration): """ Create a base service for the given collection (a Manager object) and its submanager. *namespace* is the manager name (could be forced in conf) configuration parameters is the manager's config read from config file FIXME : remplacer collection par manager dans le code PARTOUT collection MUST be a Manager subclass and configuration an instance of Conf for this collection """ self.configuration = configuration self._collection_services = {} self.url = URL([namespace]) if 'Lock' in configuration: lock_conf = configuration.get('Lock') if 'name' not in lock_conf: raise ValueError('Lock configuration must have at least a name') logger.info('Creating lock %s for %s', lock_conf.get('name'), namespace) self.lock = lock_factory(lock_conf) else: self.lock = None namespaces = (namespace, ) service = FirstCollectionService( FirstServedManager( collection, self.configuration, namespaces, lock=self.lock, ), self.url) self._collection_services[namespaces] = service self._create_collection_service(collection, namespaces, service, 0)
def setUp(self): self.manager = manager = mock.Mock() self.served_manager_instance = smi = mock.Mock( spec=ServedManagerInstance, manager=manager, ) self.url = url = URL(['abc', None]) self.acs = mock.Mock( spec=ActionService, collection=manager, lock=mock.Mock(spec=Lock), resource_url=url ) self.action = self.manager.do_the_stuff self.validate = self.action.resource_fields.validate self.validate.return_value = {} self.data = mock.Mock(name='data') self.context = mock.Mock( spec=CollectionContext, service=self.acs, method='POST', data=self.data, parameters={}, ) self.context.get_manager_instance.return_value = smi
def setUp(self): self.request = mock.Mock(spec=Request) self.served_action = mock.Mock( spec=ServedAction, meta_data=mock.Mock(), name='served_action', lock=None, ) self.served_action.name = 'impulse' self.collection_service = mock.Mock( spec=CollectionService, resource_url=URL(['parent', None]), )
def setUp(self): mc = mock.Mock(spec=ManagedClass) mc.get_name.return_value = 'def' self.manager = manager = mock.Mock() manager.get_managed_classes.return_value = [mc] self.url = url = URL(['abc', None]) self.cs = mock.Mock( spec=CollectionService, lock=None, collection=manager, resource_url=url) self.context = mock.Mock( spec=CollectionContext, method='GET', service=self.cs, ) self.context.get_manager_instance.return_value = manager
def setUp(self): self.context = mock.Mock( name='request', spec=NapixdContext, method='GET', parameters=mock.MagicMock(), ) self.served_manager = mock.Mock( spec=ServedManager, name='served_manager', manager_class=mock.Mock(), lock=None, get_all_actions=mock.Mock(return_value=[]), ) self.ps = mock.Mock(name='previous_service', ) self.cs = CollectionService(self.ps, self.served_manager, URL(['parent', None, 'child'])) self.router = Router() self.cs.setup_bottle(self.router)
def test_url_noargs(self): url = URL() self.assertEqual(unicode(url), u'/')
def test_with_slash(self): url = URL(['ab', None]) self.assertEqual(url.with_slash(), '/ab/?/')
def test_reverse_empty(self): url = URL(['ab']) self.assertEqual(url.reverse([]), u'/ab')
def test_reverse_additional(self): url = URL(['ab', None, 'cd', None]) self.assertEqual(url.reverse(['a/b', 'cd', 'ef']), u'/ab/a%2Fb/cd/cd/ef')
def test_add_variable(self): url = URL(['ab', None]) url = url.add_variable() self.assertEqual(unicode(url), u'/ab/?/?')
def cs(self): return CollectionService(self.ps, self.served_manager, URL(['parent']))
def test_reverse_additional(self): url = URL(['ab', None, 'cd', None]) self.assertEqual( url.reverse(['a/b', 'cd', 'ef']), u'/ab/a%2Fb/cd/cd/ef')
def test_add_segment(self): url = URL(['ab', None]) url = url.add_segment('cd') self.assertEqual(unicode(url), u'/ab/?/cd')
def fcs(self): return FirstCollectionService(self.served_manager, URL(['parent']))
def test_url_args(self): url = URL(['ab', None]) self.assertEqual(unicode(url), u'/ab/?')