Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Sep 21, 2023
1 parent 57cc033 commit e71f095
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 11 additions & 5 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,13 @@ def workbook_to_json(

if row.get("default"):
new_dict["default"] = process_image_default(row["default"])
parameters_generic.validate(parameters=parameters, allowed=("max-pixels","app",))
parameters_generic.validate(
parameters=parameters,
allowed=(
"max-pixels",
"app",
),
)
if "max-pixels" in parameters.keys():
try:
int(parameters["max-pixels"])
Expand All @@ -1326,13 +1332,13 @@ def workbook_to_json(
)

if "app" in parameters.keys():
android_package_regex_pattern = "^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$"
android_package_regex_pattern = (
"^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$"
)
app_package_name = str(parameters["app"])
if re.fullmatch(android_package_regex_pattern, app_package_name):
new_dict["control"] = new_dict.get("control", {})
new_dict["control"].update(
{"intent": app_package_name}
)
new_dict["control"].update({"intent": app_package_name})
else:
raise PyXFormError("Invalid Android package name format")

Expand Down
11 changes: 4 additions & 7 deletions tests/test_image_app_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@


class ImageAppParameterTest(PyxformTestCase):

def test_valid_android_package_name(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | | |
| | type | name | label | parameters |
| | image | my_image | Image | app=com.jeyluta.timestampcamerafree |
| | image | my_image | Image | app=com.jeyluta.timestampcamerafree |
""",
xml__xpath_match=[
"/h:html/h:body/x:upload[@intent='com.jeyluta.timestampcamerafree' and @mediatype='image/*' and @ref='/data/my_image']"
Expand All @@ -27,9 +26,7 @@ def test_invalid_android_package_name(self):
md="""
| survey | | | | |
| | type | name | label | parameters |
| | image | my_image | Image | app=something |
| | image | my_image | Image | app=something |
""",
error__contains=[
"Invalid Android package name format"
],
)
error__contains=["Invalid Android package name format"],
)

0 comments on commit e71f095

Please sign in to comment.