Beispiel #1
0
 def test_form_upload(self):
     self._publish_xml_form()
     with codecs.open(self.form_def_path, encoding='utf-8') as f:
         params = {'form_def_file': f, 'dataFile': ''}
         request = self.factory.post(self._form_upload_url, params)
         response = form_upload(request, username=self.user.username)
         self.assertEqual(response.status_code, 401)
         auth = DigestAuth(self.login_username, self.login_password)
         request.META.update(auth(request.META, response))
         response = form_upload(request, username=self.user.username)
         self.assertContains(
             response,
             'Form with this id or SMS-keyword already exists',
             status_code=400)
 def test_form_upload(self):
     self._publish_xml_form()
     with codecs.open(self.form_def_path, encoding='utf-8') as f:
         params = {'form_def_file': f, 'dataFile': ''}
         request = self.factory.post(self._form_upload_url, params)
         response = form_upload(request, username=self.user.username)
         self.assertEqual(response.status_code, 401)
         auth = DigestAuth(self.login_username, self.login_password)
         request.META.update(auth(request.META, response))
         response = form_upload(request, username=self.user.username)
         self.assertContains(
             response,
             u'Form with this id or SMS-keyword already exists',
             status_code=400)
Beispiel #3
0
 def _publish_xml_form(self):
     count = XForm.objects.count()
     with codecs.open(self.form_def_path, encoding='utf-8') as f:
         params = {'form_def_file': f, 'dataFile': ''}
         request = self.factory.post(self._form_upload_url, params)
         response = form_upload(request, username=self.user.username)
         self.assertEqual(response.status_code, 401)
         auth = DigestAuth(self.login_username, self.login_password)
         request.META.update(auth(request.META, response))
         response = form_upload(request, username=self.user.username)
         self.assertContains(
             response, "successfully published.", status_code=201)
         self.assertEqual(XForm.objects.count(), count + 1)
     self.xform = XForm.objects.order_by('pk').reverse()[0]
Beispiel #4
0
    def test_publish_xml_form_other_user(self):
        # deno cannot publish form to bob's account
        self._create_user('deno', 'deno')
        count = XForm.objects.count()

        with codecs.open(self.form_def_path, encoding='utf-8') as f:
            params = {'form_def_file': f, 'dataFile': ''}
            request = self.factory.post(self._form_upload_url, params)
            response = form_upload(request, username=self.user.username)
            self.assertEqual(response.status_code, 401)
            auth = DigestAuth('deno', 'deno')
            request.META.update(auth(request.META, response))
            response = form_upload(request, username=self.user.username)
            self.assertNotEqual(XForm.objects.count(), count + 1)
            self.assertEqual(response.status_code, 403)
    def test_publish_xml_form_OtherUser(self):
        # deno cannot publish form to bob's account
        self._create_user('deno', 'deno')
        count = XForm.objects.count()

        with codecs.open(self.form_def_path, encoding='utf-8') as f:
            params = {'form_def_file': f, 'dataFile': ''}
            request = self.factory.post(self._form_upload_url, params)
            response = form_upload(request, username=self.user.username)
            self.assertEqual(response.status_code, 401)
            auth = DigestAuth('deno', 'deno')
            request.META.update(auth(request.META, response))
            response = form_upload(request, username=self.user.username)
            self.assertNotEqual(XForm.objects.count(), count + 1)
            self.assertEqual(response.status_code, 403)
Beispiel #6
0
 def test_publish_xml_form_where_filename_is_not_id_string(self):
     form_def_path = os.path.join(
         self.this_directory, 'fixtures', 'transportation',
         'Transportation Form.xml')
     count = XForm.objects.count()
     with codecs.open(form_def_path, encoding='utf-8') as f:
         params = {'form_def_file': f, 'dataFile': ''}
         request = self.factory.post(self._form_upload_url, params)
         response = form_upload(request, username=self.user.username)
         self.assertEqual(response.status_code, 401)
         auth = DigestAuth(self.login_username, self.login_password)
         request.META.update(auth(request.META, response))
         response = form_upload(request, username=self.user.username)
         self.assertContains(
             response, "successfully published.", status_code=201)
         self.assertEqual(XForm.objects.count(), count + 1)