moved LIMIT_LISTING const to swift.common.constraints, added test.unit.MockTrue, 100% test coverage on swift.common.constraints

This commit is contained in:
Clay Gerrard
2010年07月29日 13:30:16 -05:00
parent 0cda9a0cbe
commit 4a27df057d

View File

@@ -22,3 +22,44 @@ def connect_tcp(hostport):
rv = socket.socket()
rv.connect(hostport)
return rv
class MockTrue(object):
"""
Instances of MockTrue evalulate 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):
self = True
return self == other
def __ne__(self, other):
self = True
return self != other

View File

@@ -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()
Reference in New Issue
openstack/swift
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.