-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for getting xml element + encoding tests
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version='1.0' encoding='{encoding}' ?> | ||
<form xmlns="http://commcarehq.org/couchforms-tests"> | ||
<meta> | ||
<instanceID>{form_id}</instanceID> | ||
</meta> | ||
<test>{sample_value}</test> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8 | ||
|
||
import uuid | ||
import os | ||
from couchforms.util import post_xform_to_couch | ||
from django.utils.unittest.case import TestCase | ||
|
||
|
||
class XMLElementTest(TestCase): | ||
|
||
def test_various_encodings(self): | ||
tests = ( | ||
('utf-8', u'हिन्दी चट्टानों'), | ||
('UTF-8', u'हिन्दी चट्टानों'), | ||
('ASCII', 'hello'), | ||
) | ||
file_path = os.path.join(os.path.dirname(__file__), "data", "encoding.xml") | ||
with open(file_path, "rb") as f: | ||
xml_template = f.read() | ||
|
||
for encoding, value in tests: | ||
xml_data = xml_template.format( | ||
encoding=encoding, | ||
form_id=uuid.uuid4().hex, | ||
sample_value=value.encode(encoding), | ||
) | ||
xform = post_xform_to_couch(xml_data) | ||
self.assertEqual(value, xform.form['test']) | ||
elem = xform.get_xml_element() | ||
self.assertEqual(value, elem.find('{http://commcarehq.org/couchforms-tests}test').text) |