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

Don't check for dynamic label if there is no label #535

Merged
merged 1 commit into from
May 13, 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
74 changes: 74 additions & 0 deletions pyxform/tests_v1/test_choices_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
from pyxform.tests_v1.pyxform_test_case import PyxformTestCase
from pyxform.utils import unicode


class ChoicesSheetTest(PyxformTestCase):
def test_numeric_choice_names__for_static_selects__allowed(self):
"""
Test numeric choice names for static selects.
"""
self.assertPyxformXform(
md="""
| survey | | | |
| | type | name | label |
| | select_one choices | a | A |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | One |
| | choices | 2 | Two |
""",
xml__contains=["<value>1</value>"],
)

def test_numeric_choice_names__for_dynamic_selects__allowed(self):
"""
Test numeric choice names for dynamic selects.
"""
self.assertPyxformXform(
md="""
| survey | | | | |
| | type | name | label | choice_filter |
| | select_one choices | a | A | true() |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | One |
| | choices | 2 | Two |
""",
xml__contains=['<instance id="choices">', "<item>", "<name>1</name>"],
)

def test_choices_without_labels__for_static_selects__allowed(self):
"""
Test choices without labels for static selects. Validate will NOT fail.
"""
self.assertPyxformXform(
md="""
| survey | | | |
| | type | name | label |
| | select_one choices | a | A |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | |
| | choices | 2 | |
""",
xml__contains=["<value>1</value>"],
)

def test_choices_without_labels__for_dynamic_selects__allowed_by_pyxform(self):
"""
Test choices without labels for dynamic selects. Validate will fail.
"""
self.assertPyxformXform(
md="""
| survey | | | | |
| | type | name | label | choice_filter |
| | select_one choices | a | A | true() |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | |
| | choices | 2 | |
""",
run_odk_validate=False,
xml__contains=['<instance id="choices">', "<item>", "<name>1</name>"],
)
6 changes: 5 additions & 1 deletion pyxform/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ def default_is_dynamic(element_default, element_type=None):
def has_dynamic_label(choice_list, multi_language):
if not multi_language:
for i in range(0, min(2, len(choice_list))):
if re.search(BRACKETED_TAG_REGEX, choice_list[i].get("label")) is not None:
if (
choice_list[i].get("label") is not None
and re.search(BRACKETED_TAG_REGEX, choice_list[i].get("label"))
is not None
):
return True
return False