]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - regression-tests.api/test_Servers.py
dnsdist: Refactoring to merge the UDP and TCP paths
[thirdparty/pdns.git] / regression-tests.api / test_Servers.py
index 7b08d763ab620633dff890842789f9094c7d98b0..bc24d08c5b8f5a04295b87546ab64e19000bf9c7 100644 (file)
@@ -39,5 +39,32 @@ class Servers(ApiTestCase):
     def test_read_statistics(self):
         r = self.session.get(self.url("/api/v1/servers/localhost/statistics"))
         self.assert_success_json(r)
-        data = dict([(r['name'], r['value']) for r in r.json()])
-        self.assertIn('uptime', data)
+        data = r.json()
+        self.assertIn('uptime', [e['name'] for e in data])
+        if is_auth():
+            print(data)
+            qtype_stats, respsize_stats, queries_stats, rcode_stats = None, None, None, None
+            for elem in data:
+                if elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-qtype':
+                    qtype_stats = elem['value']
+                elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-sizes':
+                    respsize_stats = elem['value']
+                elif elem['type'] == 'RingStatisticItem' and elem['name'] == 'queries':
+                    queries_stats = elem['value']
+                elif elem['type'] == 'MapStatisticItem' and elem['name'] == 'response-by-rcode':
+                    rcode_stats = elem['value']
+            self.assertIn('A', [e['name'] for e in qtype_stats])
+            self.assertIn('60', [e['name'] for e in respsize_stats])
+            self.assertIn('example.com/A', [e['name'] for e in queries_stats])
+            self.assertIn('No Error', [e['name'] for e in rcode_stats])
+
+    def test_read_one_statistic(self):
+        r = self.session.get(self.url("/api/v1/servers/localhost/statistics?statistic=uptime"))
+        self.assert_success_json(r)
+        data = r.json()
+        self.assertIn('uptime', [e['name'] for e in data])
+
+    def test_read_one_non_existent_statistic(self):
+        r = self.session.get(self.url("/api/v1/servers/localhost/statistics?statistic=uptimeAAAA"))
+        self.assertEquals(r.status_code, 422)
+        self.assertIn("Unknown statistic name", r.json()['error'])