# Path: oslo_middleware/sizelimit.py
# LOG = logging.getLogger(__name__)
# class LimitingReader(object):
# class RequestBodySizeLimiter(base.ConfigurableMiddleware):
#     def __init__(self, data, limit):
#     def __iter__(self):
#     def read(self, i=None):
#     def __init__(self, application, conf=None):
#     def __call__(self, req):


import io
import webob
from oslo_config import fixture as config
from oslotest import base as test_base
from oslo_middleware import sizelimit
#
#    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.





class TestLimitingReader(test_base.BaseTestCase):

    def test_limiting_reader(self):
        BYTES = 1024
        bytes_read = 0
        data = io.StringIO("*" * BYTES)
        for chunk in sizelimit.LimitingReader(data, BYTES):
            bytes_read += len(chunk)

        self.assertEqual(BYTES, bytes_read)

        bytes_read = 0
        data = io.StringIO("*" * BYTES)

# Path: oslo_middleware/sizelimit.py
# LOG = logging.getLogger(__name__)
# class LimitingReader(object):
# class RequestBodySizeLimiter(base.ConfigurableMiddleware):
#     def __init__(self, data, limit):
#     def __iter__(self):
#     def read(self, i=None):
#     def __init__(self, application, conf=None):
#     def __call__(self, req):


# Path: oslo_middleware/tests/test_sizelimit.py
import io
import webob
from oslo_config import fixture as config
from oslotest import base as test_base
from oslo_middleware import sizelimit

#
#    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.





class TestLimitingReader(test_base.BaseTestCase):

    def test_limiting_reader(self):
        BYTES = 1024
        bytes_read = 0
        data = io.StringIO("*" * BYTES)
        for chunk in sizelimit.LimitingReader(data, BYTES):
            bytes_read += len(chunk)

        self.assertEqual(BYTES, bytes_read)

        bytes_read = 0
        data = io.StringIO("*" * BYTES)

        reader = sizelimit.LimitingReader(data, BYTES)