Skip to content

Commit

Permalink
Don't allow periods in dataset names
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Nov 18, 2022
1 parent f6cd4a8 commit 2fb3bd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pyxform/entities/entities_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ def get_entity_declaration(workbook_dict: Dict, warnings: List) -> Dict:
f"Invalid dataset name: '{dataset}' starts with reserved prefix {constants.ENTITIES_RESERVED_PREFIX}."
)

if "." in dataset:
raise PyXFormError(
f"Invalid dataset name: '{dataset}'. Dataset names may not include periods."
)

if not is_valid_xml_tag(dataset):
if isinstance(dataset, bytes):
dataset = dataset.encode("utf-8")

raise PyXFormError(
f"Invalid dataset name: '{dataset}'. Dataset names {constants.XML_IDENTIFIER_ERROR_MESSAGE}"
f"Invalid dataset name: '{dataset}'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers or dashes."
)

if not ("label" in entity):
Expand Down
19 changes: 18 additions & 1 deletion tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,24 @@ def test_dataset_with_invalid_xml_name__errors(self):
""",
errored=True,
error__contains=[
"Invalid dataset name: '$sweet'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers, dashes, and periods."
"Invalid dataset name: '$sweet'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers or dashes."
],
)

def test_dataset_with_period_in_name__errors(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | dataset | label | |
| | s.w.eet | a | |
""",
errored=True,
error__contains=[
"Invalid dataset name: 's.w.eet'. Dataset names may not include periods."
],
)

Expand Down

0 comments on commit 2fb3bd8

Please sign in to comment.