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

Entities Support #2341

Merged
merged 9 commits into from
Jun 26, 2023
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
7 changes: 5 additions & 2 deletions onadata/apps/api/tests/viewsets/test_floip_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ def test_publish_number_question_names(self): # pylint: disable=C0103
self.assertEqual(response.status_code, 400)
self.assertEqual(response['Content-Type'],
'application/vnd.api+json')
self.assertIn(u"The name '1448506769745_42' is an invalid XML tag",
response.data['text'])
self.assertIn(
"The name '1448506769745_42' "
"contains an invalid character '1'",
response.data['text']
)

def test_responses_endpoint_format(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3496,9 +3496,9 @@ def test_survey_preview_endpoint(self):
response = view(request)
self.assertEqual(response.status_code, 400, response.data)
error_message = (
"[row : 2] Invalid question name [sdfasdfaf "
"sdf] Names must begin with a letter, colon, or underscore."
"Subsequent characters can include numbers, dashes, and periods."
"[row : 2] Invalid question name 'sdfasdfaf sdf'. "
"Names must begin with a letter, colon, or underscore. "
"Other characters can include numbers, dashes, and periods."
)
self.assertEqual(response.data.get("detail"), error_message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def update_instance_geoms(apps, schema_editor):
xform__downloadable=True,
xform__deleted_at__isnull=True,
):
if inst.geom.empty:
if inst.geom and inst.geom.empty:
inst.geom = None
inst.save()

Expand Down
90 changes: 90 additions & 0 deletions onadata/apps/logger/tests/test_publish_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.core.management import call_command
from django.core.management.base import CommandError
from pyxform.errors import PyXFormError

from onadata.apps.main.tests.test_base import TestBase
from onadata.apps.logger.models.xform import XForm
Expand Down Expand Up @@ -77,6 +78,95 @@ def test_xform_hash(self):
self.assertFalse(self.xform.hash == "" or self.xform.hash is None)
self.assertFalse(self.xform.hash == xform_old_hash)

def test_xform_with_entities(self):
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | dataset | label | |
| | trees | a | |
"""
self._create_user_and_login()
self.xform = self._publish_markdown(md, self.user)
# assert has entities namespace
self.assertIn(
'xmlns:entities="http://www.opendatakit.org/xforms/entities"',
self.xform.xml
)
# assert has entities version
self.assertIn(
'entities:entities-version="2022.1.0"',
self.xform.xml
)

def test_xform_with_entities_save_to(self):
md="""
| survey | | | | |
| | type | name | label | save_to |
| | text | a | A | foo |
| entities | | | | |
| | dataset | label | | |
| | trees | a | | |
"""
self._create_user_and_login()
self.xform = self._publish_markdown(md, self.user)
# assert has save_to column in xml
self.assertIn(
'entities:saveto="foo"',
self.xform.xml
)

def test_xform_create_if_in_entities(self):
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | dataset | create_if | label |
| | trees | string-length(a) > 3 | a |
"""
self._create_user_and_login()
self.xform = self._publish_markdown(md, self.user)
# assert has create_if entity expression
self.assertIn(
'calculate="string-length(a) > 3"',
self.xform.xml
)
self.assertIn(
'<entity create="1" dataset="trees" id="">',
self.xform.xml
)

def test_xform_big_image_invalid_if_no_image(self):
md="""
| survey | | | |
| | type | name | media::big-image |
| | text | c | m.png |
"""
self._create_user_and_login()
msg = ("To use big-image, you must also specify"
" an image for the survey element")
with self.assertRaisesMessage(PyXFormError, msg):
self.xform = self._publish_markdown(md, self.user)

def test_single_entity_allowed_per_form(self):
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | dataset | | |
| | trees | | |
| | shovels | | |
"""
self._create_user_and_login()
msg = ("Currently, you can only declare a single entity per form."
" Please make sure your entities sheet only declares"
" one entity.")
with self.assertRaisesMessage(PyXFormError, msg):
self.xform = self._publish_markdown(md, self.user)

def test_report_exception_with_exc_info(self):
e = Exception("A test exception")
try:
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.pip
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pytz==2023.3
# djangorestframework
# fleming
# onadata
pyxform==1.10.1
pyxform==1.12.0
# via
# onadata
# pyfloip
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.pip
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pytz==2022.1
# djangorestframework
# fleming
# onadata
pyxform==1.10.1
pyxform==1.12.0
# via
# onadata
# pyfloip
Expand Down