]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/test_RecursorConfig.py
Make sure we can install unsigned packages.
[thirdparty/pdns.git] / regression-tests.api / test_RecursorConfig.py
1 import json
2 import unittest
3 from test_helper import ApiTestCase, is_recursor
4
5
6 @unittest.skipIf(not is_recursor(), "Only applicable to recursors")
7 class RecursorConfig(ApiTestCase):
8
9 def test_config_allow_from_get(self):
10 r = self.session.get(self.url("/api/v1/servers/localhost/config/allow-from"))
11 self.assert_success_json(r)
12
13 def test_config_allow_from_replace(self):
14 payload = {'value': ["127.0.0.1"]}
15 r = self.session.put(
16 self.url("/api/v1/servers/localhost/config/allow-from"),
17 data=json.dumps(payload),
18 headers={'content-type': 'application/json'})
19 self.assert_success_json(r)
20 data = r.json()
21 self.assertIn("value", data)
22 self.assertEquals(len(data["value"]), 1)
23 self.assertEquals("127.0.0.1/32", data["value"][0])
24
25 def test_config_allow_from_replace_error(self):
26 """Test the error case, should return 422."""
27 payload = {'value': ["abcdefgh"]}
28 r = self.session.put(
29 self.url("/api/v1/servers/localhost/config/allow-from"),
30 data=json.dumps(payload),
31 headers={'content-type': 'application/json'})
32 self.assertEquals(r.status_code, 422)
33 data = r.json()
34 self.assertIn('Unable to convert', data['error'])