Skip to content

Commit

Permalink
Merge pull request #1389 fix #1352 Add created by to cloned xform and…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
ukanga committed May 2, 2018
2 parents 3642e54 + 3449855 commit e861a3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Expand Up @@ -4329,6 +4329,30 @@ def test_upload_xml_form_file(self):
xform = XForm.objects.last()
self.assertEqual(xform.instances.count(), 6)

def test_created_by_field_on_cloned_forms(self):
"""
Test that the created by field is not empty for cloned forms
"""
with HTTMock(enketo_mock):
self._publish_xls_form_to_project()
view = XFormViewSet.as_view({
'post': 'clone'
})
alice_data = {'username': 'alice', 'email': 'alice@localhost.com'}
alice_profile = self._create_user_profile(alice_data)
count = XForm.objects.count()

data = {'username': 'alice'}
formid = self.xform.pk
ManagerRole.add(self.user, alice_profile)
request = self.factory.post('/', data=data, **self.extra)
response = view(request, pk=formid)
self.assertTrue(self.user.has_perm('can_add_xform', alice_profile))
self.assertEqual(response.status_code, 201)
self.assertEqual(count + 1, XForm.objects.count())
cloned_form = XForm.objects.last()
self.assertEqual(cloned_form.created_by.username, 'alice')

@override_settings(CELERY_ALWAYS_EAGER=False)
@patch('onadata.libs.utils.api_export_tools.AsyncResult')
def test_pending_export_async(self, async_result):
Expand Down
1 change: 1 addition & 0 deletions onadata/libs/models/clone_xform.py
Expand Up @@ -27,6 +27,7 @@ def save(self, **kwargs):
xls_file = default_storage.save(xls_file_path, xls_data)
self.cloned_form = DataDictionary.objects.create(
user=user,
created_by=user,
xls=xls_file,
project=project
)

0 comments on commit e861a3c

Please sign in to comment.