diff --git a/onadata/apps/api/tests/viewsets/test_abstract_viewset.py b/onadata/apps/api/tests/viewsets/test_abstract_viewset.py index bfc6f5d7f4..fca088f04f 100644 --- a/onadata/apps/api/tests/viewsets/test_abstract_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_abstract_viewset.py @@ -29,7 +29,13 @@ from onadata.apps.api.viewsets.project_viewset import ProjectViewSet from onadata.apps.api.viewsets.team_viewset import TeamViewSet from onadata.apps.api.viewsets.widget_viewset import WidgetViewSet -from onadata.apps.logger.models import Attachment, Instance, Project, XForm +from onadata.apps.logger.models import ( + Attachment, + Instance, + Project, + XForm, + XFormVersion, +) from onadata.apps.logger.models.data_view import DataView from onadata.apps.logger.models.widget import Widget from onadata.apps.logger.views import submission @@ -699,3 +705,76 @@ def _publish_markdown(self, md, user, project=None, **kwargs): xform.save() return xform + + def _publish_registration_form(self): + md = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | geometry | + | | select_one species | species | Tree species | species | + | | integer | circumference | Tree circumference in cm | circumference_cm | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees | concat(${circumference}, "cm ", ${species})| | |""" + + if not hasattr(self, "project"): + self._project_create() + elif self.project.created_by != self.user: + self._project_create() + + data_dict = self._publish_markdown( + md, + self.user, + self.project, + id_string="trees_registration", + title="Trees registration", + ) + latest_form = XForm.objects.all().order_by("-pk").first() + XFormVersion.objects.create( + xform=latest_form, + version="2022110901", + xml=data_dict.xml, + json=json.dumps(data_dict.json), + ) + return latest_form + + def _publish_follow_up_form(self): + md = """ + | survey | + | | type | name | label | required | + | | select_one_from_file trees.csv | tree | Select the tree you are visiting | yes | + | settings| | | | | + | | form_title | form_id | version | | + | | Trees follow-up | trees_follow_up | 2022111801 | | + """ + + if not hasattr(self, "project"): + self._project_create() + elif self.project.created_by != self.user: + self._project_create() + + data_dict = self._publish_markdown( + md, + self.user, + self.project, + id_string="trees_follow_up", + title="Trees follow-up", + ) + latest_form = XForm.objects.all().order_by("-pk").first() + XFormVersion.objects.create( + xform=latest_form, + version="2022111801", + xml=data_dict.xml, + json=json.dumps(data_dict.json), + ) + return latest_form diff --git a/onadata/apps/api/tests/viewsets/test_entity_list_viewset.py b/onadata/apps/api/tests/viewsets/test_entity_list_viewset.py index 60e9c57098..7c2a02a186 100644 --- a/onadata/apps/api/tests/viewsets/test_entity_list_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_entity_list_viewset.py @@ -25,27 +25,9 @@ def setUp(self): def test_get_all(self): """GET all EntityLists works""" # Publish registration form and create "trees" EntityList dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_registration_form() # Publish follow up form for "trees" dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_follow_up_form() # Make submission on tree_registration form submission_path = os.path.join( settings.PROJECT_ROOT, @@ -180,27 +162,9 @@ def setUp(self): self.view = EntityListViewSet.as_view({"get": "retrieve"}) # Publish registration form and create "trees" EntityList dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_registration_form() # Publish follow up form for "trees" dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_follow_up_form() self.entity_list = EntityList.objects.first() # Make submission on tree_registration form submission_path = os.path.join( @@ -304,27 +268,9 @@ def setUp(self): self.view = EntityListViewSet.as_view({"get": "entities"}) # Publish registration form and create "trees" EntityList dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_registration_form() # Publish follow up form for "trees" dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_follow_up_form() # Make submissions which will then create Entities paths = [ os.path.join( diff --git a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py index 2fdbbd61bb..94ea5d9e84 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py @@ -968,16 +968,7 @@ def test_retrieve_xform_media_linked_xform(self): def test_retrieve_xform_media_entity_list_dataset(self): """EntityList dataset is returned""" # Publish registration form and create "trees" Entitylist dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_registration_form() # Make submission to trees_registration form submission_path = os.path.join( self.main_directory, diff --git a/onadata/apps/api/tests/viewsets/test_xform_submission_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_submission_viewset.py index b7e45a17bf..3a0b335727 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_submission_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_submission_viewset.py @@ -1323,16 +1323,7 @@ def test_edit_submission_sent_to_rapidpro(self, mock_send): def test_create_entity(self): """An Entity is created for if the form is a RegistrationForm""" - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self.xform = self._publish_registration_form() submission_path = os.path.join( self.main_directory, "fixtures", @@ -1373,16 +1364,7 @@ def test_create_entity(self): def test_registration_form_inactive(self): """When the RegistrationForm is inactive, Entity should not be created""" - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self.xform = self._publish_registration_form() registration_form = self.xform.registration_forms.first() # deactivate registration form registration_form.is_active = False diff --git a/onadata/apps/api/tests/viewsets/test_xform_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_viewset.py index 41a0aa7187..5503771bcc 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_viewset.py @@ -61,8 +61,6 @@ Project, XForm, EntityList, - RegistrationForm, - FollowUpForm, ) from onadata.apps.logger.models.xform_version import XFormVersion from onadata.apps.logger.views import delete_xform @@ -731,171 +729,6 @@ def test_external_choice_integer_name_xlsform(self): for index, row in enumerate(csv_reader): self.assertEqual(row, expected_data[index]) - def test_registration_form(self): - """Publishing an XLSForm that creates entities works""" - with HTTMock(enketo_mock): - xforms = XForm.objects.count() - path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - - with open(path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.post("/", data=post_data, **self.extra) - response = self.view(request) - - self.assertEqual(xforms + 1, XForm.objects.count()) - self.assertEqual(response.status_code, 201) - self.assertEqual(EntityList.objects.count(), 1) - self.assertEqual(RegistrationForm.objects.count(), 1) - entity_list = EntityList.objects.first() - reg_form = RegistrationForm.objects.first() - latest_form = XForm.objects.all().order_by("-pk").first() - self.assertEqual(entity_list.name, "trees") - self.assertEqual(reg_form.xform, latest_form) - self.assertEqual( - reg_form.get_save_to(), - { - "geometry": "location", - "species": "species", - "circumference_cm": "circumference", - }, - ) - self.assertEqual(reg_form.entity_list, entity_list) - self.assertTrue(reg_form.is_active) - - def test_follow_up_form(self): - """Publishing an XLSForm that consumes entities works""" - # Publish registration form - md = """ - | survey | - | | type | name | label | save_to | - | | geopoint | location | Tree location | geometry | - | | select_one species | species | Tree species | species | - | | integer | circumference | Tree circumference in cm | circumference_cm | - | choices | | | | | - | | list_name | name | label | | - | | species | wallaba | Wallaba | | - | | species | mora | Mora | | - | | species | purpleheart | Purpleheart | | - | | species | greenheart | Greenheart | | - | settings | | | | | - | | form_title | form_id | | | - | | Trees registration | trees_reg | | | - | entities | | | | | - | | list_name | label | | | - | | trees | foo | | |""" - self._publish_markdown(md, self.user) - - with HTTMock(enketo_mock): - path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - - with open(path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.post("/", data=post_data, **self.extra) - response = self.view(request) - self.assertEqual(XForm.objects.count(), 2) - self.assertEqual(response.status_code, 201) - latest_form = XForm.objects.all().order_by("-pk").first() - entity_list = EntityList.objects.first() - self.assertTrue( - FollowUpForm.objects.filter( - entity_list__name="trees", xform=latest_form - ).exists() - ) - self.assertTrue( - MetaData.objects.filter( - object_id=latest_form.pk, - data_type="media", - data_value=f"entity_list {entity_list.pk} trees", - ).exists() - ) - - # Follow up form references multiple entity lists - md = """ - | survey | - | | type | name | label | save_to | - | | geopoint | location | Tree location | geometry | - | | select_one species | species | Tree species | species | - | | integer | circumference | Tree circumference in cm | circumference_cm | - | choices | | | | | - | | list_name | name | label | | - | | species | wallaba | Wallaba | | - | | species | mora | Mora | | - | | species | purpleheart | Purpleheart | | - | | species | greenheart | Greenheart | | - | settings | | | | | - | | form_title | form_id | | | - | | Trees registration | xyz_reg | | | - | entities | | | | | - | | list_name | label | | | - | | xyz | foo | | |""" - self._publish_markdown(md, self.user, id_string="xyz_reg") - - with HTTMock(enketo_mock): - path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up_multiple_lists.xlsx", - ) - - with open(path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.post("/", data=post_data, **self.extra) - response = self.view(request) - self.assertEqual(response.status_code, 201) - self.assertEqual(XForm.objects.count(), 4) - latest_form = XForm.objects.all().order_by("-pk").first() - self.assertTrue( - FollowUpForm.objects.filter( - entity_list__name="trees", xform=latest_form - ).exists() - ) - self.assertTrue( - FollowUpForm.objects.filter( - entity_list__name="xyz", xform=latest_form - ).exists() - ) - - def test_follow_up_form_list_not_found(self): - """Entity list not found when publishing followup form""" - with HTTMock(enketo_mock): - path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - - with open(path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.post("/", data=post_data, **self.extra) - response = self.view(request) - self.assertEqual(XForm.objects.count(), 1) - self.assertEqual(response.status_code, 201) - self.assertEqual(FollowUpForm.objects.count(), 0) - class TestXFormViewSet(XFormViewSetBaseTestCase): """Test XFormViewSet""" @@ -5359,326 +5192,6 @@ def test_csv_xls_import_errors(self): self.assertEqual(response.status_code, 400) self.assertEqual(response.data.get("error"), "csv_file not a csv file") - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_replace_form_entities_save_to(self, mock_send_message): - """Replacing entity properties works""" - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - registration_form = self.xform.registration_forms.first() - self.assertEqual( - registration_form.get_save_to(), - { - "geometry": "location", - "species": "species", - "circumference_cm": "circumference", - }, - ) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration_replace_save_to.xlsx", - ) - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - self.assertTrue(mock_send_message.called) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - self.xform.refresh_from_db() - registration_form = self.xform.registration_forms.first() - self.assertEqual( - registration_form.get_save_to(), - { - "location": "location", - "species": "species", - }, - ) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_replace_form_entities_list_name(self, mock_send_message): - """Replacing entities list_name works""" - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration_replace_list_name.xlsx", - ) - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - # A new EntityList is created if it does not exist - entity_list = EntityList.objects.get( - name="trees_registration", project=self.project - ) - # A new RegistrationForm referencing the new entity list is - # created for the XForm - self.assertTrue( - RegistrationForm.objects.filter( - entity_list=entity_list, xform=self.xform - ).exists() - ) - self.assertEqual(EntityList.objects.count(), 2) - self.assertEqual(self.xform.registration_forms.count(), 2) - # RegistrationForm contributing to the previous EntityList - # should be disabled - registration_forms = self.xform.registration_forms.all().order_by("pk") - prev_registration_form = registration_forms[0] - new_registration_form = registration_forms[1] - self.assertFalse(prev_registration_form.is_active) - self.assertTrue(new_registration_form.is_active) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_replace_form_remove_entities(self, mock_send_message): - """Removing entities definition disables registration form""" - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration_remove_entities.xlsx", - ) - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - reg_form = self.xform.registration_forms.first() - self.assertFalse(reg_form.is_active) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_registration_form_disabled(self, mock_send_message): - """Existing RegistrationForm if disabled is activated""" - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - registration_form = self.xform.registration_forms.first() - # Disable registration form - registration_form.is_active = False - registration_form.save() - registration_form.refresh_from_db() - self.assertFalse(registration_form.is_active) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - registration_form.refresh_from_db() - self.assertTrue(registration_form.is_active) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_replace_followup_form(self, mock_send_message): - """We can replace a followup form successfully""" - self._project_create() - EntityList.objects.create(name="trees", project=self.project) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_followup_form_remove_dataset(self, mock_send_message): - """FollowUpForm is deactivated if entity dataset reference removed""" - self._project_create() - EntityList.objects.create(name="trees", project=self.project) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - form = FollowUpForm.objects.filter( - entity_list__name="trees", xform=self.xform - ).first() - self.assertIsNotNone(form) - self.assertTrue(form.is_active) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up_remove_dataset.xlsx", - ) - - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - form.refresh_from_db() - self.assertFalse(form.is_active) - - @patch("onadata.apps.api.viewsets.xform_viewset.send_message") - def test_followup_form_reactivate_dataset(self, mock_send_message): - """FollowUpForm is re-activated if previously activated - - If entity dataset is referenced again, deactivate FollowUpForm - is re-activated - """ - self._project_create() - entity_list = EntityList.objects.create(name="trees", project=self.project) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up_remove_dataset.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xls_file_path) - # Simulate deactivated FollowUpForm - form = FollowUpForm.objects.create( - entity_list=entity_list, xform=self.xform, is_active=False - ) - self.assertFalse(form.is_active) - - with HTTMock(enketo_mock): - # Replace form created above - view = XFormViewSet.as_view({"patch": "partial_update"}) - xls_file_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - - with open(xls_file_path, "rb") as xls_file: - post_data = {"xls_file": xls_file} - request = self.factory.patch("/", data=post_data, **self.extra) - response = view(request, pk=self.xform.pk) - - self.assertEqual(response.status_code, 200) - mock_send_message.called_with( - self.xform.id, self.xform.id, XFORM, request.user, FORM_UPDATED - ) - form.refresh_from_db() - self.assertTrue(form.is_active) - @override_settings(TIME_ZONE="UTC") def test_get_single_registration_form(self): """Response a for an XForm contributing entities is correct""" diff --git a/onadata/apps/logger/tests/models/test_entity.py b/onadata/apps/logger/tests/models/test_entity.py index d4b7d67166..8d3b4b3be2 100644 --- a/onadata/apps/logger/tests/models/test_entity.py +++ b/onadata/apps/logger/tests/models/test_entity.py @@ -1,7 +1,5 @@ """Tests for module onadata.apps.logger.models.entity""" -import os -import json import pytz from datetime import datetime @@ -18,15 +16,7 @@ def setUp(self): # Mute signal that creates Entity when Instance is saved self._mute_post_save_signals([(Instance, "create_entity")]) self.mocked_now = datetime(2023, 11, 8, 13, 17, 0, tzinfo=pytz.utc) - fixture_dir = os.path.join(self.this_directory, "fixtures", "entities") - form_path = os.path.join(fixture_dir, "trees_registration.xlsx") - self._publish_xls_file_and_set_xform(form_path) - self.xform.versions.create( - xls=self.xform.xls, - version=self.xform.version, - xml=self.xform.xml, - json=json.dumps(self.xform.json), - ) + self.xform = self._publish_registration_form() def test_creation(self): """We can create an Entity""" diff --git a/onadata/apps/logger/tests/models/test_entity_list.py b/onadata/apps/logger/tests/models/test_entity_list.py index 988cf14719..a4db238e0b 100644 --- a/onadata/apps/logger/tests/models/test_entity_list.py +++ b/onadata/apps/logger/tests/models/test_entity_list.py @@ -5,7 +5,6 @@ from datetime import datetime from unittest.mock import patch -from django.conf import settings from django.db.utils import IntegrityError, DataError from onadata.apps.main.tests.test_base import TestBase @@ -75,10 +74,29 @@ def test_max_name_length(self): def test_properties(self): """Returns the correct dataset properties""" # Publish XLSForm and implicity create EntityList - form_path = os.path.join(self.fixture_dir, "trees_registration.xlsx") - self._publish_xls_file_and_set_xform(form_path) - form_path = os.path.join(self.fixture_dir, "trees_registration_height.xlsx") - self._publish_xls_file_and_set_xform(form_path) + self._publish_registration_form() + height_md = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | geometry | + | | select_one species | species | Tree species | species | + | | integer | height | Tree height in m | height_m | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration_height | 2022110901 | concat(${height}, "m ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees | concat(${height}, "m ", ${species}) | | |""" + self._publish_markdown( + height_md, self.user, self.project, id_string="trees_registration_height" + ) entity_list = EntityList.objects.first() # The properties should be from all forms creating Entities for the dataset self.assertCountEqual( @@ -94,8 +112,7 @@ def test_defaults(self): def test_queried_last_entity_update_time(self): """Property `queried_last_entity_update_time` works""" - form_path = os.path.join(self.fixture_dir, "trees_registration.xlsx") - self._publish_xls_file_and_set_xform(form_path) + self._publish_registration_form() entity_list = EntityList.objects.first() # Returns None if no Entities exist self.assertIsNone(entity_list.queried_last_entity_update_time) @@ -144,16 +161,7 @@ def test_queried_num_entities(self): "" "" ) - form_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_file_and_set_xform(form_path) + self.xform = self._publish_registration_form() reg_form = self.xform.registration_forms.first() entity_list = EntityList.objects.get(name="trees") # Before creating Entity diff --git a/onadata/apps/logger/tests/models/test_follow_up_form.py b/onadata/apps/logger/tests/models/test_follow_up_form.py index 65433e3a08..6b71c3c776 100644 --- a/onadata/apps/logger/tests/models/test_follow_up_form.py +++ b/onadata/apps/logger/tests/models/test_follow_up_form.py @@ -1,5 +1,5 @@ """Tests for module onadata.apps.logger.models.follow_up_form""" -import os + import pytz from datetime import datetime from unittest.mock import patch @@ -17,9 +17,7 @@ def setUp(self): super().setUp() self.mocked_now = datetime(2023, 11, 8, 13, 17, 0, tzinfo=pytz.utc) - fixture_dir = os.path.join(self.this_directory, "fixtures", "entities") - form_path = os.path.join(fixture_dir, "trees_follow_up.xlsx") - self._publish_xls_file_and_set_xform(form_path) + self.xform = self._publish_follow_up_form() self.entity_list = EntityList.objects.create(name="trees", project=self.project) @patch("django.utils.timezone.now") diff --git a/onadata/apps/logger/tests/models/test_registration_form.py b/onadata/apps/logger/tests/models/test_registration_form.py index 2461aed8ef..cd38dbb743 100644 --- a/onadata/apps/logger/tests/models/test_registration_form.py +++ b/onadata/apps/logger/tests/models/test_registration_form.py @@ -1,7 +1,6 @@ """Tests for module onadata.apps.logger.models.registration_form""" import json -import os import pytz from datetime import datetime from unittest.mock import patch @@ -20,8 +19,6 @@ def setUp(self): super().setUp() self.mocked_now = datetime(2023, 11, 8, 13, 17, 0, tzinfo=pytz.utc) - fixture_dir = os.path.join(self.this_directory, "fixtures", "entities") - self.form_path = os.path.join(fixture_dir, "trees_registration.xlsx") @patch("django.utils.timezone.now") def test_creation(self, mock_now): @@ -30,7 +27,7 @@ def test_creation(self, mock_now): self._mute_post_save_signals( [(DataDictionary, "create_registration_form_datadictionary")] ) - self._publish_xls_file_and_set_xform(self.form_path) + self.xform = self._publish_registration_form() entity_list = EntityList.objects.create(name="trees", project=self.project) reg_form = RegistrationForm.objects.create( entity_list=entity_list, @@ -53,7 +50,7 @@ def test_get_save_to(self): self._mute_post_save_signals( [(DataDictionary, "create_registration_form_datadictionary")] ) - self._publish_xls_file_and_set_xform(self.form_path) + self.xform = self._publish_registration_form() entity_list = EntityList.objects.create(name="trees", project=self.project) form = RegistrationForm.objects.create( entity_list=entity_list, @@ -155,7 +152,7 @@ def test_entity_list_xform_unique(self): self._mute_post_save_signals( [(DataDictionary, "create_registration_form_datadictionary")] ) - self._publish_xls_file_and_set_xform(self.form_path) + self.xform = self._publish_registration_form() entity_list = EntityList.objects.create(name="trees", project=self.project) RegistrationForm.objects.create( entity_list=entity_list, @@ -173,7 +170,7 @@ def test_optional_fields(self): self._mute_post_save_signals( [(DataDictionary, "create_registration_form_datadictionary")] ) - self._publish_xls_file_and_set_xform(self.form_path) + self.xform = self._publish_registration_form() entity_list = EntityList.objects.create(name="trees", project=self.project) reg_form = RegistrationForm.objects.create( entity_list=entity_list, diff --git a/onadata/apps/main/tests/fixtures/entities/trees_follow_up.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_follow_up.xlsx deleted file mode 100644 index fc25ce72d5..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_follow_up.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_follow_up_multiple_lists.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_follow_up_multiple_lists.xlsx deleted file mode 100644 index aa53a7b5f2..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_follow_up_multiple_lists.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_follow_up_remove_dataset.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_follow_up_remove_dataset.xlsx deleted file mode 100644 index b7729b5156..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_follow_up_remove_dataset.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_registration.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_registration.xlsx deleted file mode 100644 index da2a741432..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_registration.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_registration_height.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_registration_height.xlsx deleted file mode 100644 index 61ac1a8643..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_registration_height.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_registration_remove_entities.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_registration_remove_entities.xlsx deleted file mode 100644 index cdcafa2332..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_registration_remove_entities.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_list_name.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_list_name.xlsx deleted file mode 100644 index 1d6214b559..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_list_name.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_save_to.xlsx b/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_save_to.xlsx deleted file mode 100644 index 0143f34b75..0000000000 Binary files a/onadata/apps/main/tests/fixtures/entities/trees_registration_replace_save_to.xlsx and /dev/null differ diff --git a/onadata/apps/main/tests/test_base.py b/onadata/apps/main/tests/test_base.py index d051605ed7..02f3b7eb09 100644 --- a/onadata/apps/main/tests/test_base.py +++ b/onadata/apps/main/tests/test_base.py @@ -29,7 +29,7 @@ from six.moves.urllib.request import urlopen from onadata.apps.api.viewsets.xform_viewset import XFormViewSet -from onadata.apps.logger.models import Instance, XForm +from onadata.apps.logger.models import Instance, XForm, XFormVersion from onadata.apps.logger.views import submission from onadata.apps.logger.xform_instance_parser import clean_and_parse_xml from onadata.apps.main.models import UserProfile @@ -466,6 +466,7 @@ def _publish_markdown(self, md_xlsform, user, project=None, **kwargs): xml=survey.to_xml(), json=json.loads(survey.to_json()), project=project, + version=survey.get("version"), ) xform.save() @@ -505,3 +506,72 @@ def _mute_post_save_signals(self, target_signals: list[tuple]): for signal in target_signals: model, dispatch_uid = signal signals.post_save.disconnect(sender=model, dispatch_uid=dispatch_uid) + + def _publish_registration_form(self): + md = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | geometry | + | | select_one species | species | Tree species | species | + | | integer | circumference | Tree circumference in cm | circumference_cm | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees | concat(${circumference}, "cm ", ${species})| | |""" + + if not hasattr(self, "project"): + self.project = get_user_default_project(self.user) + + data_dict = self._publish_markdown( + md, + self.user, + self.project, + id_string="trees_registration", + title="Trees registration", + ) + latest_form = XForm.objects.all().order_by("-pk").first() + XFormVersion.objects.create( + xform=latest_form, + version="2022110901", + xml=data_dict.xml, + json=json.dumps(data_dict.json), + ) + return latest_form + + def _publish_follow_up_form(self): + md = """ + | survey | + | | type | name | label | required | + | | select_one_from_file trees.csv | tree | Select the tree you are visiting | yes | + | settings| | | | | + | | form_title | form_id | version | | + | | Trees follow-up | trees_follow_up | 2022111801 | | + """ + + if not hasattr(self, "project"): + self.project = get_user_default_project(self.user) + + data_dict = self._publish_markdown( + md, + self.user, + self.project, + id_string="trees_follow_up", + title="Trees follow-up", + ) + latest_form = XForm.objects.all().order_by("-pk").first() + XFormVersion.objects.create( + xform=latest_form, + version="2022111801", + xml=data_dict.xml, + json=json.dumps(data_dict.json), + ) + return latest_form diff --git a/onadata/apps/viewer/models/tests/__init__.py b/onadata/apps/viewer/models/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/onadata/apps/viewer/models/tests/test_data_dictionary.py b/onadata/apps/viewer/models/tests/test_data_dictionary.py new file mode 100644 index 0000000000..b9528e9b3f --- /dev/null +++ b/onadata/apps/viewer/models/tests/test_data_dictionary.py @@ -0,0 +1,271 @@ +"""Tests for onadata.apps.viewer.models.data_dictionary""" + +import json + +from onadata.apps.main.tests.test_base import TestBase +from onadata.apps.logger.models.entity_list import EntityList +from onadata.apps.logger.models.xform import XForm +from onadata.apps.logger.models.follow_up_form import FollowUpForm +from onadata.apps.logger.models.registration_form import RegistrationForm +from onadata.apps.main.models.meta_data import MetaData +from onadata.libs.utils.user_auth import get_user_default_project + + +class DataDictionaryTestCase(TestBase): + """Tests for model DataDictionary""" + + def setUp(self): + super().setUp() + + self.project = get_user_default_project(self.user) + self.registration_form = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | geometry | + | | select_one species | species | Tree species | species | + | | integer | circumference | Tree circumference in cm | circumference_cm | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees | concat(${circumference}, "cm ", ${species})| | |""" + self.follow_up_form = """ + | survey | + | | type | name | label | required | + | | select_one_from_file trees.csv | tree | Select the tree you are visiting | yes | + | settings| | | | | + | | form_title | form_id | version | | + | | Trees follow-up | trees_follow_up | 2022111801 | | + """ + + def _replace_form(self, markdown, data_dict): + survey = self.md_to_pyxform_survey(markdown, kwargs={"name": "data"}) + data_dict.xml = survey.to_xml() + data_dict.json = json.loads(survey.to_json()) + data_dict.save() + + def test_create_registration_form(self): + """Registration form created successfully""" + self._publish_markdown(self.registration_form, self.user) + self.assertEqual(XForm.objects.count(), 1) + self.assertTrue(EntityList.objects.filter(name="trees").exists()) + self.assertEqual(RegistrationForm.objects.count(), 1) + entity_list = EntityList.objects.first() + reg_form = RegistrationForm.objects.first() + latest_form = XForm.objects.all().order_by("-pk").first() + self.assertEqual(entity_list.name, "trees") + self.assertEqual(reg_form.xform, latest_form) + self.assertEqual( + reg_form.get_save_to(), + { + "geometry": "location", + "species": "species", + "circumference_cm": "circumference", + }, + ) + self.assertEqual(reg_form.entity_list, entity_list) + self.assertTrue(reg_form.is_active) + + def test_create_follow_up_form(self): + """Follow up form created successfully""" + # Simulate existing trees dataset + EntityList.objects.create(name="trees", project=self.project) + self._publish_markdown(self.follow_up_form, self.user) + self.assertEqual(XForm.objects.count(), 1) + latest_form = XForm.objects.all().order_by("-pk").first() + entity_list = EntityList.objects.first() + self.assertTrue( + FollowUpForm.objects.filter( + entity_list__name="trees", xform=latest_form + ).exists() + ) + self.assertTrue( + MetaData.objects.filter( + object_id=latest_form.pk, + data_type="media", + data_value=f"entity_list {entity_list.pk} trees", + ).exists() + ) + + def test_follow_up_form_list_not_found(self): + """Entity list not found when publishing followup form""" + self._publish_markdown(self.follow_up_form, self.user) + self.assertEqual(XForm.objects.count(), 1) + self.assertEqual(FollowUpForm.objects.count(), 0) + + def test_replace_form_entities_save_to(self): + """Replacing entity properties works""" + data_dict = self._publish_markdown(self.registration_form, self.user) + registration_form = RegistrationForm.objects.first() + self.assertEqual( + registration_form.get_save_to(), + { + "geometry": "location", + "species": "species", + "circumference_cm": "circumference", + }, + ) + md = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | location | + | | select_one species | species | Tree species | species | + | | integer | circumference | Tree circumference in cm | | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees | concat(${circumference}, "cm ", ${species})| | |""" + self._replace_form(md, data_dict) + registration_form.refresh_from_db() + self.assertEqual( + registration_form.get_save_to(), + { + "location": "location", + "species": "species", + }, + ) + + def test_replace_form_entities_list_name(self): + """Replacing entities list_name works""" + data_dict = self._publish_markdown(self.registration_form, self.user) + # name changed entities list_name to `trees_registration` + md = """ + | survey | + | | type | name | label | save_to | + | | geopoint | location | Tree location | geometry | + | | select_one species | species | Tree species | species | + | | integer | circumference | Tree circumference in cm | circumference_cm | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})| + | entities | | | | | + | | list_name | label | | | + | | trees_registration | concat(${circumference}, "cm ", ${species})| | |""" + self._replace_form(md, data_dict) + # A new EntityList is created + self.assertTrue(EntityList.objects.filter(name="trees_registration").exists()) + # A new RegistrationForm referencing the new entity list is + # created for the XForm + latest_form = XForm.objects.all().order_by("-pk").first() + self.assertTrue( + RegistrationForm.objects.filter( + entity_list__name="trees_registration", xform=latest_form + ).exists() + ) + # RegistrationForm contributing to the previous EntityList + # should be disabled + registration_forms = RegistrationForm.objects.all().order_by("pk") + prev_registration_form = registration_forms[0] + new_registration_form = registration_forms[1] + self.assertFalse(prev_registration_form.is_active) + self.assertTrue(new_registration_form.is_active) + + def test_replace_form_remove_entities(self): + """Removing entities definition disables registration form""" + data_dict = self._publish_markdown(self.registration_form, self.user) + md = """ + | survey | + | | type | name | label | | + | | geopoint | location | Tree location | | + | | select_one species | species | Tree species | | + | | integer | circumference | Tree circumference in cm | | + | | text | intake_notes | Intake notes | | + | choices | | | | | + | | list_name | name | label | | + | | species | wallaba | Wallaba | | + | | species | mora | Mora | | + | | species | purpleheart | Purpleheart | | + | | species | greenheart | Greenheart | | + | settings | | | | | + | | form_title | form_id | version | instance_name | + | | Trees registration | trees_registration | 2022110901 | concat(${circumference}, "cm ", ${species})|""" + self._replace_form(md, data_dict) + registration_form = RegistrationForm.objects.first() + self.assertFalse(registration_form.is_active) + + def test_registration_form_reactivated(self): + """Existing RegistrationForm if disabled is activated""" + data_dict = self._publish_markdown(self.registration_form, self.user) + registration_form = RegistrationForm.objects.first() + # Disable registration form + registration_form.is_active = False + registration_form.save() + registration_form.refresh_from_db() + self.assertFalse(registration_form.is_active) + # Replace + self._replace_form(self.registration_form, data_dict) + registration_form.refresh_from_db() + self.assertTrue(registration_form.is_active) + + def test_followup_form_remove_dataset(self): + """FollowUpForm is deactivated if entity dataset reference removed""" + # Simulate existing trees dataset + EntityList.objects.create(name="trees", project=self.project) + data_dict = self._publish_markdown(self.follow_up_form, self.user) + follow_up_form = FollowUpForm.objects.filter(entity_list__name="trees").first() + self.assertTrue(follow_up_form.is_active) + # Replace + md = """ + | survey | + | | type | name | label | + | | text | tree | What is the name of the tree? | + | | integer | circumference | Tree circumeference in cm | + | settings| | | | + | | form_title | form_id | version | + | | Trees follow-up | trees_follow_up | 2022111801 | + """ + self._replace_form(md, data_dict) + follow_up_form.refresh_from_db() + self.assertFalse(follow_up_form.is_active) + + def test_reactivate_followup_form(self): + """FollowUpForm is re-activated if previously activated + + If entity dataset is referenced again, deactivate FollowUpForm + is re-activated + """ + # Simulate existing deactivate FollowUpForm + md = """ + | survey | + | | type | name | label | + | | text | tree | What is the name of the tree? | + | | integer | circumference | Tree circumeference in cm | + | settings| | | | + | | form_title | form_id | version | + | | Trees follow-up | trees_follow_up| 2022111801 | + """ + data_dict = self._publish_markdown(md, self.user) + entity_list = EntityList.objects.create(name="trees", project=self.project) + xform = XForm.objects.first() + form = FollowUpForm.objects.create( + entity_list=entity_list, xform=xform, is_active=False + ) + self.assertFalse(form.is_active) + # Replace + self._replace_form(self.follow_up_form, data_dict) + form.refresh_from_db() + self.assertTrue(form.is_active) diff --git a/onadata/libs/tests/serializers/test_xform_serializer.py b/onadata/libs/tests/serializers/test_xform_serializer.py index 056601c01d..c3f963a943 100644 --- a/onadata/libs/tests/serializers/test_xform_serializer.py +++ b/onadata/libs/tests/serializers/test_xform_serializer.py @@ -2,7 +2,6 @@ """ Test onadata.libs.serializers.xform_serializer """ -import json import os from unittest.mock import MagicMock @@ -73,28 +72,9 @@ def test_entity_dataset_hash(self): serializer = XFormManifestSerializer() self._create_user_and_login() # Publish registration form - xlsx_path = os.path.join( - self.this_directory, - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_file(xlsx_path) - reg_form = XForm.objects.first() - reg_form.versions.create( - xls=reg_form.xls, - version=reg_form.version, - xml=reg_form.xml, - json=json.dumps(reg_form.json), - ) + self._publish_registration_form() # Publish follow up form - xlsx_path = os.path.join( - self.this_directory, - "fixtures", - "entities", - "trees_follow_up.xlsx", - ) - self._publish_xls_file(xlsx_path) + self._publish_follow_up_form() follow_up_xform = XForm.objects.order_by("pk").reverse()[0] entity_list = self.project.entity_lists.first() # Make submission to create new Entity diff --git a/onadata/libs/tests/utils/test_export_tools.py b/onadata/libs/tests/utils/test_export_tools.py index 14340ed521..79c4dbc4b4 100644 --- a/onadata/libs/tests/utils/test_export_tools.py +++ b/onadata/libs/tests/utils/test_export_tools.py @@ -1011,16 +1011,7 @@ class GenerateExportTestCase(TestAbstractViewSet): def test_generate_export_entity_list(self): """Generate export for EntityList dataset works""" # Publish registration form and create "trees" Entitylist dataset - xlsform_path = os.path.join( - settings.PROJECT_ROOT, - "apps", - "main", - "tests", - "fixtures", - "entities", - "trees_registration.xlsx", - ) - self._publish_xls_form_to_project(xlsform_path=xlsform_path) + self._publish_registration_form() # Make submission to trees_registration form submission_path = os.path.join( self.main_directory, diff --git a/onadata/libs/tests/utils/test_logger_tools.py b/onadata/libs/tests/utils/test_logger_tools.py index 6530b3d376..44916fa0ba 100644 --- a/onadata/libs/tests/utils/test_logger_tools.py +++ b/onadata/libs/tests/utils/test_logger_tools.py @@ -2,7 +2,6 @@ """ Test logger_tools utility functions. """ -import json import os import re from io import BytesIO @@ -659,15 +658,7 @@ def setUp(self): super().setUp() # Mute signal that creates Entity when Instance is saved self._mute_post_save_signals([(Instance, "create_entity")]) - fixture_dir = os.path.join(self.this_directory, "fixtures", "entities") - form_path = os.path.join(fixture_dir, "trees_registration.xlsx") - self._publish_xls_file_and_set_xform(form_path) - self.xform.versions.create( - xls=self.xform.xls, - version=self.xform.version, - xml=self.xform.xml, - json=json.dumps(self.xform.json), - ) + self.xform = self._publish_registration_form() self.xml = ( '' '