Ejemplo n.º 1
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.public_api_url = reverse(
         public_api, kwargs={"username": self.user.username, "id_string": self.xform.id_string}
     )
Ejemplo n.º 2
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     s = 'transport_2011-07-25_19-05-49'
     self._make_submission(os.path.join(self.this_directory, 'fixtures',
         'transportation', 'instances', s, s + '.xml'))
     self.submission = self.xform.surveys.reverse()[0]
     self.url = reverse(map_view, kwargs={'username': self.user.username,
         'id_string': self.xform.id_string})
     self.perm_url = reverse(set_perm, kwargs={
         'username': self.user.username, 'id_string': self.xform.id_string})
     self.edit_url = reverse(edit, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
     self.show_url = reverse(show,
                 kwargs={'uuid': self.xform.uuid})
     self.show_normal_url = reverse(show, kwargs={
             'username': self.user.username,
             'id_string': self.xform.id_string
     })
     self.api_url = reverse(api, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 3
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     s = 'transport_2011-07-25_19-05-49'
     self._make_submission(
         os.path.join(self.this_directory, 'fixtures', 'transportation',
                      'instances', s, s + '.xml'))
     self.submission = self.xform.surveys.reverse()[0]
     self.url = reverse(map_view,
                        kwargs={
                            'username': self.user.username,
                            'id_string': self.xform.id_string
                        })
     self.perm_url = reverse(set_perm,
                             kwargs={
                                 'username': self.user.username,
                                 'id_string': self.xform.id_string
                             })
     self.edit_url = reverse(edit,
                             kwargs={
                                 'username': self.user.username,
                                 'id_string': self.xform.id_string
                             })
     self.show_url = reverse(show, kwargs={'uuid': self.xform.uuid})
     self.show_normal_url = reverse(show,
                                    kwargs={
                                        'username': self.user.username,
                                        'id_string': self.xform.id_string
                                    })
     self.api_url = reverse(api,
                            kwargs={
                                'username': self.user.username,
                                'id_string': self.xform.id_string
                            })
Ejemplo n.º 4
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.url = reverse(show, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 5
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.api_url = reverse(api, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 6
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     self.url = reverse(show, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 7
0
 def setUp(self):
     MainTestCase.setUp(self)
     self.set_role_url = reverse(set_role)
     self._create_user_and_login()
     self._publish_transportation_form()
     self.form_show_url = reverse(show, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
     UserProfile.objects.get_or_create(user=self.user)
Ejemplo n.º 8
0
 def setUp(self):
     MainTestCase.setUp(self)
     self.set_role_url = reverse(set_role)
     self._create_user_and_login()
     self._publish_transportation_form()
     self.form_show_url = reverse(show,
                                  kwargs={
                                      'username': self.user.username,
                                      'id_string': self.xform.id_string
                                  })
     UserProfile.objects.get_or_create(user=self.user)
Ejemplo n.º 9
0
 def setUp(self):
     MainTestCase.setUp(self)
     #Already done by setUp
     #self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.perm_url = reverse(set_perm, kwargs={
         'username': self.user.username, 'id_string': self.xform.id_string})
     self.show_url = reverse(show, kwargs={'uuid': self.xform.uuid})
     self.url = reverse(enter_data, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 10
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.perm_url = reverse(set_perm, kwargs={
         'username': self.user.username, 'id_string': self.xform.id_string})
     self.show_url = reverse(show,
                 kwargs={'uuid': self.xform.uuid})
     self.url = reverse(enter_data, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
Ejemplo n.º 11
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.submission = self.xform.surveys.reverse()[0]
     self.url = reverse(show_submission, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'uuid': self.submission.uuid,
     })
     self.survey_url = reverse(survey_responses, kwargs={
             'instance_id': self.submission.pk })
Ejemplo n.º 12
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.submission = self.xform.surveys.reverse()[0]
     self.url = reverse(show_submission, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'uuid': self.submission.uuid,
     })
     self.survey_url = reverse(survey_responses, kwargs={
                               'instance_id': self.submission.pk})
Ejemplo n.º 13
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.delete_url = reverse(delete_data, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
     self.mongo_args = {
         'username': self.user.username, 'id_string': self.xform.id_string,
         'query': "{}", 'limit': 1,
         'sort': '{"_id":-1}', 'fields': '["_id","_uuid"]'}
Ejemplo n.º 14
0
    def setUp(self):
        MainTestCase.setUp(self)
        self._create_user_and_login()
        self._publish_transportation_form()

        # turn on crowd forms for this form
        self.xform.is_crowd_form = True
        self.xform.save()
        self.edit_url = reverse(edit, kwargs={
            'username': self.xform.user.username,
            'id_string': self.xform.id_string
        })
        self.alice = 'alice'
        self.crowdform_count = 0
Ejemplo n.º 15
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     s = "transport_2011-07-25_19-05-49"
     self._make_submission(
         os.path.join(self.this_directory, "fixtures", "transportation", "instances", s, s + ".xml")
     )
     self.submission = self.xform.surveys.reverse()[0]
     self.url = reverse(map_view, kwargs={"username": self.user.username, "id_string": self.xform.id_string})
     self.perm_url = reverse(set_perm, kwargs={"username": self.user.username, "id_string": self.xform.id_string})
     self.edit_url = reverse(edit, kwargs={"username": self.user.username, "id_string": self.xform.id_string})
     self.show_url = reverse(show, kwargs={"uuid": self.xform.uuid})
     self.show_normal_url = reverse(show, kwargs={"username": self.user.username, "id_string": self.xform.id_string})
     self.api_url = reverse(api, kwargs={"username": self.user.username, "id_string": self.xform.id_string})
Ejemplo n.º 16
0
    def setUp(self):
        MainTestCase.setUp(self)
        self._create_user_and_login()
        self._publish_transportation_form()

        # turn on crowd forms for this form
        self.xform.is_crowd_form = True
        self.xform.save()
        self.edit_url = reverse(edit,
                                kwargs={
                                    'username': self.xform.user.username,
                                    'id_string': self.xform.id_string
                                })
        self.alice = 'alice'
        self.crowdform_count = 0
Ejemplo n.º 17
0
 def _publish_transportation_id_string_starts_with_number_form(self):
     xls_path = os.path.join(self.this_directory, "fixtures",
         "transportation", "transportation.id_starts_with_num.xls")
     count = XForm.objects.count()
     response = MainTestCase._publish_xls_file(self, xls_path)
     self.assertEqual(XForm.objects.count(), count + 1)
     self.xform = XForm.objects.all().reverse()[0]
Ejemplo n.º 18
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form_and_submit_instance()
     self.delete_url = reverse(delete_data,
                               kwargs={
                                   'username': self.user.username,
                                   'id_string': self.xform.id_string
                               })
     self.mongo_args = {
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'query': "{}",
         'limit': 1,
         'sort': '{"_id":-1}',
         'fields': '["_id","_uuid"]'
     }
Ejemplo n.º 19
0
 def _publish_transportation_id_string_starts_with_number_form(self):
     xls_path = os.path.join(
         self.this_directory, "fixtures", "transportation", "transportation.id_starts_with_num.xls"
     )
     count = XForm.objects.count()
     response = MainTestCase._publish_xls_file(self, xls_path)
     self.assertEqual(XForm.objects.count(), count + 1)
     self.xform = XForm.objects.all().reverse()[0]
Ejemplo n.º 20
0
    def _publish_xls_file(self):
        xls_path = os.path.join(self.this_directory, "fixtures", "transportation", "transportation.xls")
        pre_count = XForm.objects.count()
        response = MainTestCase._publish_xls_file(self, xls_path)

        # make sure publishing the survey worked
        self.assertEqual(response.status_code, 200)
        self.assertEqual(XForm.objects.count(), pre_count+1)
        self.xform = list(XForm.objects.all())[-1]
        self.assertEqual(self.xform.id_string, "transportation_2011_07_25")
Ejemplo n.º 21
0
 def test_publish_bad_xls_with_unicode_in_error(self):
     """
     Check that publishing a bad xls where the error has a unicode character
     returns a 200, thus showing a readable error to the user
     """
     self._create_user_and_login()
     path = os.path.join(self.this_directory, "fixtures", "form_with_unicode_in_relevant_column.xlsx")
     response = MainTestCase._publish_xls_file(self, path)
     # make sure we get a 200 response
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 22
0
 def test_publish_bad_xls_with_unicode_in_error(self):
     """
     Check that publishing a bad xls where the error has a unicode character
     returns a 200, thus showing a readable error to the user
     """
     self._create_user_and_login()
     path = os.path.join(self.this_directory, 'fixtures',
                         'form_with_unicode_in_relevant_column.xlsx')
     response = MainTestCase._publish_xls_file(self, path)
     # make sure we get a 200 response
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 23
0
    def test_uuid_injection_in_cascading_select(self):
        """Test that the uuid is injected in the right instance node for
        forms with a cascading select"""
        pre_count = XForm.objects.count()
        xls_path = os.path.join(self.this_directory, "fixtures",
                                "cascading_selects",
                                "new_cascading_select.xls")
        file_name, file_ext = os.path.splitext(os.path.split(xls_path)[1])
        self.response = MainTestCase._publish_xls_file(self, xls_path)
        post_count = XForm.objects.count()
        self.assertEqual(post_count, pre_count + 1)
        xform = XForm.objects.latest('date_created')

        # check that the uuid is within the main instance/ the one without an id attribute
        xml = clean_and_parse_xml(xform.xml)

        # check for instance nodes that are direct children of the model node
        model_node = xml.getElementsByTagName("model")[0]
        instance_nodes = [
            node for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE and node.tagName.lower() ==
            "instance" and not node.hasAttribute("id")
        ]
        self.assertEqual(len(instance_nodes), 1)
        instance_node = instance_nodes[0]

        # get the first element whose id attribute is equal to our form's id_string
        form_nodes = [
            node for node in instance_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE
            and node.getAttribute("id") == xform.id_string
        ]
        form_node = form_nodes[0]

        # find the formhub node that has a uuid child node
        formhub_nodes = form_node.getElementsByTagName("formhub")
        self.assertEqual(len(formhub_nodes), 1)
        uuid_nodes = formhub_nodes[0].getElementsByTagName("uuid")
        self.assertEqual(len(uuid_nodes), 1)

        # check for the calculate bind
        calculate_bind_nodes = [
            node for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE and node.tagName == "bind"
            and node.getAttribute("nodeset") == "/%s/formhub/uuid" % file_name
        ]
        self.assertEqual(len(calculate_bind_nodes), 1)
        calculate_bind_node = calculate_bind_nodes[0]
        self.assertEqual(calculate_bind_node.getAttribute("calculate"),
                         "'%s'" % xform.uuid)
Ejemplo n.º 24
0
    def test_uuid_injection_in_cascading_select(self):
        """Test that the uuid is injected in the right instance node for
        forms with a cascading select"""
        pre_count = XForm.objects.count()
        xls_path = os.path.join(self.this_directory, "fixtures", "cascading_selects", "new_cascading_select.xls")
        file_name, file_ext = os.path.splitext(os.path.split(xls_path)[1])
        self.response = MainTestCase._publish_xls_file(self, xls_path)
        post_count = XForm.objects.count()
        self.assertEqual(post_count, pre_count + 1)
        xform = XForm.objects.latest("date_created")

        # check that the uuid is within the main instance/ the one without an id attribute
        xml = clean_and_parse_xml(xform.xml)

        # check for instance nodes that are direct children of the model node
        model_node = xml.getElementsByTagName("model")[0]
        instance_nodes = [
            node
            for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE and node.tagName.lower() == "instance" and not node.hasAttribute("id")
        ]
        self.assertEqual(len(instance_nodes), 1)
        instance_node = instance_nodes[0]

        # get the first element whose id attribute is equal to our form's id_string
        form_nodes = [
            node
            for node in instance_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE and node.getAttribute("id") == xform.id_string
        ]
        form_node = form_nodes[0]

        # find the formhub node that has a uuid child node
        formhub_nodes = form_node.getElementsByTagName("formhub")
        self.assertEqual(len(formhub_nodes), 1)
        uuid_nodes = formhub_nodes[0].getElementsByTagName("uuid")
        self.assertEqual(len(uuid_nodes), 1)

        # check for the calculate bind
        calculate_bind_nodes = [
            node
            for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE
            and node.tagName == "bind"
            and node.getAttribute("nodeset") == "/%s/formhub/uuid" % file_name
        ]
        self.assertEqual(len(calculate_bind_nodes), 1)
        calculate_bind_node = calculate_bind_nodes[0]
        self.assertEqual(calculate_bind_node.getAttribute("calculate"), "'%s'" % xform.uuid)
Ejemplo n.º 25
0
 def _publish_file(self, xls_path, strict=True):
     """
     Returns False if not strict and publish fails
     """
     pre_count = XForm.objects.count()
     self.response = MainTestCase._publish_xls_file(self, xls_path)
     # make sure publishing the survey worked
     self.assertEqual(self.response.status_code, 200)
     if XForm.objects.count() != pre_count + 1:
         # print file location
         print '\nPublish Failure for file: %s' % xls_path
         if strict:
             self.assertEqual(XForm.objects.count(), pre_count + 1)
         else:
             return False
     self.xform = list(XForm.objects.all())[-1]
     return True
Ejemplo n.º 26
0
 def _publish_file(self, xls_path, strict=True):
     """
     Returns False if not strict and publish fails
     """
     pre_count = XForm.objects.count()
     self.response = MainTestCase._publish_xls_file(self, xls_path)
     # make sure publishing the survey worked
     self.assertEqual(self.response.status_code, 200)
     if XForm.objects.count() != pre_count + 1:
         # print file location
         print '\nPublish Failure for file: %s' % xls_path
         if strict:
             self.assertEqual(XForm.objects.count(), pre_count + 1)
         else:
             return False
     self.xform = list(XForm.objects.all().order_by('date_created'))[-1]
     return True
Ejemplo n.º 27
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login('bob', 'bob')
     self._publish_transportation_form()
     self.url = reverse(formList, kwargs={'username': self.user.username})
Ejemplo n.º 28
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     self.url = reverse(clone_xlsform, kwargs={"username": self.user.username})
Ejemplo n.º 29
0
 def _publish_survey(self):
     self.this_directory = os.path.dirname(__file__)
     xls_path = os.path.join(self.this_directory, "fixtures", "gps",
                             "gps.xls")
     MainTestCase._publish_xls_file(self, xls_path)
Ejemplo n.º 30
0
 def _publish_survey(self):
     self.this_directory = os.path.dirname(__file__)
     xls_path = os.path.join(
         self.this_directory, "fixtures", "gps", "gps.xls")
     MainTestCase._publish_xls_file(self, xls_path)
Ejemplo n.º 31
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login()
     self._publish_transportation_form()
     self.url = reverse(clone_xlsform, kwargs={'username': self.user.username})
Ejemplo n.º 32
0
 def setUp(self):
     MainTestCase.setUp(self)
     self.settings_url = reverse(
         profile_settings, kwargs={'username': self.user.username})
Ejemplo n.º 33
0
 def setUp(self):
     MainTestCase.setUp(self)
     self._create_user_and_login('bob', 'bob')
     self._publish_transportation_form()
     self.url = reverse(formList, kwargs={'username': self.user.username})