diff --git a/onadata/apps/api/tests/viewsets/test_briefcase_api.py b/onadata/apps/api/tests/viewsets/test_briefcase_api.py
index b62c41186..f44704b94 100644
--- a/onadata/apps/api/tests/viewsets/test_briefcase_api.py
+++ b/onadata/apps/api/tests/viewsets/test_briefcase_api.py
@@ -3,7 +3,6 @@
from django.urls import reverse
from django.core.files.storage import get_storage_class
-from django.utils.encoding import smart_str
from django_digest.test import DigestAuth
from rest_framework.test import APIRequestFactory
@@ -224,7 +223,7 @@ def test_view_download_submission(self):
text = text.replace('{{xform_uuid}}',
self.xform.uuid)
self.assertContains(response, instance_id, status_code=200)
- self.assertMultiLineEqual(smart_str(response.content), text)
+ self.assertMultiLineEqual(response.content.decode('utf-8'), text)
def test_view_download_submission_other_user(self):
view = BriefcaseApi.as_view({'get': 'retrieve'})
diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py
index fb2dd09f0..cdc145726 100644
--- a/onadata/apps/api/tests/viewsets/test_data_viewset.py
+++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py
@@ -21,7 +21,7 @@
def enketo_mock(url, request):
response = requests.Response()
response.status_code = 201
- response._content = '{"url": "https://hmh2a.enketo.formhub.org"}'
+ response._content = b'{"url": "https://hmh2a.enketo.formhub.org"}'
return response
diff --git a/onadata/apps/api/tests/viewsets/test_xform_list_api.py b/onadata/apps/api/tests/viewsets/test_xform_list_api.py
index 8c53d706b..42a263950 100644
--- a/onadata/apps/api/tests/viewsets/test_xform_list_api.py
+++ b/onadata/apps/api/tests/viewsets/test_xform_list_api.py
@@ -3,7 +3,6 @@
from django.conf import settings
from django_digest.test import DigestAuth
-from django.utils.encoding import smart_str
from guardian.shortcuts import assign_perm
from onadata.apps.api.tests.viewsets.test_abstract_viewset import\
@@ -40,7 +39,7 @@ def test_get_xform_list(self):
form_list_xml = f.read().strip()
data = {"hash": self.xform.hash, "pk": self.xform.pk}
content = response.render().content
- self.assertEqual(smart_str(content), form_list_xml % data)
+ self.assertEqual(content.decode('utf-8'), form_list_xml % data)
self.assertTrue(response.has_header('X-OpenRosa-Version'))
self.assertTrue(
response.has_header('X-OpenRosa-Accept-Content-Length'))
@@ -61,7 +60,7 @@ def test_get_xform_list_inactive_form(self):
xml = '\n'
- content = smart_str(response.render().content)
+ content = response.render().content.decode('utf-8')
self.assertEqual(content, xml)
self.assertTrue(response.has_header('X-OpenRosa-Version'))
self.assertTrue(
@@ -85,7 +84,7 @@ def test_get_xform_list_anonymous_user(self):
form_list_xml = f.read().strip()
data = {"hash": self.xform.hash, "pk": self.xform.pk}
content = response.render().content
- self.assertEqual(smart_str(content), form_list_xml % data)
+ self.assertEqual(content.decode('utf-8'), form_list_xml % data)
self.assertTrue(response.has_header('X-OpenRosa-Version'))
self.assertTrue(
response.has_header('X-OpenRosa-Accept-Content-Length'))
@@ -121,7 +120,7 @@ def test_get_xform_list_other_user_with_no_role(self):
request.META.update(auth(request.META, response))
response = self.view(request)
self.assertEqual(response.status_code, 200)
- content = smart_str(response.render().content)
+ content = response.render().content.decode('utf-8')
self.assertNotIn(self.xform.id_string, content)
self.assertEqual(
content, '\n\nscreenshot.png%(hash)shttp://testserver/bob/xformsMedia/%(xform)s/%(pk)s.png""" # noqa
data = {"hash": self.metadata.hash, "pk": self.metadata.pk,
"xform": self.xform.pk}
- content = smart_str(response.render().content).strip()
+ content = response.render().content.decode('utf-8').strip()
self.assertEqual(content, manifest_xml % data)
self.assertTrue(response.has_header('X-OpenRosa-Version'))
self.assertTrue(
@@ -306,7 +305,7 @@ def test_retrieve_xform_manifest_anonymous_user(self):
screenshot.png%(hash)shttp://testserver/bob/xformsMedia/%(xform)s/%(pk)s.png""" # noqa
data = {"hash": self.metadata.hash, "pk": self.metadata.pk,
"xform": self.xform.pk}
- content = smart_str(response.render().content).strip()
+ content = response.render().content.decode('utf-8').strip()
self.assertEqual(content, manifest_xml % data)
self.assertTrue(response.has_header('X-OpenRosa-Version'))
self.assertTrue(
diff --git a/onadata/apps/api/tests/viewsets/test_xform_submission_api.py b/onadata/apps/api/tests/viewsets/test_xform_submission_api.py
index 37dca4e79..bbec28dcf 100644
--- a/onadata/apps/api/tests/viewsets/test_xform_submission_api.py
+++ b/onadata/apps/api/tests/viewsets/test_xform_submission_api.py
@@ -4,7 +4,6 @@
import simplejson as json
from django.contrib.auth.models import AnonymousUser
from django.core.files.uploadedfile import InMemoryUploadedFile
-from django.utils.encoding import smart_str
from django_digest.test import DigestAuth
from guardian.shortcuts import assign_perm
@@ -163,8 +162,8 @@ def test_post_submission_authenticated_bad_json(self):
'..',
'fixtures',
'transport_submission_bad.json')
- with open(path, 'rb') as f:
- data = json.loads(smart_str(f.read()))
+ with open(path) as f:
+ data = json.loads(f.read())
request = self.factory.post('/submission', data, format='json')
response = self.view(request)
self.assertEqual(response.status_code, 401)
@@ -175,8 +174,11 @@ def test_post_submission_authenticated_bad_json(self):
response = self.view(request)
rendered_response = response.render()
self.assertTrue('error' in rendered_response.data)
- self.assertTrue(smart_str(rendered_response.data['error']).
- startswith("b'Received empty submission"))
+ self.assertTrue(
+ rendered_response.data['error'].startswith(
+ 'Received empty submission'
+ )
+ )
self.assertTrue(rendered_response.status_code == 400)
self.assertTrue(rendered_response.has_header('X-OpenRosa-Version'))
self.assertTrue(
diff --git a/onadata/apps/api/viewsets/xform_submission_api.py b/onadata/apps/api/viewsets/xform_submission_api.py
index 0d27ccb3b..47423a513 100644
--- a/onadata/apps/api/viewsets/xform_submission_api.py
+++ b/onadata/apps/api/viewsets/xform_submission_api.py
@@ -5,7 +5,6 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
-from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
from rest_framework import permissions
@@ -211,9 +210,11 @@ def error_response(self, error, is_json_request, request):
elif not is_json_request:
return error
else:
- error_msg = xml_error_re.search(smart_str(error.content)).groups()[0]
+ error_msg = xml_error_re.search(
+ error.content.decode('utf-8')
+ ).groups()[0]
status_code = error.status_code
- return Response({'error': smart_str(error_msg)},
+ return Response({'error': error_msg},
headers=self.get_openrosa_headers(request),
status=status_code)
diff --git a/onadata/apps/logger/xform_instance_parser.py b/onadata/apps/logger/xform_instance_parser.py
index f65f668ee..21b93c305 100644
--- a/onadata/apps/logger/xform_instance_parser.py
+++ b/onadata/apps/logger/xform_instance_parser.py
@@ -122,7 +122,7 @@ def get_deprecated_uuid_from_xml(xml):
def clean_and_parse_xml(xml_string):
clean_xml_str = xml_string.strip()
clean_xml_str = re.sub(r">\s+<", "><", smart_str(clean_xml_str))
- xml_obj = minidom.parseString(smart_str(clean_xml_str))
+ xml_obj = minidom.parseString(clean_xml_str)
return xml_obj
diff --git a/onadata/libs/utils/logger_tools.py b/onadata/libs/utils/logger_tools.py
index cb2d1a58e..636cba311 100644
--- a/onadata/libs/utils/logger_tools.py
+++ b/onadata/libs/utils/logger_tools.py
@@ -558,10 +558,14 @@ class OpenRosaResponse(BaseOpenRosaResponse):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# wrap content around xml
- self.content = '''
-
- %s
-''' % self.content
+ self.content = (
+ b"\n"
+ b'\n'
+ b' '
+ ) + self.content + (
+ b'\n'
+ b''
+ )
class OpenRosaResponseNotFound(OpenRosaResponse):
diff --git a/onadata/libs/utils/viewer_tools.py b/onadata/libs/utils/viewer_tools.py
index 1d2e036ae..e266d72b7 100644
--- a/onadata/libs/utils/viewer_tools.py
+++ b/onadata/libs/utils/viewer_tools.py
@@ -12,7 +12,6 @@
from django.core.files.storage import get_storage_class
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.mail import mail_admins
-from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
from onadata.libs.utils import common_tags
@@ -204,8 +203,7 @@ def enketo_url(form_url, id_string, instance_xml=None,
if req.status_code in [200, 201]:
try:
- # ToDo find out why req.json() does not work
- response = json.loads(smart_str(req.content))
+ response = req.json()
except ValueError:
pass
else:
@@ -217,7 +215,7 @@ def enketo_url(form_url, id_string, instance_xml=None,
return response['url']
else:
try:
- response = json.loads(smart_str(req.content))
+ response = req.json()
except ValueError:
pass
else: