From ed280daa85bb1868d797abec1806d04d2ea4cf2a Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Thu, 29 Apr 2021 17:16:45 +0300 Subject: [PATCH 1/5] Ensure .ssh directory is present --- .github/workflows/ecr-image-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ecr-image-build.yml b/.github/workflows/ecr-image-build.yml index 99121c55af..6f6ace217c 100644 --- a/.github/workflows/ecr-image-build.yml +++ b/.github/workflows/ecr-image-build.yml @@ -46,7 +46,8 @@ jobs: run: | ssh-agent -a $SSH_AUTH_SOCK >> /dev/null ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}" - ssh-keyscan github.com >> ~/.ssh/known_hosts + mkdir -p ~/.ssh + ssh-keyscan github.com > ~/.ssh/known_hosts - name: Build and push id: docker-build From 62ee85b068ebed38649f77e47de62d8a868d1a46 Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Thu, 29 Apr 2021 17:32:48 +0300 Subject: [PATCH 2/5] Assert that the `send_message` function was called with the right arguements --- onadata/apps/api/tests/viewsets/test_data_viewset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py index cc85004082..c7cc28e5bf 100644 --- a/onadata/apps/api/tests/viewsets/test_data_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py @@ -1439,9 +1439,9 @@ def test_delete_submission(self, send_message_mock): self.assertEqual(first_xform_instance[0].deleted_by, request.user) # message sent upon delete self.assertTrue(send_message_mock.called) - send_message_mock.called_with( - [dataid], formid, XFORM, - request.user, SUBMISSION_DELETED) + send_message_mock.assert_called_with( + instance_id=dataid, target_id=formid, target_type=XFORM, + user=request.user, message_verb=SUBMISSION_DELETED) # second delete of same submission should return 404 request = self.factory.delete('/', **self.extra) From 88a55046e5506fa798a60a406deddaa338589140 Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Thu, 29 Apr 2021 17:34:21 +0300 Subject: [PATCH 3/5] Pass an Instance ID instead of an Instance object to `send_message` --- onadata/apps/api/viewsets/data_viewset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onadata/apps/api/viewsets/data_viewset.py b/onadata/apps/api/viewsets/data_viewset.py index 6361a8c9e9..f77f863a0b 100644 --- a/onadata/apps/api/viewsets/data_viewset.py +++ b/onadata/apps/api/viewsets/data_viewset.py @@ -344,10 +344,11 @@ def destroy(self, request, *args, **kwargs): if request.user.has_perm( CAN_DELETE_SUBMISSION, self.object.xform): + instance_id = self.object.pk delete_instance(self.object, request.user) # send message send_message( - instance_id=self.object, target_id=self.object.xform.id, + instance_id=instance_id, target_id=self.object.xform.id, target_type=XFORM, user=request.user, message_verb=SUBMISSION_DELETED) else: From e280efd7ce497a60fad2390bbd45e974fdf45dbe Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Fri, 30 Apr 2021 09:49:36 +0300 Subject: [PATCH 4/5] Update submission review test Remove assertion statement that checked whether Instance and Submission Review date_created fields were the same; Instances & Submission Reviews are two different entities and are not created at the same time as such asserting that the date_created is the same between the two will not always pass. --- onadata/apps/logger/tests/models/test_instance.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/onadata/apps/logger/tests/models/test_instance.py b/onadata/apps/logger/tests/models/test_instance.py index 7d1e227452..47f8c77654 100644 --- a/onadata/apps/logger/tests/models/test_instance.py +++ b/onadata/apps/logger/tests/models/test_instance.py @@ -248,8 +248,6 @@ def test_instance_json_updated_on_review(self): self.assertEqual(SubmissionReview.APPROVED, instance.json[u'_review_status']) self.assertEqual(SubmissionReview.APPROVED, instance_review.status) - self.assertEqual(instance.date_created.strftime(MONGO_STRFTIME), - instance_review.date_created.strftime(MONGO_STRFTIME)) comment = instance_review.get_note_text() self.assertEqual(None, comment) self.assertTrue(instance.has_a_review) @@ -273,8 +271,6 @@ def test_instance_json_updated_on_review(self): self.assertEqual(SubmissionReview.APPROVED, instance.json[u'_review_status']) self.assertEqual(SubmissionReview.APPROVED, instance_review.status) - self.assertEqual(instance.date_created.strftime(MONGO_STRFTIME), - instance_review.date_created.strftime(MONGO_STRFTIME)) comment = instance_review.get_note_text() self.assertEqual("Hey There", comment) self.assertTrue(instance.has_a_review) From abec361254906eb049bedf0d3a6b197827307ac1 Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Fri, 30 Apr 2021 09:53:19 +0300 Subject: [PATCH 5/5] Update form API tests - Assert returned response is equal to the stored Instance JSON --- onadata/apps/main/tests/test_form_api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/onadata/apps/main/tests/test_form_api.py b/onadata/apps/main/tests/test_form_api.py index 3cdc65735c..f53d329ed6 100644 --- a/onadata/apps/main/tests/test_form_api.py +++ b/onadata/apps/main/tests/test_form_api.py @@ -84,8 +84,7 @@ def test_api_jsonp(self): start = callback.__len__() + 1 end = content.__len__() - 1 content = content[start: end] - d = dict_for_mongo_without_userform_id( - self.xform.instances.all()[0].parsed_instance) + d = self.xform.instances.all()[0].json find_d = json.loads(content)[0] self.assertEqual(find_d, d)