Mercurial > hg > AuthRPC
comparison wibble/tests.py @ 14:45c1d78559e2
Added more tests
author | Ben Croston <ben@croston.org> |
---|---|
date | Mon, 05 Sep 2011 13:08:07 +0100 |
parents | 4ac14cfadc15 |
children |
comparison
equal
deleted
inserted
replaced
13:21eb67081c43 | 14:45c1d78559e2 |
---|---|
24 import hashlib | 24 import hashlib |
25 from threading import Thread | 25 from threading import Thread |
26 import time | 26 import time |
27 from wsgiref import simple_server | 27 from wsgiref import simple_server |
28 import platform | 28 import platform |
29 import urllib | |
30 | |
31 try: | |
32 urllib.urlopen('http://www.wyre-it.co.uk/') | |
33 NO_INTERNET = False | |
34 except IOError: | |
35 NO_INTERNET = True | |
29 | 36 |
30 ##### server vvv ##### | 37 ##### server vvv ##### |
31 class api(object): | 38 class api(object): |
32 def mymethod(self): | 39 def mymethod(self): |
33 return 'wibbler woz ere' | 40 return 'wibbler woz ere' |
78 password='s3cr3t', | 85 password='s3cr3t', |
79 user_agent='wibble_unittest') | 86 user_agent='wibble_unittest') |
80 with self.assertRaises(UnauthorisedException): | 87 with self.assertRaises(UnauthorisedException): |
81 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | 88 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) |
82 | 89 |
90 | |
91 @unittest.skipIf(NO_INTERNET,'www.wyre-it.co.uk:80 not contactable') | |
92 class NotFoundTest(unittest.TestCase): | |
93 def runTest(self): | |
94 from client import ServerProxy, NotFoundException | |
95 self.client = ServerProxy('http://www.wyre-it.co.uk/notfound.txt') | |
96 with self.assertRaises(NotFoundException): | |
97 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | |
98 | |
99 class NetworkSocketTest(unittest.TestCase): | |
100 def runTest(self): | |
101 from client import ServerProxy, NetworkSocketException | |
102 self.client = ServerProxy('http://localhost:666/') | |
103 with self.assertRaises(NetworkSocketException): | |
104 self.assertEqual(self.client.api.mymethod(),self.client.mymethod()) | |
105 | |
83 class WibbleTests(unittest.TestCase): | 106 class WibbleTests(unittest.TestCase): |
84 def setUp(self): | 107 def setUp(self): |
85 from client import ServerProxy | 108 from client import ServerProxy |
86 self.client = ServerProxy('http://localhost:1337/', | 109 self.client = ServerProxy('http://localhost:1337/', |
87 username='testuser', | 110 username='testuser', |
130 time.sleep(0.1) # wait for server thread to start | 153 time.sleep(0.1) # wait for server thread to start |
131 | 154 |
132 # tests are as client | 155 # tests are as client |
133 suite = unittest.TestSuite() | 156 suite = unittest.TestSuite() |
134 suite.addTest(AuthTest()) | 157 suite.addTest(AuthTest()) |
158 suite.addTest(NotFoundTest()) | |
159 suite.addTest(NetworkSocketTest()) | |
135 suite.addTest(IgnoreClassNameTest()) | 160 suite.addTest(IgnoreClassNameTest()) |
136 suite.addTest(ExceptionTest()) | 161 suite.addTest(ExceptionTest()) |
137 suite.addTest(BadRequestTest()) | 162 suite.addTest(BadRequestTest()) |
138 suite.addTest(EchoTest()) | 163 suite.addTest(EchoTest()) |
139 suite.addTest(ReturnNothing()) | 164 suite.addTest(ReturnNothing()) |