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_operation_put_none(self, OperationHandler, resp_mock, request_mock): request_mock.body = None request_mock.content_type = 'application/json' hand_put = OperationHandler.return_value.put hand_put.return_value = fakes.FakeOperation() operation.OperationController('test_id').put() self.assertEqual(400, resp_mock.status)
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 test_operation_put_ok(self, OperationHandler, resp_mock, request_mock): json_update = {'name': 'foo'} request_mock.body = json.dumps(json_update) request_mock.content_type = 'application/json' hand_update = OperationHandler.return_value.update hand_update.return_value = fakes.FakeOperation() operation.OperationController('test_id').put() hand_update.assert_called_with('test_id', json_update) self.assertEqual(200, resp_mock.status)
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 test_operations_post(self, handler_mock, resp_mock, request_mock): json_create = { 'name': 'foo', 'description': 'test_desc_operation', 'user_id': 'user_id_test', 'project_id': 'project_id_test' } request_mock.body = json.dumps(json_create) request_mock.content_type = 'application/json' handler_create = handler_mock.return_value.create handler_create.return_value = fakes.FakeOperation() operation.OperationsController().post() handler_create.assert_called_with(json_create) self.assertEqual(201, resp_mock.status) handler_create.assert_called_once_with(json_create)
def test_operation_get(self, OperationHandler, resp_mock, request_mock): hand_get = OperationHandler.return_value.get fake_operation = fakes.FakeOperation() hand_get.return_value = fake_operation cont = operation.OperationController('test_id') resp = cont.get() self.assertIsNotNone(resp) self.assertEqual(fake_operation.name, resp['result'].name) self.assertEqual(fake_operation.documentation, resp['result'].documentation) self.assertEqual(fake_operation.description, resp['result'].description) self.assertEqual(fake_operation.project_id, resp['result'].project_id) self.assertEqual(fake_operation.uuid, resp['result'].uuid) hand_get.assert_called_with('test_id') self.assertEqual(200, resp_mock.status)
def test_operations_get_all(self, handler_mock, resp_mock, request_mock): hand_get_all = handler_mock.return_value.get_all fake_operation = fakes.FakeOperation() hand_get_all.return_value = [fake_operation] obj = operation.OperationsController() resp = obj.get_all() self.assertIsNotNone(resp) self.assertEqual(fake_operation.name, resp['result'][0].name) self.assertEqual(fake_operation.documentation, resp['result'][0].documentation) self.assertEqual(fake_operation.description, resp['result'][0].description) self.assertEqual(fake_operation.project_id, resp['result'][0].project_id) self.assertEqual(fake_operation.uuid, resp['result'][0].uuid) self.assertEqual(200, resp_mock.status)