forked from justquick/python-varnish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
36 lines (28 loc) · 1.14 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from varnish import VarnishManager
import unittest
ADDR = raw_input('Varnish Management Address (ip:port) [localhost:2000]: ')
if not ADDR: ADDR = 'localhost:2000'
WEB_ADDR = raw_input('Varnish Instance Address (ip:port) [localhost:8080]: ')
if not WEB_ADDR: WEB_ADDR = 'localhost:8080'
class VarnishTests(unittest.TestCase):
def setUp(self):
self.manager = VarnishManager((ADDR,))
def test_ping(self):
result = self.manager.run('ping')[0][0]
self.assertEqual(len(result), 2)
self.assert_(map(lambda x: isinstance(x, float), (True,True)))
def test_purge(self):
resp = self.manager.run(
'purge.url', 'http://%s/myrandomurl/.*' % WEB_ADDR)[0][0]
self.assertEqual(resp.status, 200)
def test_ban(self):
regex = '^/banned/*'
self.manager.run('ban.url', regex)
self.assert_(regex, str(self.manager.run('ban.list')))
def test_multiple(self):
result = self.manager.run(( ('ping',None),('ping',None) ))
self.assertEqual(result[0][0], result[0][1])
def tearDown(self):
self.manager.close()
if __name__ == '__main__':
unittest.main()