示例#1
0
 def test_get(self, mock_registry):
     mock_registry.Operation.get_by_uuid.return_value = {}
     handler = operation.OperationHandler(self.ctx)
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     mock_registry.Operation.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
示例#2
0
 def delete(self):
     """Delete this operation."""
     policy.check('delete_operation',
                  pecan.request.security_context)
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     handler.delete(self._id)
示例#3
0
 def post(self, data):
     """Create a new operation."""
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     return operation.Operation.from_db_model(
         handler.create(data.as_dict(objects.registry.Operation)),
         pecan.request.host_url)
示例#4
0
 def put(self, data):
     """Modify this operation."""
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Operation))
     return operation.Operation.from_db_model(res, pecan.request.host_url)
示例#5
0
 def get_all(self):
     """Return all operations, based on the query provided."""
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     return [
         operation.Operation.from_db_model(obj, pecan.request.host_url)
         for obj in handler.get_all()
     ]
示例#6
0
 def test_delete(self, mock_registry):
     db_obj = fakes.FakeOperation()
     mock_registry.Operation.get_by_uuid.return_value = db_obj
     handler = operation.OperationHandler(self.ctx)
     handler.delete('test_id')
     db_obj.destroy.assert_called_once_with(self.ctx)
     mock_registry.Operation.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
示例#7
0
 def test_create(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakeOperation()
     mock_registry.Operation.return_value = db_obj
     handler = operation.OperationHandler(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(db_obj, res)
示例#8
0
 def get_all(self):
     """Return all operations, based on the query provided."""
     policy.check('get_operations',
                  pecan.request.security_context)
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return [operation.Operation.from_db_model(obj, host_url)
             for obj in handler.get_all()]
示例#9
0
 def post(self, data):
     """Create a new operation."""
     policy.check('create_operation',
                  pecan.request.security_context)
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return operation.Operation.from_db_model(handler.create(
         data.as_dict(objects.registry.Operation)), host_url)
示例#10
0
 def get(self):
     """Return this operation."""
     policy.check('show_operation',
                  pecan.request.security_context)
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     host_url = pecan.request.application_url.rstrip('/')
     return operation.Operation.from_db_model(handler.get(self._id),
                                              host_url)
示例#11
0
 def put(self, data):
     """Modify this operation."""
     policy.check('update_operation',
                  pecan.request.security_context)
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     res = handler.update(self._id,
                          data.as_dict(objects.registry.Operation))
     host_url = pecan.request.application_url.rstrip('/')
     return operation.Operation.from_db_model(res, host_url)
示例#12
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakeOperation()
     mock_registry.Operation.get_by_uuid.return_value = db_obj
     handler = operation.OperationHandler(self.ctx)
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     db_obj.save.assert_called_once_with(self.ctx)
     db_obj.update.assert_called_once_with(data)
     mock_registry.Operation.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
示例#13
0
 def get_all(self):
     """Return all operations, based on the query provided."""
     handler = operation_handler.OperationHandler()
     return handler.get_all()
示例#14
0
 def test_operation_get_all(self):
     handler = operation.OperationHandler()
     res = handler.get_all()
     self.assertIsNotNone(res)
示例#15
0
 def get(self):
     """Return this operation."""
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     return operation.Operation.from_db_model(handler.get(self._id),
                                              pecan.request.host_url)
示例#16
0
 def test_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     handler = operation.OperationHandler(self.ctx)
     handler.update('test_id', data)
     mock_registry.Operation.update_and_save.assert_called_once_with(
         self.ctx, 'test_id', data)
示例#17
0
 def test_get_all(self, mock_registry):
     mock_registry.OperationList.get_all.return_value = {}
     handler = operation.OperationHandler(self.ctx)
     res = handler.get_all()
     self.assertIsNotNone(res)
     mock_registry.OperationList.get_all.assert_called_once_with(self.ctx)
示例#18
0
 def get(self):
     """Return this operation."""
     handler = operation_handler.OperationHandler()
     return handler.get(self._id)
示例#19
0
 def delete(self):
     """Delete this operation."""
     handler = operation_handler.OperationHandler(
         pecan.request.security_context)
     handler.delete(self._id)