Exemple #1
0
    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
Exemple #2
0
    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)
Exemple #3
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
Exemple #4
0
 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]),
     )
Exemple #5
0
 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
Exemple #6
0
 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)
Exemple #7
0
 def test_url_noargs(self):
     url = URL()
     self.assertEqual(unicode(url), u'/')
Exemple #8
0
 def test_with_slash(self):
     url = URL(['ab', None])
     self.assertEqual(url.with_slash(), '/ab/?/')
Exemple #9
0
 def test_reverse_empty(self):
     url = URL(['ab'])
     self.assertEqual(url.reverse([]), u'/ab')
Exemple #10
0
 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')
Exemple #11
0
 def test_add_variable(self):
     url = URL(['ab', None])
     url = url.add_variable()
     self.assertEqual(unicode(url), u'/ab/?/?')
Exemple #12
0
 def cs(self):
     return CollectionService(self.ps, self.served_manager, URL(['parent']))
Exemple #13
0
 def test_with_slash(self):
     url = URL(['ab', None])
     self.assertEqual(url.with_slash(), '/ab/?/')
Exemple #14
0
 def test_reverse_empty(self):
     url = URL(['ab'])
     self.assertEqual(url.reverse([]), u'/ab')
Exemple #15
0
 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')
Exemple #16
0
 def test_add_variable(self):
     url = URL(['ab', None])
     url = url.add_variable()
     self.assertEqual(unicode(url), u'/ab/?/?')
Exemple #17
0
 def test_add_segment(self):
     url = URL(['ab', None])
     url = url.add_segment('cd')
     self.assertEqual(unicode(url), u'/ab/?/cd')
Exemple #18
0
 def fcs(self):
     return FirstCollectionService(self.served_manager, URL(['parent']))
Exemple #19
0
 def test_url_args(self):
     url = URL(['ab', None])
     self.assertEqual(unicode(url), u'/ab/?')
Exemple #20
0
 def test_add_segment(self):
     url = URL(['ab', None])
     url = url.add_segment('cd')
     self.assertEqual(unicode(url), u'/ab/?/cd')