Mercurial > hg > AuthRPC
changeset 5:f5e3ba8cfcd0
Improved test framework
author | Ben Croston <ben@croston.org> |
---|---|
date | Wed, 31 Aug 2011 22:45:55 +0100 |
parents | ad5a8748afcf |
children | bb6b8df4dae8 |
files | wibble/client/ServerProxy.py wibble/tests.py |
diffstat | 2 files changed, 44 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/wibble/client/ServerProxy.py Wed Aug 31 21:35:14 2011 +0100 +++ b/wibble/client/ServerProxy.py Wed Aug 31 22:45:55 2011 +0100 @@ -1,4 +1,25 @@ #!/usr/bin/env python + +# Copyright (c) 2011 Ben Croston +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + from uuid import uuid4 from urlparse import urlparse import json
--- a/wibble/tests.py Wed Aug 31 21:35:14 2011 +0100 +++ b/wibble/tests.py Wed Aug 31 22:45:55 2011 +0100 @@ -9,15 +9,19 @@ ##### server vvv ##### class api(object): def mymethod(self): - #raise Exception("This is a test error") return 'wibbler woz ere' + def myexception(self): + raise Exception('This is a test error') + def myauth(username, password, useragent=None): #raise Exception("This is a test error in auth") - return username == 'testuser' and hashlib.md5('s3cr3t').hexdigest() == password and useragent == 'wibble_unittest' + return username == 'testuser' and \ + hashlib.md5('s3cr3t').hexdigest() == password and \ + useragent == 'wibble_unittest' def make_server(): - from wibble.server import JsonRpcApp + from server import JsonRpcApp class myhandler(simple_server.WSGIRequestHandler): def log_request(self, *a, **b): pass # do not output log messages @@ -28,13 +32,13 @@ ##### client vvv ##### class WibbleTests(unittest.TestCase): def setUp(self): - from wibble.client.ServerProxy import ServerProxy + from client.ServerProxy import ServerProxy self.client = ServerProxy('http://localhost:1337/', username='testuser', password='s3cr3t', user_agent='wibble_unittest') -class IgnoreModuleNameTest(WibbleTests): +class IgnoreClassNameTest(WibbleTests): def runTest(self): self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) @@ -50,22 +54,31 @@ ##### client ^^^ ##### +finished = False def suite(): if platform.python_version().startswith('3'): # no tests for python 3 because server not ported yet return unittest.TestSuite() def test_wrapper(): server = make_server() - server.log_request = None - server.serve_forever() + while not finished: + server.handle_request() thread = Thread(target=test_wrapper) thread.start() time.sleep(0.1) # wait for server thread to start suite = unittest.TestSuite() - suite.addTest(IgnoreModuleNameTest()) + suite.addTest(IgnoreClassNameTest()) return suite if __name__ == '__main__': -# unittest.main() - main() + finished = False + unittest.TextTestRunner(verbosity=2).run(suite()) + finished = True + # make a dummy request to get server thread out of loop + try: + import urllib + urllib.urlopen('http://localhost:1337/') + except: + pass +