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')
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)
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)
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)
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() ]
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')
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)
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()]
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)
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)
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)
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')
def get_all(self): """Return all operations, based on the query provided.""" handler = operation_handler.OperationHandler() return handler.get_all()
def test_operation_get_all(self): handler = operation.OperationHandler() res = handler.get_all() self.assertIsNotNone(res)
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)
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)
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)
def get(self): """Return this operation.""" handler = operation_handler.OperationHandler() return handler.get(self._id)
def delete(self): """Delete this operation.""" handler = operation_handler.OperationHandler( pecan.request.security_context) handler.delete(self._id)