diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py index 0260ea2156..7fa48501e0 100644 --- a/onadata/apps/api/tests/viewsets/test_data_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py @@ -91,8 +91,7 @@ def setUp(self): self.extra = { 'HTTP_AUTHORIZATION': 'Token %s' % self.user.auth_token} - @patch('onadata.apps.logger.models.instance.send_message') - def test_data(self, mock_send_message): + def test_data(self): """Test DataViewSet list""" self._make_submissions() view = DataViewSet.as_view({'get': 'list'}) @@ -125,10 +124,6 @@ def test_data(self, mock_send_message): self.assertNotEqual(response.get('Cache-Control'), None) self.assertIsInstance(response.data, dict) self.assertDictContainsSubset(data, response.data) - self.assertTrue(mock_send_message.called) - mock_send_message.called_with( - dataid, formid, XFORM, - request.user, SUBMISSION_DELETED) @override_settings(STREAM_DATA=True) def test_data_streaming(self): diff --git a/onadata/apps/api/tests/viewsets/test_xform_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_viewset.py index 7332386e37..07edbb5db4 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_viewset.py @@ -52,7 +52,6 @@ from onadata.apps.logger.models import XForm from onadata.apps.logger.xform_instance_parser import XLSFormError from onadata.apps.main.models import MetaData -from onadata.apps.messaging.constants import XFORM, FORM_UPDATED from onadata.apps.viewer.models import Export from onadata.libs.permissions import ( ROLES_ORDERED, DataEntryMinorRole, DataEntryOnlyRole, DataEntryRole, @@ -99,8 +98,7 @@ def setUp(self): 'get': 'list', }) - @patch('onadata.apps.logger.models.xform.send_message') - def test_form_publishing_arabic(self, mock_send_message): + def test_form_publishing_arabic(self): with HTTMock(enketo_mock): xforms = XForm.objects.count() view = XFormViewSet.as_view({ @@ -115,11 +113,6 @@ def test_form_publishing_arabic(self, mock_send_message): response = view(request) self.assertEqual(xforms + 1, XForm.objects.count()) self.assertEqual(response.status_code, 201) - # send send message upon form creation/update - xform = XForm.objects.get(id=response.data['formid']) - self.assertTrue(mock_send_message.called) - mock_send_message.called_with( - xform.id, xform.id, XFORM, xform.created_by, FORM_UPDATED) def test_replace_form_with_external_choices(self): with HTTMock(enketo_mock): diff --git a/onadata/apps/api/viewsets/submission_review_viewset.py b/onadata/apps/api/viewsets/submission_review_viewset.py index fabc115119..1c7856df96 100644 --- a/onadata/apps/api/viewsets/submission_review_viewset.py +++ b/onadata/apps/api/viewsets/submission_review_viewset.py @@ -52,17 +52,19 @@ def create(self, request, *args, **kwargs): """ Custom create method. Handle bulk create """ - self.object = self.get_object() + # self.object = self.get_object() if isinstance(request.data, list): serializer = self.get_serializer(data=request.data, many=True) serializer.is_valid(raise_exception=True) - submission_reviews = self.perform_create(serializer) - instance_ids = [sub_review.instance.id for sub_review in - submission_reviews] + self.perform_create(serializer) + instance_ids = [sub_review['instance'] for sub_review in + serializer.data] headers = self.get_success_headers(serializer.data) + xform = SubmissionReview.objects.get( + id=serializer.data[0]['id']).instance.xform send_message( instance_id=instance_ids, - target_id=self.object.instance.xform.id, + target_id=xform.id, target_type=XFORM, user=request.user, message_verb=SUBMISSION_REVIEWED) return Response(serializer.data, status=status.HTTP_201_CREATED, diff --git a/onadata/apps/logger/models/xform.py b/onadata/apps/logger/models/xform.py index 98a5db6972..f76d047d22 100644 --- a/onadata/apps/logger/models/xform.py +++ b/onadata/apps/logger/models/xform.py @@ -1036,6 +1036,7 @@ def set_object_permissions(sender, instance=None, created=False, **kwargs): from onadata.libs.utils.project_utils import set_project_perms_to_xform set_project_perms_to_xform(instance, instance.project) + post_save.connect( set_object_permissions, sender=XForm,