Skip to content

Commit

Permalink
Only allow big-image if image is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Jan 13, 2023
1 parent 8d3fccb commit 816bca0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pyxform/survey_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,15 @@ def xml_label_and_hint(self) -> "List[DetachableElement]":
msg = "The survey element named '%s' " "has no label or hint." % self.name
if len(result) == 0:
raise PyXFormError(msg)

# Guidance hint alone is not OK since they may be hidden by default.
if not any((self.label, self.media, self.hint)) and self.guidance_hint:
raise PyXFormError(msg)

# big-image must combine with image
if not ("image" in self.media) and "big-image" in self.media:
raise PyXFormError("You must specify an image in order to use big-image.")

return result

def xml_bindings(self):
Expand Down
14 changes: 13 additions & 1 deletion tests/test_sheet_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_missing_name_but_has_alias_of_name(self):
errored=False,
)

def test_missing_label(self):
def test_label_or_hint__must_be_provided(self):
self.assertPyxformXform(
name="invalidcols",
ss_structure={"survey": [{"type": "text", "name": "q1"}]},
Expand Down Expand Up @@ -63,6 +63,18 @@ def test_label_node_added_when_hint_given_but_no_label_value(self):
xml__contains=prep_for_xml_contains(expected),
)

def test_big_image_invalid_if_no_image(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | media::big-image |
| | text | c | m.png |
""",
errored=True,
error__contains=["must specify an image"],
)

def test_column_case(self):
"""
Ensure that column name is case insensitive
Expand Down

0 comments on commit 816bca0

Please sign in to comment.