コード例 #1
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()
        TestBase._publish_xls_file(self, xls_path)

        self.assertEqual(XForm.objects.count(), count + 1)
        self.xform = XForm.objects.all().reverse()[0]
コード例 #2
0
ファイル: test_form_gallery.py プロジェクト: onaio/onadata
    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()
        TestBase._publish_xls_file(self, xls_path)

        self.assertEqual(XForm.objects.count(), count + 1)
        self.xform = XForm.objects.all().reverse()[0]
コード例 #3
0
    def test_uuid_injection_in_cascading_select(self):
        """
        Uuid is injected in the right instance for forms with 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])
        TestBase._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)
コード例 #4
0
 def _publish_file(self, xls_path, strict=True):
     """
     Return False if not strict and publish fails
     """
     pre_count = XForm.objects.count()
     TestBase._publish_xls_file(self, xls_path)
     # make sure publishing the survey worked
     if XForm.objects.count() != pre_count + 1:
         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
コード例 #5
0
ファイル: test_kml_export.py プロジェクト: Azique/kobocat
 def _publish_survey(self):
     self.this_directory = os.path.dirname(__file__)
     xls_path = self._fixture_path("gps", "gps.xls")
     TestBase._publish_xls_file(self, xls_path)
コード例 #6
0
 def _publish_survey(self):
     self.this_directory = os.path.dirname(__file__)
     xls_path = self._fixture_path("gps", "gps.xls")
     TestBase._publish_xls_file(self, xls_path)