]>
Commit | Line | Data |
---|---|---|
c1374bdb | 1 | from test_helper import ApiTestCase, is_auth, is_recursor |
1a152698 CH |
2 | |
3 | ||
4 | class Servers(ApiTestCase): | |
5 | ||
c1374bdb | 6 | def test_list_servers(self): |
46d06a12 | 7 | r = self.session.get(self.url("/api/v1/servers")) |
c1374bdb | 8 | self.assert_success_json(r) |
1a152698 CH |
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 | ||
c1374bdb | 16 | def test_servers_localhost(self): |
46d06a12 | 17 | r = self.session.get(self.url("/api/v1/servers/localhost")) |
c1374bdb | 18 | self.assert_success_json(r) |
1a152698 CH |
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 | |
c1374bdb | 25 | if is_auth(): |
7c876c30 | 26 | daemon_type = 'authoritative' |
c1374bdb | 27 | elif is_recursor(): |
7c876c30 | 28 | daemon_type = 'recursor' |
c1374bdb CH |
29 | else: |
30 | raise RuntimeError('Unknown daemon type') | |
7c876c30 | 31 | self.assertEquals(data['daemon_type'], daemon_type) |
1a152698 | 32 | |
c1374bdb | 33 | def test_read_config(self): |
46d06a12 | 34 | r = self.session.get(self.url("/api/v1/servers/localhost/config")) |
c1374bdb | 35 | self.assert_success_json(r) |
a45303b8 CH |
36 | data = dict([(r['name'], r['value']) for r in r.json()]) |
37 | self.assertIn('daemon', data) | |
38 | ||
c1374bdb | 39 | def test_read_statistics(self): |
46d06a12 | 40 | r = self.session.get(self.url("/api/v1/servers/localhost/statistics")) |
c1374bdb | 41 | self.assert_success_json(r) |
118d3b31 CH |
42 | data = r.json() |
43 | self.assertIn('uptime', [e['name'] for e in data]) | |
44 | if is_auth(): | |
541bb91b | 45 | print(data) |
87798d5e | 46 | qtype_stats, respsize_stats, queries_stats, rcode_stats = None, None, None, None |
118d3b31 | 47 | for elem in data: |
87798d5e | 48 | if elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-qtype': |
118d3b31 CH |
49 | qtype_stats = elem['value'] |
50 | elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-sizes': | |
51 | respsize_stats = elem['value'] | |
52 | elif elem['type'] == 'RingStatisticItem' and elem['name'] == 'queries': | |
53 | queries_stats = elem['value'] | |
87798d5e TB |
54 | elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-rcode': |
55 | rcode_stats = elem['value'] | |
118d3b31 CH |
56 | self.assertIn('A', [e['name'] for e in qtype_stats]) |
57 | self.assertIn('60', [e['name'] for e in respsize_stats]) | |
58 | self.assertIn('example.com/A', [e['name'] for e in queries_stats]) | |
87798d5e | 59 | self.assertIn('No Error', [e['name'] for e in rcode_stats]) |