Exemple #1
0
 def delete(self):
     """Delete this component."""
     policy.check('delete_component',
                  pecan.request.security_context)
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Exemple #2
0
 def post(self, data):
     """Create a new component."""
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     return component.Component.from_db_model(
         handler.create(data.as_dict(objects.registry.Component)),
         pecan.request.host_url)
Exemple #3
0
 def put(self, data):
     """Modify this component."""
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Component))
     return component.Component.from_db_model(res, pecan.request.host_url)
Exemple #4
0
 def test_component_get(self, mock_registry):
     mock_registry.component.get_by_uuid.return_value = {'assembly_id': 42}
     handler = component_handler.ComponentHandler(self.ctx)
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     get_by_uuid = mock_registry.Component.get_by_uuid
     get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
Exemple #5
0
 def test_component_get(self, mock_registry):
     mock_registry.component.get_by_uuid.return_value = {}
     handler = component_handler.ComponentHandler()
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     mock_registry.Component.get_by_uuid.\
         assert_called_once_with(None, 'test_id')
Exemple #6
0
 def get_all(self):
     """Return all components, based on the query provided."""
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     return [
         component.Component.from_db_model(ser, pecan.request.host_url)
         for ser in handler.get_all()
     ]
Exemple #7
0
 def test_delete(self, mock_registry):
     db_obj = fakes.FakeComponent()
     mock_registry.Component.get_by_uuid.return_value = db_obj
     handler = component_handler.ComponentHandler(self.ctx)
     handler.delete('test_id')
     db_obj.destroy.assert_called_once_with(self.ctx)
     mock_registry.Component.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Exemple #8
0
 def get_all(self):
     """Return all components, based on the query provided."""
     policy.check('get_components',
                  pecan.request.security_context)
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return [component.Component.from_db_model(ser, host_url)
             for ser in handler.get_all()]
Exemple #9
0
 def post(self, data):
     """Create a new component."""
     policy.check('create_component',
                  pecan.request.security_context)
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return component.Component.from_db_model(
         handler.create(data.as_dict(objects.registry.Component)), host_url)
Exemple #10
0
 def get(self):
     """Return this component."""
     policy.check('show_component',
                  pecan.request.security_context)
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return component.Component.from_db_model(handler.get(self._id),
                                              host_url)
Exemple #11
0
 def test_create(self, mock_registry):
     data = {'name': 'new_name', 'assembly_id': 'new_assembly_id'}
     db_obj = fakes.FakeComponent()
     mock_registry.Component.return_value = db_obj
     handler = component_handler.ComponentHandler(self.ctx)
     res = handler.create(data)
     db_obj.update.assert_called_once_with(data)
     db_obj.create.assert_called_once_with(self.ctx)
     self.assertEqual(res, db_obj)
Exemple #12
0
 def put(self, data):
     """Modify this component."""
     policy.check('update_component',
                  pecan.request.security_context)
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Component))
     host_url = pecan.request.application_url.rstrip('/')
     return component.Component.from_db_model(res, host_url)
Exemple #13
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakeComponent()
     mock_registry.Component.get_by_uuid.return_value = db_obj
     handler = component_handler.ComponentHandler()
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     db_obj.save.assert_called_once_with(None)
     mock_registry.Component.get_by_uuid.assert_called_once_with(
         None, 'test_id')
Exemple #14
0
 def get(self):
     """Return this component."""
     handler = component_handler.ComponentHandler()
     return handler.get(self._id)
Exemple #15
0
 def __init__(self, component_id):
     super(ComponentController, self).__init__()
     self._id = component_id
     self._handler = component_handler.ComponentHandler()
Exemple #16
0
 def test_get_all(self, mock_registry):
     mock_registry.ComponentList.get_all.return_value = {}
     handler = component_handler.ComponentHandler(self.ctx)
     res = handler.get_all()
     self.assertIsNotNone(res)
     mock_registry.ComponentList.get_all.assert_called_once_with(self.ctx)
Exemple #17
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id', 'assembly_id': 'new_assembly_id'}
     handler = component_handler.ComponentHandler(self.ctx)
     handler.update('test_id', data)
     mock_registry.Component.update_and_save.assert_called_once_with(
         self.ctx, 'test_id', data)
Exemple #18
0
 def test_component_get_all(self):
     handler = component.ComponentHandler()
     res = handler.get_all()
     self.assertIsNotNone(res)
Exemple #19
0
 def put(self, data):
     """Modify this component."""
     handler = component_handler.ComponentHandler()
     return handler.update(self._id, data)
Exemple #20
0
 def post(self, data):
     """Create a new component."""
     handler = component_handler.ComponentHandler()
     return handler.create(data)
Exemple #21
0
 def delete(self):
     """Delete this component."""
     handler = component_handler.ComponentHandler()
     return handler.delete(self._id)
Exemple #22
0
 def delete(self):
     """Delete this component."""
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     return handler.delete(self._id)
Exemple #23
0
 def get_all(self):
     """Return all components, based on the query provided."""
     handler = component_handler.ComponentHandler()
     return handler.get_all()
Exemple #24
0
 def get(self):
     """Return this component."""
     handler = component_handler.ComponentHandler(
         pecan.request.security_context)
     return component.Component.from_db_model(handler.get(self._id),
                                              pecan.request.host_url)
Exemple #25
0
 def test_create(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     handler = component_handler.ComponentHandler()
     res = handler.create(data)
     self.assertEqual('new_user_id', res.user_id)
Exemple #26
0
 def __init__(self):
     super(ComponentsController, self).__init__()
     self._handler = component_handler.ComponentHandler()
     objects.load()