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_operation_delete_ok(self, OperationHandler, resp_mock, request_mock): hand_delete = OperationHandler.return_value.delete hand_delete.return_value = None obj = operation.OperationController('test_id') obj.delete() hand_delete.assert_called_with('test_id') self.assertEqual(204, resp_mock.status)
def test_operation_delete_not_found(self, OperationHandler, resp_mock, request_mock): hand_delete = OperationHandler.return_value.delete hand_delete.side_effect = exception.ResourceNotFound(id='test_id', name='operation') obj = operation.OperationController('test_id') obj.delete() hand_delete.assert_called_with('test_id') self.assertEqual(404, resp_mock.status)
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_operation_get_not_found(self, OperationHandler, resp_mock, request_mock): hand_get = OperationHandler.return_value.get hand_get.side_effect = exception.ResourceNotFound(id='test_id', name='operation') cont = operation.OperationController('test_id') cont.get() hand_get.assert_called_with('test_id') self.assertEqual(404, resp_mock.status)
def test_operation_put_not_found(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.side_effect = exception.ResourceNotFound(id='test_id', name='operation') operation.OperationController('test_id').put() hand_update.assert_called_with('test_id', json_update) self.assertEqual(404, resp_mock.status)
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_operation_delete(self, resp_mock, request_mock): obj = operation.OperationController('test_id') obj.delete() self.assertEqual(400, resp_mock.status)
def test_operation_put(self, resp_mock, request_mock): obj = operation.OperationController('test_id') obj.put(None) self.assertEqual(400, resp_mock.status)
def test_operation_get(self, resp_mock, request_mock): obj = operation.OperationController('test_id') result = obj.get() self.assertEqual(200, resp_mock.status) self.assertIsNotNone(result)