def test_autoconfig(self): with self.settings(OGC_SERVER=self.OGC_SERVER, SITEURL=self.OGC_GS_2): do_autoconfigure() h1 = Host.objects.get(name='localhost') h2 = Host.objects.get(name='google.com') s1 = Service.objects.get(name='geoserver1-geoserver') self.assertEqual(s1.host, h1) s2 = Service.objects.get(name='external1-geoserver') self.assertEqual(s2.host, h2) autoconf_url = reverse('monitoring:api_autoconfigure') resp = self.client.post(autoconf_url) self.assertEqual(resp.status_code, 401) self.client.login(username=self.user, password=self.passwd) resp = self.client.post(autoconf_url) self.assertEqual(resp.status_code, 200)
def post(self, request, *args, **kwargs): if not request.user.is_authenticated(): out = {'success': False, 'status': 'error', 'errors': {'user': ['User is not authenticated']} } return json_response(out, status=401) if not (request.user.is_superuser or request.user.is_staff): out = {'success': False, 'status': 'error', 'errors': {'user': ['User is not permitted']} } return json_response(out, status=401) do_autoconfigure() out = {'success': True, 'status': 'ok', 'errors': {} } return json_response(out)