From bed607b07a6389fd12be11ba8543402124ddd4bb Mon Sep 17 00:00:00 2001 From: David Goetz Date: Tue, 30 Aug 2011 12:07:32 -0700 Subject: [PATCH] adding unit tests --- test/unit/common/test_utils.py | 21 +++++++++++++++++++++ test/unit/common/test_wsgi.py | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 05707158a1..356e9ce2dc 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -536,6 +536,27 @@ log_name = yarr''' os.unlink('/tmp/test') self.assertRaises(SystemExit, utils.readconf, '/tmp/test') + def test_readconf_raw(self): + conf = '''[section1] +foo = bar + +[section2] +log_name = %(yarr)s''' + # setup a real file + with open('/tmp/test', 'wb') as f: + f.write(conf) + make_filename = lambda: '/tmp/test' + # setup a file stream + make_fp = lambda: StringIO(conf) + for conf_object_maker in (make_filename, make_fp): + result = utils.readconf(conf_object_maker(), raw=True) + expected = {'log_name': None, + 'section1': {'foo': 'bar'}, + 'section2': {'log_name': '%(yarr)s'}} + self.assertEquals(result, expected) + os.unlink('/tmp/test') + self.assertRaises(SystemExit, utils.readconf, '/tmp/test') + def test_drop_privileges(self): user = getuser() # over-ride os with mock diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 2df6936a83..b7496e7966 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -28,6 +28,7 @@ from StringIO import StringIO from collections import defaultdict from eventlet import sleep +from webob import Request from swift.common import wsgi @@ -173,6 +174,19 @@ class TestWSGI(unittest.TestCase): wsgi.sleep = old_sleep wsgi.time = old_time + def test_pre_auth_req(self): + class FakeReq(object): + @classmethod + def fake_blank(cls, path, environ={}, body='', headers={}): + self.assertEquals(environ['swift.authorize']('test'), None) + self.assertEquals(environ['HTTP_X_TRANS_ID'], '1234') + was_blank = Request.blank + Request.blank = FakeReq.fake_blank + wsgi.make_pre_authed_request({'HTTP_X_TRANS_ID': '1234'}, + 'PUT', '/', body='tester', headers={}) + wsgi.make_pre_authed_request({'HTTP_X_TRANS_ID': '1234'}, + 'PUT', '/', headers={}) + Request.blank = was_blank if __name__ == '__main__': unittest.main()