]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/test_Servers.py
JSON API: provide flush-cache, notify, axfr-receive
[thirdparty/pdns.git] / regression-tests.api / test_Servers.py
1 from test_helper import ApiTestCase, is_auth, is_recursor
2
3
4 class Servers(ApiTestCase):
5
6 def test_list_servers(self):
7 r = self.session.get(self.url("/servers"))
8 self.assert_success_json(r)
9 lst = r.json()
10 self.assertEquals(len(lst), 1) # only localhost allowed in there
11 data = lst[0]
12 for k in ('id', 'daemon_type', 'url'):
13 self.assertIn(k, data)
14 self.assertEquals(data['id'], 'localhost')
15
16 def test_servers_localhost(self):
17 r = self.session.get(self.url("/servers/localhost"))
18 self.assert_success_json(r)
19 data = r.json()
20 for k in ('id', 'type', 'version', 'daemon_type', 'url', 'zones_url', 'config_url'):
21 self.assertIn(k, data)
22 self.assertEquals(data['id'], 'localhost')
23 self.assertEquals(data['type'], 'Server')
24 # or 'recursor' for recursors
25 if is_auth():
26 daemon_type = 'authoritative'
27 elif is_recursor():
28 daemon_type = 'recursor'
29 else:
30 raise RuntimeError('Unknown daemon type')
31 self.assertEquals(data['daemon_type'], daemon_type)
32
33 def test_read_config(self):
34 r = self.session.get(self.url("/servers/localhost/config"))
35 self.assert_success_json(r)
36 data = dict([(r['name'], r['value']) for r in r.json()])
37 self.assertIn('daemon', data)
38
39 def test_read_statistics(self):
40 r = self.session.get(self.url("/servers/localhost/statistics"))
41 self.assert_success_json(r)
42 data = dict([(r['name'], r['value']) for r in r.json()])
43 self.assertIn('uptime', data)
44
45 def test_flush_cache(self):
46 r = self.session.put(self.url("/servers/localhost/flush-cache?domain=example.org."))
47 self.assert_success_json(r)
48 data = r.json()
49 self.assertIn('count', data)
50
51 def test_flush_complete_cache(self):
52 r = self.session.put(self.url("/servers/localhost/flush-cache"))
53 self.assert_success_json(r)
54 data = r.json()
55 self.assertIn('count', data)
56 self.assertEqual(data['result'], 'Flushed cache.')