moved LIMIT_LISTING consts to swift.common.constraints, 100% test coverage of swift.common.constraints
This commit is contained in:
commit
138cf266e7
@ -3,3 +3,4 @@
|
||||
doc/build/*
|
||||
dist
|
||||
ChangeLog
|
||||
.coverage
|
||||
|
@ -30,13 +30,12 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
|
||||
import simplejson
|
||||
from xml.sax import saxutils
|
||||
|
||||
from swift.common import ACCOUNT_LISTING_LIMIT
|
||||
from swift.common.db import AccountBroker
|
||||
from swift.common.exceptions import MessageTimeout
|
||||
from swift.common.utils import get_param, split_path, storage_directory, \
|
||||
hash_path
|
||||
from swift.common.constraints import check_mount, check_float, \
|
||||
check_xml_encodable
|
||||
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_xml_encodable
|
||||
from swift.common.healthcheck import healthcheck
|
||||
from swift.common.db_replicator import ReplicatorRpc
|
||||
|
||||
|
@ -1,5 +1 @@
|
||||
""" Code common to all of Swift. """
|
||||
|
||||
ACCOUNT_LISTING_LIMIT = 10000
|
||||
CONTAINER_LISTING_LIMIT = 10000
|
||||
FILE_SIZE_LIMIT = 5368709122
|
||||
|
@ -32,6 +32,12 @@ MAX_META_COUNT = 90
|
||||
MAX_META_OVERALL_SIZE = 4096
|
||||
#: Max object name length
|
||||
MAX_OBJECT_NAME_LENGTH = 1024
|
||||
#: Max object list length of a get request for a container
|
||||
CONTAINER_LISTING_LIMIT = 10000
|
||||
#: Max container list length of a get request for an account
|
||||
ACCOUNT_LISTING_LIMIT = 10000
|
||||
|
||||
|
||||
|
||||
|
||||
def check_metadata(req):
|
||||
|
@ -31,12 +31,11 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
|
||||
HTTPCreated, HTTPException, HTTPInternalServerError, HTTPNoContent, \
|
||||
HTTPNotFound, HTTPPreconditionFailed, HTTPMethodNotAllowed
|
||||
|
||||
from swift.common import CONTAINER_LISTING_LIMIT
|
||||
from swift.common.db import ContainerBroker
|
||||
from swift.common.utils import get_logger, get_param, hash_path, \
|
||||
storage_directory, split_path, mkdirs
|
||||
from swift.common.constraints import check_mount, check_float, \
|
||||
check_xml_encodable
|
||||
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
|
||||
check_mount, check_float, check_xml_encodable
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.healthcheck import healthcheck
|
||||
from swift.common.exceptions import ConnectionTimeout, MessageTimeout
|
||||
|
@ -22,3 +22,42 @@ def connect_tcp(hostport):
|
||||
rv = socket.socket()
|
||||
rv.connect(hostport)
|
||||
return rv
|
||||
|
||||
class MockTrue(object):
|
||||
"""
|
||||
Instances of MockTrue evaluate like True
|
||||
Any attr accessed on an instance of MockTrue will return a MockTrue instance
|
||||
Any method called on an instance of MockTrue will return a MockTrue instance
|
||||
|
||||
>>> thing = MockTrue()
|
||||
>>> thing
|
||||
True
|
||||
>>> thing == True # True == True
|
||||
True
|
||||
>>> thing == False # True == False
|
||||
False
|
||||
>>> thing != True # True != True
|
||||
False
|
||||
>>> thing != False # True != False
|
||||
True
|
||||
>>> thing.attribute
|
||||
True
|
||||
>>> thing.method()
|
||||
True
|
||||
>>> thing.attribute.method()
|
||||
True
|
||||
>>> thing.method().attribute
|
||||
True
|
||||
|
||||
"""
|
||||
|
||||
def __getattribute__(self, *args, **kwargs):
|
||||
return self
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
def __repr__(*args, **kwargs):
|
||||
return repr(True)
|
||||
def __eq__(self, other):
|
||||
return other == True
|
||||
def __ne__(self, other):
|
||||
return other != True
|
||||
|
@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from test.unit import MockTrue
|
||||
|
||||
from webob import Request
|
||||
from webob.exc import HTTPBadRequest, HTTPLengthRequired, \
|
||||
@ -21,7 +22,6 @@ from webob.exc import HTTPBadRequest, HTTPLengthRequired, \
|
||||
|
||||
from swift.common import constraints
|
||||
|
||||
|
||||
class TestConstraints(unittest.TestCase):
|
||||
|
||||
def test_check_metadata_empty(self):
|
||||
@ -137,6 +137,15 @@ class TestConstraints(unittest.TestCase):
|
||||
self.assert_(isinstance(resp, HTTPBadRequest))
|
||||
self.assert_('Content-Type' in resp.body)
|
||||
|
||||
def test_check_mount(self):
|
||||
self.assertFalse(constraints.check_mount('', ''))
|
||||
constraints.os = MockTrue() # mock os module
|
||||
self.assertTrue(constraints.check_mount('/srv', '1'))
|
||||
reload(constraints) # put it back
|
||||
|
||||
def test_check_float(self):
|
||||
self.assertFalse(constraints.check_float(''))
|
||||
self.assertTrue(constraints.check_float('0'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user