Skip to content

Commit

Permalink
Fix XML attribute order and response bytestring…
Browse files Browse the repository at this point in the history
issues in unit tests
  • Loading branch information
jnm committed May 25, 2021
1 parent 09e7da8 commit 46b6650
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion onadata/apps/api/tests/fixtures/Transportation Form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<bind nodeset="/transportation_2011_07_25/transport/loop_over_transport_types_frequency/motorbike/frequency_to_referral_facility" relevant="selected( /transportation_2011_07_25/transport/available_transportation_types_to_referral_facility , 'motorbike')" type="string"/>
<bind nodeset="/transportation_2011_07_25/transport/loop_over_transport_types_frequency/taxi/frequency_to_referral_facility" relevant="selected( /transportation_2011_07_25/transport/available_transportation_types_to_referral_facility , 'taxi')" type="string"/>
<bind jr:preload="uid" nodeset="/transportation_2011_07_25/meta/instanceID" readonly="true()" type="string"/>
<bind calculate="'%(form_uuid)s'" nodeset="/transportation_2011_07_25/formhub/uuid" type="string"/>
<bind nodeset="/transportation_2011_07_25/formhub/uuid" type="string" calculate="'%(form_uuid)s'"/>
</model>
</h:head>
<h:body>
Expand Down
4 changes: 2 additions & 2 deletions onadata/apps/api/tests/viewsets/test_xform_list_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_get_xform_list_with_formid_parameter(self):
with open(path) as f:
form_list_xml = f.read().strip()
data = {"hash": self.xform.hash, "pk": self.xform.pk}
content = response.render().content
content = response.render().content.decode('utf-8')
self.assertEqual(content, form_list_xml % data)

def test_retrieve_xform_xml(self):
Expand All @@ -247,7 +247,7 @@ def test_retrieve_xform_xml(self):
os.path.dirname(__file__),
'..', 'fixtures', 'Transportation Form.xml')

with open(path, 'r') as f:
with open(path) as f:
form_xml = f.read().strip()
data = {"form_uuid": self.xform.uuid}
content = smart_str(response.render().content).strip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<bind nodeset="/transportation_2011_07_25/transport/loop_over_transport_types_frequency/motorbike/frequency_to_referral_facility" relevant="selected( /transportation_2011_07_25/transport/available_transportation_types_to_referral_facility , 'motorbike')" type="string"/>
<bind nodeset="/transportation_2011_07_25/transport/loop_over_transport_types_frequency/taxi/frequency_to_referral_facility" relevant="selected( /transportation_2011_07_25/transport/available_transportation_types_to_referral_facility , 'taxi')" type="string"/>
<bind jr:preload="uid" nodeset="/transportation_2011_07_25/meta/instanceID" readonly="true()" type="string"/>
<bind calculate="''" nodeset="/transportation_2011_07_25/formhub/uuid" type="string" />
<bind nodeset="/transportation_2011_07_25/formhub/uuid" type="string" calculate="''" />
</model>
</h:head>
<h:body>
Expand Down
5 changes: 1 addition & 4 deletions onadata/apps/main/tests/test_past_bugs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding: utf-8
import os

from django.utils.encoding import smart_text

from onadata.apps.logger.models import XForm, Instance
from .test_base import TestBase

Expand All @@ -19,8 +17,7 @@ def test_uniqueness_of_group_names_enforced(self):
response = self._publish_xls_file(
'fixtures/group_names_must_be_unique.xls')
message = 'The name "group_names_must_be_unique" is the same as the form name'
response_content = smart_text(response.content)
self.assertTrue(message in response_content)
self.assertTrue(message in response.json()['text'])
self.assertEqual(XForm.objects.count(), pre_count)

def test_mch(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding: utf-8
import os

from django.utils.encoding import smart_text

from onadata.apps.logger.models import XForm
from .test_base import TestBase

Expand All @@ -25,12 +23,11 @@ def test_unique_together(self):

# second time
response = self._publish_xls_file(xls_path)
response_content = smart_text(response.content)
# SQLite returns `UNIQUE constraint failed` whereas PostgreSQL
# returns 'duplicate key ... violates unique constraint'
self.assertIn(
'unique constraint',
response_content.lower(),
response.json()['text'].lower(),
)
self.assertEqual(XForm.objects.count(), 1)
self.client.logout()
Expand Down

0 comments on commit 46b6650

Please sign in to comment.