Skip to content

Commit

Permalink
create XFormversion when publish markdown during test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Apr 12, 2024
1 parent 634f6d2 commit 3152677
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions onadata/apps/api/tests/viewsets/test_abstract_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,23 @@ def _publish_markdown(self, md, user, project=None, **kwargs):
survey["sms_keyword"] = survey["id_string"]
if not project or not hasattr(self, "project"):
project = get_user_default_project(user)
xform = DataDictionary(
data_dict = DataDictionary(
created_by=user,
user=user,
xml=survey.to_xml(),
json=json.loads(survey.to_json()),
project=project,
)
xform.save()
data_dict.save()
latest_form = XForm.objects.all().order_by("-pk").first()
XFormVersion.objects.create(
xform=latest_form,
version=survey.get("version"),
xml=data_dict.xml,
json=json.dumps(data_dict.json),
)

return xform
return data_dict

def _publish_registration_form(self):
md = """
Expand Down Expand Up @@ -732,20 +739,15 @@ def _publish_registration_form(self):
elif self.project.created_by != self.user:
self._project_create()

data_dict = self._publish_markdown(
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):
Expand All @@ -763,18 +765,13 @@ def _publish_follow_up_form(self):
elif self.project.created_by != self.user:
self._project_create()

data_dict = self._publish_markdown(
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

0 comments on commit 3152677

Please sign in to comment.