comparison wibble/tests.py @ 9:23743b0f67ab

Moved client.ServerProxy into client.__init__
author Ben Croston <ben@croston.org>
date Sun, 04 Sep 2011 23:44:50 +0100
parents 685479d1f0a7
children 58e764e39492
comparison
equal deleted inserted replaced
8:685479d1f0a7 9:23743b0f67ab
32 ##### server ^^^ ##### 32 ##### server ^^^ #####
33 33
34 ##### client vvv ##### 34 ##### client vvv #####
35 class NotAuthTest(unittest.TestCase): 35 class NotAuthTest(unittest.TestCase):
36 def runTest(self): 36 def runTest(self):
37 from client.ServerProxy import ServerProxy, UnauthorisedException 37 from client import ServerProxy, UnauthorisedException
38 self.client = ServerProxy('http://localhost:1337/', 38 self.client = ServerProxy('http://localhost:1337/',
39 username='testuser', 39 username='testuser',
40 password='s3cr3t', 40 password='s3cr3t',
41 user_agent='InternetExploiter') 41 user_agent='InternetExploiter')
42 with self.assertRaises(UnauthorisedException): 42 with self.assertRaises(UnauthorisedException):
43 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) 43 self.assertEqual(self.client.api.mymethod(),self.client.mymethod())
44 44
45 class WibbleTests(unittest.TestCase): 45 class WibbleTests(unittest.TestCase):
46 def setUp(self): 46 def setUp(self):
47 from client.ServerProxy import ServerProxy 47 from client import ServerProxy
48 self.client = ServerProxy('http://localhost:1337/', 48 self.client = ServerProxy('http://localhost:1337/',
49 username='testuser', 49 username='testuser',
50 password='s3cr3t', 50 password='s3cr3t',
51 user_agent='wibble_unittest') 51 user_agent='wibble_unittest')
52 52
59 with self.assertRaises(Exception): 59 with self.assertRaises(Exception):
60 self.client.raiseexception() 60 self.client.raiseexception()
61 61
62 class BadRequestTest(WibbleTests): 62 class BadRequestTest(WibbleTests):
63 def runTest(self): 63 def runTest(self):
64 from client.ServerProxy import BadRequestException 64 from client import BadRequestException
65 with self.assertRaises(BadRequestException): 65 with self.assertRaises(BadRequestException):
66 self.client.FunctionDoesNotExist() 66 self.client.FunctionDoesNotExist()
67 67
68 class EchoTest(WibbleTests): 68 class EchoTest(WibbleTests):
69 def runTest(self): 69 def runTest(self):
96 suite.addTest(EchoTest()) 96 suite.addTest(EchoTest())
97 return suite 97 return suite
98 98
99 if __name__ == '__main__': 99 if __name__ == '__main__':
100 import sys 100 import sys
101 if platform.python_version().startswith('2 ') and 'serve' in sys.argv: 101 if platform.python_version().startswith('2') and 'serve' in sys.argv:
102 print 'Listening on port 1337 (Ctrl-C qo quit)...' 102 print 'Listening on port 1337 (Ctrl-C qo quit)...'
103 server = make_server() 103 server = make_server()
104 try: 104 try:
105 server.serve_forever() 105 server.serve_forever()
106 except KeyboardInterrupt: 106 except KeyboardInterrupt: