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