Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional manifest url #1543

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onadata/apps/api/tests/fixtures/formList.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<xforms xmlns="http://openrosa.org/xforms/xformsList"><xform><formID>transportation_2011_07_25</formID><name>transportation_2011_07_25</name><version>2014111</version><hash>%(hash)s</hash><descriptionText></descriptionText><downloadUrl>http://testserver/bob/forms/%(pk)s/form.xml</downloadUrl><manifestUrl></manifestUrl></xform></xforms>
<xforms xmlns="http://openrosa.org/xforms/xformsList"><xform><formID>transportation_2011_07_25</formID><name>transportation_2011_07_25</name><version>2014111</version><hash>%(hash)s</hash><descriptionText></descriptionText><downloadUrl>http://testserver/bob/forms/%(pk)s/form.xml</downloadUrl></xform></xforms>
8 changes: 4 additions & 4 deletions onadata/apps/api/tests/viewsets/test_xform_list_viewset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from builtins import open
from hashlib import md5

from builtins import open
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TransactionTestCase
Expand Down Expand Up @@ -894,9 +894,9 @@ def test_get_xform_anonymous_user_xform_require_auth(self):
# success with authentication
self.assertEqual(response.status_code, 200)

def test_manifest_url_tag_is_empty_when_no_media(self):
def test_manifest_url_tag_is_not_present_when_no_media(self):
"""
Test that content contains an empty tag for manifest url
Test that content does not contain a manifest url
only when the form has no media
"""
request = self.factory.get('/')
Expand All @@ -905,7 +905,7 @@ def test_manifest_url_tag_is_empty_when_no_media(self):
self.assertEqual(response.status_code, 200)
content = response.render().content.decode('utf-8')
manifest_url = ('<manifestUrl></manifestUrl>')
self.assertTrue(manifest_url in content)
self.assertNotIn(manifest_url, content)

# Add media and test that manifest url exists
data_type = 'media'
Expand Down
17 changes: 8 additions & 9 deletions onadata/apps/main/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import json
import os
import re
import pytz
from builtins import open
from datetime import datetime
from future.utils import iteritems
from hashlib import md5
from mock import patch
from xml.dom import minidom, Node

from django.core.urlresolvers import reverse
import pytz
from builtins import open
from django.conf import settings
from django_digest.test import Client as DigestClient
from django.core.files.uploadedfile import UploadedFile
from django.core.urlresolvers import reverse
from django_digest.test import Client as DigestClient
from future.utils import iteritems
from mock import patch
from xlrd import open_workbook
from xml.dom import minidom, Node

from onadata.apps.logger.models import XForm
from onadata.apps.logger.models.xform import XFORM_TITLE_LENGTH
Expand All @@ -26,7 +26,6 @@
from onadata.libs.utils.common_tags import MONGO_STRFTIME
from onadata.libs.utils.common_tools import get_response_content


uuid_regex = re.compile(
r'(</instance>.*uuid[^//]+="\')([^\']+)(\'".*)', re.DOTALL)

Expand Down Expand Up @@ -217,7 +216,7 @@ def _check_formlist(self):
% (self.user.username, self.xform.pk)
md5_hash = md5(self.xform.xml.encode('utf-8')).hexdigest()
expected_content = """<?xml version="1.0" encoding="utf-8"?>
<xforms xmlns="http://openrosa.org/xforms/xformsList"><xform><formID>transportation_2011_07_25</formID><name>transportation_2011_07_25</name><version>2014111</version><hash>md5:%(hash)s</hash><descriptionText></descriptionText><downloadUrl>%(download_url)s</downloadUrl><manifestUrl></manifestUrl></xform></xforms>""" # noqa
<xforms xmlns="http://openrosa.org/xforms/xformsList"><xform><formID>transportation_2011_07_25</formID><name>transportation_2011_07_25</name><version>2014111</version><hash>md5:%(hash)s</hash><descriptionText></descriptionText><downloadUrl>%(download_url)s</downloadUrl></xform></xforms>""" # noqa
expected_content = expected_content % {
'download_url': self.download_url,
'hash': md5_hash
Expand Down
16 changes: 12 additions & 4 deletions onadata/libs/renderers/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import math
from io import BytesIO

from future.utils import iteritems

import pytz
from django.utils.dateparse import parse_datetime
from django.utils.encoding import smart_text
from django.utils.xmlutils import SimplerXMLGenerator

import pytz
from future.utils import iteritems
from rest_framework import negotiation
from rest_framework.compat import six
from rest_framework.renderers import (BaseRenderer, JSONRenderer,
Expand All @@ -31,6 +29,14 @@
'meta/sessionID',
]

FORMLIST_MANDATORY_FIELDS = [
'formID',
'name',
'version',
'hash',
'downloadUrl'
]


def pairing(val1, val2):
"""
Expand Down Expand Up @@ -244,6 +250,8 @@ def _to_xml(self, xml, data):

elif isinstance(data, dict):
for (key, value) in iteritems(data):
if key not in FORMLIST_MANDATORY_FIELDS and value is None:
continue
xml.startElement(key, {})
self._to_xml(xml, value)
xml.endElement(key)
Expand Down