diff options
author | Gordon Chung <gord@live.ca> | 2014-06-24 18:25:43 -0400 |
---|---|---|
committer | Gordon Chung <gord@live.ca> | 2014-06-24 18:25:43 -0400 |
commit | 9607c7d69f3e7dd51225802d653af9fdef321a20 (patch) | |
tree | 27311ccf19e0f2497f670a6c3293758e19f7d82a /tests | |
parent | a41dedff40946c1c5326ae9d0cec5ece563e4e52 (diff) | |
download | oslo-middleware-9607c7d69f3e7dd51225802d653af9fdef321a20.tar.gz |
remove stray tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/base.py | 54 | ||||
-rw-r--r-- | tests/test_middleware.py | 28 | ||||
-rw-r--r-- | tests/unit/middleware/test_catch_errors.py | 47 | ||||
-rw-r--r-- | tests/unit/middleware/test_correlation_id.py | 53 | ||||
-rw-r--r-- | tests/unit/middleware/test_request_id.py | 37 | ||||
-rw-r--r-- | tests/unit/middleware/test_sizelimit.py | 99 |
6 files changed, 0 insertions, 318 deletions
diff --git a/tests/base.py b/tests/base.py deleted file mode 100644 index f9a09a8..0000000 --- a/tests/base.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2010-2011 OpenStack Foundation -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import os - -import fixtures -import testtools - -_TRUE_VALUES = ('true', '1', 'yes') - -# FIXME(dhellmann) Update this to use oslo.test library - -class TestCase(testtools.TestCase): - - """Test case base class for all unit tests.""" - - def setUp(self): - """Run before each test method to initialize test environment.""" - - super(TestCase, self).setUp() - test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) - try: - test_timeout = int(test_timeout) - except ValueError: - # If timeout value is invalid do not set a timeout. - test_timeout = 0 - if test_timeout > 0: - self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) - - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.TempHomeDir()) - - if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: - stdout = self.useFixture(fixtures.StringStream('stdout')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: - stderr = self.useFixture(fixtures.StringStream('stderr')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - - self.log_fixture = self.useFixture(fixtures.FakeLogger())
\ No newline at end of file diff --git a/tests/test_middleware.py b/tests/test_middleware.py deleted file mode 100644 index ad7dce1..0000000 --- a/tests/test_middleware.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -test_middleware ----------------------------------- - -Tests for `middleware` module. -""" - -from . import base - - -class TestMiddleware(base.TestCase): - - def test_something(self): - pass
\ No newline at end of file diff --git a/tests/unit/middleware/test_catch_errors.py b/tests/unit/middleware/test_catch_errors.py deleted file mode 100644 index a14789d..0000000 --- a/tests/unit/middleware/test_catch_errors.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2013 NEC Corporation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from oslotest import base as test_base -import webob.dec -import webob.exc - -from oslo.middleware import catch_errors - - -class CatchErrorsTest(test_base.BaseTestCase): - - def _test_has_request_id(self, application, expected_code=None): - app = catch_errors.CatchErrorsMiddleware(application) - req = webob.Request.blank('/test') - res = req.get_response(app) - self.assertEqual(expected_code, res.status_int) - - def test_success_response(self): - @webob.dec.wsgify - def application(req): - return 'Hello, World!!!' - - self._test_has_request_id(application, webob.exc.HTTPOk.code) - - def test_internal_server_error(self): - @webob.dec.wsgify - def application(req): - raise Exception() - - with mock.patch.object(catch_errors.LOG, 'exception') as log_exc: - self._test_has_request_id(application, - webob.exc.HTTPInternalServerError.code) - self.assertEqual(1, log_exc.call_count) diff --git a/tests/unit/middleware/test_correlation_id.py b/tests/unit/middleware/test_correlation_id.py deleted file mode 100644 index 5248d8f..0000000 --- a/tests/unit/middleware/test_correlation_id.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2013 Rackspace Hosting -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import uuid - -import mock -from oslotest import base as test_base -from oslotest import moxstubout - -from oslo.middleware import correlation_id - - -class CorrelationIdMiddlewareTest(test_base.BaseTestCase): - - def setUp(self): - super(CorrelationIdMiddlewareTest, self).setUp() - self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs - - def test_process_request(self): - app = mock.Mock() - req = mock.Mock() - req.headers = {} - - mock_uuid4 = mock.Mock() - mock_uuid4.return_value = "fake_uuid" - self.stubs.Set(uuid, 'uuid4', mock_uuid4) - - middleware = correlation_id.CorrelationIdMiddleware(app) - middleware(req) - - self.assertEqual(req.headers.get("X_CORRELATION_ID"), "fake_uuid") - - def test_process_request_should_not_regenerate_correlation_id(self): - app = mock.Mock() - req = mock.Mock() - req.headers = {"X_CORRELATION_ID": "correlation_id"} - - middleware = correlation_id.CorrelationIdMiddleware(app) - middleware(req) - - self.assertEqual(req.headers.get("X_CORRELATION_ID"), "correlation_id") diff --git a/tests/unit/middleware/test_request_id.py b/tests/unit/middleware/test_request_id.py deleted file mode 100644 index c43229b..0000000 --- a/tests/unit/middleware/test_request_id.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2013 NEC Corporation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from oslotest import base as test_base -from testtools import matchers -import webob -import webob.dec - -from oslo.middleware import request_id - - -class RequestIdTest(test_base.BaseTestCase): - def test_generate_request_id(self): - @webob.dec.wsgify - def application(req): - return req.environ[request_id.ENV_REQUEST_ID] - - app = request_id.RequestIdMiddleware(application) - req = webob.Request.blank('/test') - res = req.get_response(app) - res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID) - self.assertThat(res_req_id, matchers.StartsWith(b'req-')) - # request-id in request environ is returned as response body - self.assertEqual(res_req_id, res.body) diff --git a/tests/unit/middleware/test_sizelimit.py b/tests/unit/middleware/test_sizelimit.py deleted file mode 100644 index 8f571d9..0000000 --- a/tests/unit/middleware/test_sizelimit.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (c) 2012 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslotest import base as test_base -import six -import webob - -from openstack.common.fixture import config -from oslo.middleware import sizelimit - - -class TestLimitingReader(test_base.BaseTestCase): - - def test_limiting_reader(self): - BYTES = 1024 - bytes_read = 0 - data = six.StringIO("*" * BYTES) - for chunk in sizelimit.LimitingReader(data, BYTES): - bytes_read += len(chunk) - - self.assertEqual(bytes_read, BYTES) - - bytes_read = 0 - data = six.StringIO("*" * BYTES) - reader = sizelimit.LimitingReader(data, BYTES) - byte = reader.read(1) - while len(byte) != 0: - bytes_read += 1 - byte = reader.read(1) - - self.assertEqual(bytes_read, BYTES) - - def test_limiting_reader_fails(self): - BYTES = 1024 - - def _consume_all_iter(): - bytes_read = 0 - data = six.StringIO("*" * BYTES) - for chunk in sizelimit.LimitingReader(data, BYTES - 1): - bytes_read += len(chunk) - - self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, - _consume_all_iter) - - def _consume_all_read(): - bytes_read = 0 - data = six.StringIO("*" * BYTES) - reader = sizelimit.LimitingReader(data, BYTES - 1) - byte = reader.read(1) - while len(byte) != 0: - bytes_read += 1 - byte = reader.read(1) - - self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, - _consume_all_read) - - -class TestRequestBodySizeLimiter(test_base.BaseTestCase): - - def setUp(self): - super(TestRequestBodySizeLimiter, self).setUp() - self.MAX_REQUEST_BODY_SIZE = \ - self.useFixture(config.Config()).conf.max_request_body_size - - @webob.dec.wsgify() - def fake_app(req): - return webob.Response(req.body) - - self.middleware = sizelimit.RequestBodySizeLimiter(fake_app) - self.request = webob.Request.blank('/', method='POST') - - def test_content_length_acceptable(self): - self.request.headers['Content-Length'] = self.MAX_REQUEST_BODY_SIZE - self.request.body = b"0" * self.MAX_REQUEST_BODY_SIZE - response = self.request.get_response(self.middleware) - self.assertEqual(response.status_int, 200) - - def test_content_length_too_large(self): - self.request.headers['Content-Length'] = self.MAX_REQUEST_BODY_SIZE + 1 - self.request.body = b"0" * (self.MAX_REQUEST_BODY_SIZE + 1) - response = self.request.get_response(self.middleware) - self.assertEqual(response.status_int, 413) - - def test_request_too_large_no_content_length(self): - self.request.body = b"0" * (self.MAX_REQUEST_BODY_SIZE + 1) - self.request.headers['Content-Length'] = None - response = self.request.get_response(self.middleware) - self.assertEqual(response.status_int, 413) |