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

Add support for odk:recordaudio #519

Merged
merged 8 commits into from
Feb 17, 2021
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
5 changes: 5 additions & 0 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@
CURRENT_XFORMS_VERSION = "1.0.0"

DEPRECATED_DEVICE_ID_METADATA_FIELDS = ["subscriberid", "simserial"]

AUDIO_QUALITY_VOICE_ONLY = "voice-only"
AUDIO_QUALITY_LOW = "low"
AUDIO_QUALITY_NORMAL = "normal"
AUDIO_QUALITY_EXTERNAL = "external"
5 changes: 5 additions & 0 deletions pyxform/question_type_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,9 @@ def generate_new_dict():
"bind": {"type": "geopoint"},
"action": {"name": "odk:setgeopoint", "event": "odk-instance-first-load"},
},
"background-audio": {
"control": {"tag": "action"},
seadowg marked this conversation as resolved.
Show resolved Hide resolved
"bind": {"type": "binary"},
"action": {"name": "odk:recordaudio", "event": "odk-instance-load"},
},
}
3 changes: 2 additions & 1 deletion pyxform/tests_v1/pyxform_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def assertContains(self, content, text, count=None, msg_prefix=""):
)
else:
self.assertTrue(
real_count != 0, msg_prefix + "Couldn't find %s in content" % text_repr
real_count != 0,
msg_prefix + "Couldn't find %s in content:\n" % text_repr + content,
seadowg marked this conversation as resolved.
Show resolved Hide resolved
)

def assertNotContains(self, content, text, msg_prefix=""):
Expand Down
81 changes: 81 additions & 0 deletions pyxform/tests_v1/test_background_audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
from pyxform.tests_v1.pyxform_test_case import PyxformTestCase


class BackgroundAudioTest(PyxformTestCase):
def test_background_audio(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | |
| | type | name |
| | background-audio | my_recording |
""",
xml__contains=[
'<bind nodeset="/data/my_recording" type="binary"/>',
'<odk:recordaudio event="odk-instance-load" ref="/data/my_recording"/>',
seadowg marked this conversation as resolved.
Show resolved Hide resolved
],
)

def test_background_audio_voice_only(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | parameters |
| | background-audio | my_recording | quality=voice-only |
""",
xml__contains=[
'<odk:recordaudio event="odk-instance-load" ref="/data/my_recording" odk:quality="voice-only"/>',
],
)

def test_background_audio_low(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | parameters |
| | background-audio | my_recording | quality=low |
""",
xml__contains=[
'<odk:recordaudio event="odk-instance-load" ref="/data/my_recording" odk:quality="low"/>',
],
)

def test_background_audio_normal(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | parameters |
| | background-audio | my_recording | quality=normal |
""",
xml__contains=[
'<odk:recordaudio event="odk-instance-load" ref="/data/my_recording" odk:quality="normal"/>',
],
)

def test_external_quality_fails(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | parameters |
| | background-audio | my_recording | quality=external |
""",
errored=True,
error__contains=["Invalid value for quality."],
)

def test_foo_quality_fails(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | parameters |
| | background-audio | my_recording | quality=foo |
""",
errored=True,
error__contains=["Invalid value for quality."],
)
2 changes: 1 addition & 1 deletion pyxform/validators/odk_validate/.last_check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-09-09T22:12:52Z
2021-02-17T17:36:35Z
Binary file modified pyxform/validators/odk_validate/bin/ODK_Validate.jar
Binary file not shown.
48 changes: 24 additions & 24 deletions pyxform/validators/odk_validate/bin/installed.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"assets": [
{
"browser_download_url": "https://github.com/getodk/validate/releases/download/v1.15.0/ODK-Validate-v1.15.0.jar",
"browser_download_url": "https://github.com/getodk/validate/releases/download/v1.16.0/ODK-Validate-v1.16.0.jar",
"content_type": "application/java-archive",
"created_at": "2020-09-09T22:10:24Z",
"download_count": 0,
"id": 25270722,
"created_at": "2021-02-17T17:18:34Z",
"download_count": 1,
"id": 32212241,
"label": null,
"name": "ODK-Validate-v1.15.0.jar",
"node_id": "MDEyOlJlbGVhc2VBc3NldDI1MjcwNzIy",
"size": 1634611,
"name": "ODK-Validate-v1.16.0.jar",
"node_id": "MDEyOlJlbGVhc2VBc3NldDMyMjEyMjQx",
"size": 1640452,
"state": "uploaded",
"updated_at": "2020-09-09T22:10:31Z",
"updated_at": "2021-02-17T17:18:38Z",
"uploader": {
"avatar_url": "https://avatars3.githubusercontent.com/u/967540?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/967540?v=4",
"events_url": "https://api.github.com/users/lognaturel/events{/privacy}",
"followers_url": "https://api.github.com/users/lognaturel/followers",
"following_url": "https://api.github.com/users/lognaturel/following{/other_user}",
Expand All @@ -32,12 +32,12 @@
"type": "User",
"url": "https://api.github.com/users/lognaturel"
},
"url": "https://api.github.com/repos/getodk/validate/releases/assets/25270722"
"url": "https://api.github.com/repos/getodk/validate/releases/assets/32212241"
}
],
"assets_url": "https://api.github.com/repos/getodk/validate/releases/31011277/assets",
"assets_url": "https://api.github.com/repos/getodk/validate/releases/38181391/assets",
"author": {
"avatar_url": "https://avatars3.githubusercontent.com/u/967540?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/967540?v=4",
"events_url": "https://api.github.com/users/lognaturel/events{/privacy}",
"followers_url": "https://api.github.com/users/lognaturel/followers",
"following_url": "https://api.github.com/users/lognaturel/following{/other_user}",
Expand All @@ -56,19 +56,19 @@
"type": "User",
"url": "https://api.github.com/users/lognaturel"
},
"body": "[All changes](https://github.com/opendatakit/validate/compare/v1.14.0..v1.15.0)\r\n\r\n**Highlights**\r\n* Upgrade to [JavaRosa v3.0.0](https://github.com/opendatakit/javarosa/releases/tag/v3.0.0)\r\n",
"created_at": "2020-09-09T22:05:47Z",
"body": "**Highlights**\r\n * Upgrade to [JavaRosa v3.1.0](https://github.com/getodk/javarosa/releases/tag/v3.1.0)",
"created_at": "2021-02-17T16:50:50Z",
"draft": false,
"html_url": "https://github.com/getodk/validate/releases/tag/v1.15.0",
"id": 31011277,
"name": "ODK Validate v1.15.0",
"node_id": "MDc6UmVsZWFzZTMxMDExMjc3",
"html_url": "https://github.com/getodk/validate/releases/tag/v1.16.0",
"id": 38181391,
"name": "ODK Validate v1.16.0",
"node_id": "MDc6UmVsZWFzZTM4MTgxMzkx",
"prerelease": false,
"published_at": "2020-09-09T22:09:38Z",
"tag_name": "v1.15.0",
"tarball_url": "https://api.github.com/repos/getodk/validate/tarball/v1.15.0",
"published_at": "2021-02-17T17:16:50Z",
"tag_name": "v1.16.0",
"tarball_url": "https://api.github.com/repos/getodk/validate/tarball/v1.16.0",
"target_commitish": "master",
"upload_url": "https://uploads.github.com/repos/getodk/validate/releases/31011277/assets{?name,label}",
"url": "https://api.github.com/repos/getodk/validate/releases/31011277",
"zipball_url": "https://api.github.com/repos/getodk/validate/zipball/v1.15.0"
"upload_url": "https://uploads.github.com/repos/getodk/validate/releases/38181391/assets{?name,label}",
"url": "https://api.github.com/repos/getodk/validate/releases/38181391",
"zipball_url": "https://api.github.com/repos/getodk/validate/zipball/v1.16.0"
}
26 changes: 22 additions & 4 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,10 +1294,10 @@ def replace_prefix(d, prefix):

if "quality" in parameters.keys():
if parameters["quality"] not in [
"voice-only",
"low",
"normal",
"external",
constants.AUDIO_QUALITY_VOICE_ONLY,
constants.AUDIO_QUALITY_LOW,
constants.AUDIO_QUALITY_NORMAL,
constants.AUDIO_QUALITY_EXTERNAL,
]:
raise PyXFormError("Invalid value for quality.")

Expand All @@ -1307,6 +1307,24 @@ def replace_prefix(d, prefix):
parent_children_array.append(new_dict)
continue

if question_type == "background-audio":
new_dict = row.copy()
parameters = get_parameters(row.get("parameters", ""), ["quality"])

if "quality" in parameters.keys():
if parameters["quality"] not in [
constants.AUDIO_QUALITY_VOICE_ONLY,
constants.AUDIO_QUALITY_LOW,
constants.AUDIO_QUALITY_NORMAL,
]:
raise PyXFormError("Invalid value for quality.")

new_dict["action"] = new_dict.get("action", {})
new_dict["action"].update({"odk:quality": parameters["quality"]})

parent_children_array.append(new_dict)
continue

# TODO: Consider adding some question_type validation here.

# Put the row in the json dict as is:
Expand Down