Пример #1
0
 def test_add_form_tag_propagates_to_data_tags(self):
     """Test that when a tag is applied on an xform,
     it propagates to the instance submissions
     """
     view = XFormViewSet.as_view({
         'get': 'labels',
         'post': 'labels',
         'delete': 'labels'
     })
     # no tags
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1, formid=1)
     self.assertEqual(response.data, [])
     # add tag "hello"
     request = self.factory.post('/', data={"tags": "hello"}, **self.extra)
     response = view(request, owner='bob', pk=1, formid=1)
     self.assertEqual(response.status_code, 201)
     self.assertEqual(response.data, [u'hello'])
     for i in self.xform.surveys.all():
         self.assertIn(u'hello', i.tags.names())
     # remove tag "hello"
     request = self.factory.delete('/', data={"tags": "hello"},
                                   **self.extra)
     response = view(request, owner='bob', pk=1, formid=1, label='hello')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, [])
     for i in self.xform.surveys.all():
         self.assertNotIn(u'hello', i.tags.names())
Пример #2
0
 def test_form_get(self):
     self._publish_xls_form_to_project()
     view = XFormViewSet.as_view({'get': 'retrieve'})
     request = self.factory.get('/', **self.extra)
     response = view(request)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data,
                      {'detail': 'Expected URL keyword argument `owner`.'})
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.form_data)
Пример #3
0
 def test_form_get(self):
     self._publish_xls_form_to_project()
     view = XFormViewSet.as_view({
         'get': 'retrieve'
     })
     request = self.factory.get('/', **self.extra)
     response = view(request)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data,
                      {'detail': 'Expected URL keyword argument `owner`.'})
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.form_data)
Пример #4
0
    def test_form_format(self):
        self._publish_xls_form_to_project()
        view = XFormViewSet.as_view({
            'get': 'form'
        })
        formid = self.xform.pk
        data = {
            "title": "transportation_2011_07_25",
            "default_language": "default",
            "id_string": "transportation_2011_07_25",
            "type": "survey",
        }
        request = self.factory.get('/', **self.extra)
        response = view(request, owner='bob', pk=formid, format='json')
        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(data, response.data)
        self.assertRegexpMatches(response.data['name'], r'^transportation.*')
        
        tmpName = response.data['name']

        response = view(request, owner='bob', pk=formid, format='xml')
        self.assertEqual(response.status_code, 200)
        response_doc = minidom.parseString(response.data)

        xml_path = os.path.join(
            settings.PROJECT_ROOT, "main", "tests", "fixtures",
            "transportation", "transportation.xml")
        with open(xml_path) as xml_file:
            expected_doc = minidom.parse(xml_file)

        model_node = [
            n for n in
            response_doc.getElementsByTagName("h:head")[0].childNodes
            if n.nodeType == Node.ELEMENT_NODE and
            n.tagName == "model"][0]

        # check for UUID and remove
        uuid_nodes = [
            node for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE
            and node.getAttribute("nodeset") == "/"+tmpName+"/formhub/uuid"]
        self.assertEqual(len(uuid_nodes), 1)
        uuid_node = uuid_nodes[0]
        uuid_node.setAttribute("calculate", "''")

        # check content without UUID
        self.assertEqual(response_doc.toxml().replace(tmpName, "transportation") , expected_doc.toxml())
Пример #5
0
    def test_form_format(self):
        self._publish_xls_form_to_project()
        view = XFormViewSet.as_view({
            'get': 'form'
        })
        formid = self.xform.pk
        data = {
            "name": "transportation",
            "title": "transportation_2011_07_25",
            "default_language": "default",
            "id_string": "transportation_2011_07_25",
            "type": "survey",
        }
        request = self.factory.get('/', **self.extra)
        response = view(request, owner='bob', pk=formid, format='json')
        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(data, response.data)
        response = view(request, owner='bob', pk=formid, format='xml')
        self.assertEqual(response.status_code, 200)
        response_doc = minidom.parseString(response.data)

        xml_path = os.path.join(
            settings.PROJECT_ROOT, "main", "tests", "fixtures",
            "transportation", "transportation.xml")
        with open(xml_path) as xml_file:
            expected_doc = minidom.parse(xml_file)

        model_node = [
            n for n in
            response_doc.getElementsByTagName("h:head")[0].childNodes
            if n.nodeType == Node.ELEMENT_NODE and
            n.tagName == "model"][0]

        # check for UUID and remove
        uuid_nodes = [
            node for node in model_node.childNodes
            if node.nodeType == Node.ELEMENT_NODE
            and node.getAttribute("nodeset") == "/transportation/formhub/uuid"]
        self.assertEqual(len(uuid_nodes), 1)
        uuid_node = uuid_nodes[0]
        uuid_node.setAttribute("calculate", "''")

        # check content without UUID
        self.assertEqual(response_doc.toxml(), expected_doc.toxml())
Пример #6
0
 def test_form_tags(self):
     self._publish_xls_form_to_project()
     view = XFormViewSet.as_view({
         'get': 'labels',
         'post': 'labels',
         'delete': 'labels'
     })
     formid = self.xform.pk
     # no tags
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=formid)
     self.assertEqual(response.data, [])
     # add tag "hello"
     request = self.factory.post('/', data={"tags": "hello"}, **self.extra)
     response = view(request, owner='bob', pk=formid)
     self.assertEqual(response.status_code, 201)
     self.assertEqual(response.data, [u'hello'])
     # remove tag "hello"
     request = self.factory.delete('/', data={"tags": "hello"},
                                   **self.extra)
     response = view(request, owner='bob', pk=formid, label='hello')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, [])
Пример #7
0
 def test_form_tags(self):
     self._publish_xls_form_to_project()
     view = XFormViewSet.as_view({
         'get': 'labels',
         'post': 'labels',
         'delete': 'labels'
     })
     formid = self.xform.pk
     # no tags
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=formid)
     self.assertEqual(response.data, [])
     # add tag "hello"
     request = self.factory.post('/', data={"tags": "hello"}, **self.extra)
     response = view(request, owner='bob', pk=formid)
     self.assertEqual(response.status_code, 201)
     self.assertEqual(response.data, [u'hello'])
     # remove tag "hello"
     request = self.factory.delete('/', data={"tags": "hello"},
                                   **self.extra)
     response = view(request, owner='bob', pk=formid, label='hello')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, [])
Пример #8
0
 def setUp(self):
     super(TestFormsAPI, self).setUp()
     self.view = XFormViewSet.as_view({
         'get': 'list',
     })
Пример #9
0
 def setUp(self):
     super(TestFormsAPI, self).setUp()
     self.view = XFormViewSet.as_view({
         'get': 'list',
     })