Mercurial > hg > AuthRPC
comparison wibble/tests.py @ 12:4ac14cfadc15
Improved AuthTest
author | Ben Croston <ben@croston.org> |
---|---|
date | Mon, 05 Sep 2011 12:29:08 +0100 |
parents | dbd55e6af4f6 |
children | 45c1d78559e2 |
comparison
equal
deleted
inserted
replaced
11:dbd55e6af4f6 | 12:4ac14cfadc15 |
---|---|
54 application = JsonRpcApp(api(), auth=myauth) | 54 application = JsonRpcApp(api(), auth=myauth) |
55 return simple_server.make_server('localhost', 1337, application, handler_class=myhandler) | 55 return simple_server.make_server('localhost', 1337, application, handler_class=myhandler) |
56 ##### server ^^^ ##### | 56 ##### server ^^^ ##### |
57 | 57 |
58 ##### client vvv ##### | 58 ##### client vvv ##### |
59 class NotAuthTest(unittest.TestCase): | 59 class AuthTest(unittest.TestCase): |
60 def runTest(self): | 60 def runTest(self): |
61 from client import ServerProxy, UnauthorisedException | 61 from client import ServerProxy, UnauthorisedException |
62 self.client = ServerProxy('http://localhost:1337/', | 62 self.client = ServerProxy('http://localhost:1337/', |
63 username='testuser', | 63 username='testuser', |
64 password='s3cr3t', | 64 password='s3cr3t', |
65 user_agent='InternetExploiter') | 65 user_agent='InternetExploiter') |
66 with self.assertRaises(UnauthorisedException): | |
67 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | |
68 | |
69 self.client = ServerProxy('http://localhost:1337/', | |
70 username='testuser', | |
71 password='wrongpassword', | |
72 user_agent='wibble_unittest') | |
73 with self.assertRaises(UnauthorisedException): | |
74 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | |
75 | |
76 self.client = ServerProxy('http://localhost:1337/', | |
77 username='wronguser', | |
78 password='s3cr3t', | |
79 user_agent='wibble_unittest') | |
66 with self.assertRaises(UnauthorisedException): | 80 with self.assertRaises(UnauthorisedException): |
67 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | 81 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) |
68 | 82 |
69 class WibbleTests(unittest.TestCase): | 83 class WibbleTests(unittest.TestCase): |
70 def setUp(self): | 84 def setUp(self): |
115 thread.start() | 129 thread.start() |
116 time.sleep(0.1) # wait for server thread to start | 130 time.sleep(0.1) # wait for server thread to start |
117 | 131 |
118 # tests are as client | 132 # tests are as client |
119 suite = unittest.TestSuite() | 133 suite = unittest.TestSuite() |
120 suite.addTest(NotAuthTest()) | 134 suite.addTest(AuthTest()) |
121 suite.addTest(IgnoreClassNameTest()) | 135 suite.addTest(IgnoreClassNameTest()) |
122 suite.addTest(ExceptionTest()) | 136 suite.addTest(ExceptionTest()) |
123 suite.addTest(BadRequestTest()) | 137 suite.addTest(BadRequestTest()) |
124 suite.addTest(EchoTest()) | 138 suite.addTest(EchoTest()) |
125 suite.addTest(ReturnNothing()) | 139 suite.addTest(ReturnNothing()) |