]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.api/test_Cache.py
Merge pull request #14021 from Habbie/auth-lua-join-whitespace
[thirdparty/pdns.git] / regression-tests.api / test_Cache.py
CommitLineData
d19c22a1 1from test_helper import ApiTestCase, is_auth, is_recursor, sdig
92144233 2import unittest
c0f6a1da
CH
3
4
5class Servers(ApiTestCase):
6
7 def test_flush(self):
8 r = self.session.put(self.url("/api/v1/servers/localhost/cache/flush?domain=example.org."))
9 self.assert_success_json(r)
10 data = r.json()
11 self.assertIn('count', data)
12
92144233 13 @unittest.skipIf(not is_recursor(), "Not applicable")
d19c22a1
CHB
14 def test_flush_count(self):
15 sdig("ns1.example.com", 'A')
16 r = self.session.put(self.url("/api/v1/servers/localhost/cache/flush?domain=ns1.example.com."))
17 self.assert_success_json(r)
18 data = r.json()
19 self.assertIn('count', data)
8d8ee515 20 self.assertEqual(2, data['count'])
d19c22a1 21
92144233 22 @unittest.skipIf(not is_recursor(), "Not applicable")
d19c22a1
CHB
23 def test_flush_subtree(self):
24 sdig("ns1.example.com", 'A')
25 sdig("ns2.example.com", 'A')
26 r = self.session.put(self.url("/api/v1/servers/localhost/cache/flush?domain=example.com.&subtree=false"))
27 self.assert_success_json(r)
28 data = r.json()
29 self.assertIn('count', data)
8d8ee515 30 self.assertEqual(3, data['count'])
d19c22a1
CHB
31 r = self.session.put(self.url("/api/v1/servers/localhost/cache/flush?domain=example.com.&subtree=true"))
32 self.assert_success_json(r)
33 data = r.json()
34 self.assertIn('count', data)
8d8ee515 35 self.assertEqual(4, data['count'])
d19c22a1 36
c0f6a1da
CH
37 def test_flush_root(self):
38 r = self.session.put(self.url("/api/v1/servers/localhost/cache/flush?domain=."))
39 self.assert_success_json(r)
40 data = r.json()
41 self.assertIn('count', data)
42 self.assertEqual(data['result'], 'Flushed cache.')
43
44 def test_flush_no_domain(self):
45 r = self.session.put(
46 self.url("/api/v1/servers/localhost/cache/flush"))
4bfebc93 47 self.assertEqual(r.status_code, 422)
c0f6a1da
CH
48
49 def test_flush_unqualified(self):
50 r = self.session.put(
51 self.url("/api/v1/servers/localhost/cache/flush?domain=bar"))
4bfebc93 52 self.assertEqual(r.status_code, 422)