]>
Commit | Line | Data |
---|---|---|
41942bb3 | 1 | import json |
41942bb3 | 2 | import unittest |
c1374bdb | 3 | from test_helper import ApiTestCase, is_recursor |
41942bb3 CH |
4 | |
5 | ||
c1374bdb | 6 | @unittest.skipIf(not is_recursor(), "Only applicable to recursors") |
41942bb3 CH |
7 | class RecursorConfig(ApiTestCase): |
8 | ||
c1374bdb | 9 | def test_config_allow_from_get(self): |
46d06a12 | 10 | r = self.session.get(self.url("/api/v1/servers/localhost/config/allow-from")) |
c1374bdb | 11 | self.assert_success_json(r) |
41942bb3 | 12 | |
c1374bdb | 13 | def test_config_allow_from_replace(self): |
bd0320fe | 14 | payload = {'value': ["127.0.0.1"]} |
41942bb3 | 15 | r = self.session.put( |
46d06a12 | 16 | self.url("/api/v1/servers/localhost/config/allow-from"), |
41942bb3 CH |
17 | data=json.dumps(payload), |
18 | headers={'content-type': 'application/json'}) | |
c1374bdb | 19 | self.assert_success_json(r) |
41942bb3 | 20 | data = r.json() |
f9a7adb0 RG |
21 | self.assertIn("value", data) |
22 | self.assertEquals(len(data["value"]), 1) | |
bd0320fe | 23 | self.assertEquals("127.0.0.1/32", data["value"][0]) |
35f26cc5 | 24 | |
c1374bdb | 25 | def test_config_allow_from_replace_error(self): |
35f26cc5 CH |
26 | """Test the error case, should return 422.""" |
27 | payload = {'value': ["abcdefgh"]} | |
28 | r = self.session.put( | |
46d06a12 | 29 | self.url("/api/v1/servers/localhost/config/allow-from"), |
35f26cc5 CH |
30 | data=json.dumps(payload), |
31 | headers={'content-type': 'application/json'}) | |
32 | self.assertEquals(r.status_code, 422) | |
33 | data = r.json() | |
faa0f891 | 34 | self.assertIn('Unable to convert', data['error']) |