def form_list_xml(url, request, **kwargs): response = requests.Response() factory = RequestFactory() req = factory.get(url.path) req.user = authenticate(username='******', password='******') req.user.profile.require_auth = False req.user.profile.save() id_string = 'transportation_2011_07_25' if url.path.endswith('formList'): res = formList(req, username='******') elif url.path.endswith('form.xml'): res = download_xform(req, username='******', id_string=id_string) elif url.path.find('xformsManifest') > -1: res = xformsManifest(req, username='******', id_string=id_string) elif url.path.find('formid-media') > -1: data_id = url.path[url.path.rfind('/') + 1:] res = download_media_data( req, username='******', id_string=id_string, data_id=data_id) response._content = get_streaming_content(res) else: res = formList(req, username='******') response.status_code = 200 if not response._content: response._content = res.content return response
def test_returns_200_for_owner(self): self._set_require_auth() request = self.factory.get('/') auth = DigestAuth('bob', 'bob') response = formList(request, self.user.username) request.META.update(auth(request.META, response)) response = formList(request, self.user.username) self.assertEqual(response.status_code, 200)
def test_returns_200_for_authenticated_non_owner(self): self._set_require_auth() credentials = ('alice', 'alice',) self._create_user(*credentials) auth = DigestAuth('alice', 'alice') request = self.factory.get('/') response = formList(request, self.user.username) request.META.update(auth(request.META, response)) response = formList(request, self.user.username) self.assertEqual(response.status_code, 200)
def test_returns_200_for_authenticated_non_owner(self): self._set_require_auth() credentials = ( 'alice', 'alice', ) self._create_user(*credentials) auth = DigestAuth('alice', 'alice') request = self.factory.get('/') response = formList(request, self.user.username) request.META.update(auth(request.META, response)) response = formList(request, self.user.username) self.assertEqual(response.status_code, 200)
def test_show_for_anon_when_require_auth_false(self): request = self.factory.get('/') request.user = AnonymousUser() response = formList(request, self.user.username) self.assertEquals(response.status_code, 200)
def test_return_401_for_anon_when_require_auth_true(self): self._set_require_auth() request = self.factory.get('/') response = formList(request, self.user.username) self.assertEqual(response.status_code, 401)