def test_put_with_site(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with a local site """ draft_caption = 'The new caption' user = self._login_user(local_site=True) review_request = self.create_review_request(submitter=user, with_local_site=True, publish=True) file_attachment = self.create_file_attachment(review_request) rsp = self.apiPut( get_draft_file_attachment_item_url(review_request, file_attachment.pk, self.local_site_name), {'caption': draft_caption}, expected_mimetype=draft_file_attachment_item_mimetype) self.assertEqual(rsp['stat'], 'ok') draft = review_request.get_draft(user) self.assertNotEqual(draft, None) file_attachment = FileAttachment.objects.get(pk=file_attachment.pk) self.assertEqual(file_attachment.draft_caption, draft_caption)
def test_put_file_with_non_owner_local_site_admin(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as LocalSite admin """ review_request = self.create_review_request(submitter=self.user, with_local_site=True, publish=True) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(local_site=True, admin=True) self.assertNotEqual(user, self.user) rsp = self.api_put( get_draft_file_attachment_item_url(review_request, file_attachment.pk, self.local_site_name), { 'caption': 'My new caption', }, expected_mimetype=draft_file_attachment_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.check_put_result(user, rsp['draft_file_attachment'], file_attachment)
def setup_basic_delete_test(self, user, with_local_site, local_site_name): review_request = self.create_review_request( with_local_site=with_local_site, submitter=user) file_attachment = self.create_file_attachment(review_request, draft=True) return (get_draft_file_attachment_item_url(review_request, file_attachment.pk, local_site_name), [review_request, file_attachment])
def setup_basic_put_test(self, user, with_local_site, local_site_name, put_valid_data): review_request = self.create_review_request( with_local_site=with_local_site, submitter=user) file_attachment = self.create_file_attachment(review_request) return (get_draft_file_attachment_item_url(review_request, file_attachment.pk, local_site_name), draft_file_attachment_item_mimetype, { 'caption': 'My new caption' }, file_attachment, [])
def test_delete_file_with_non_owner_superuser(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as superuser """ review_request = self.create_review_request(submitter=self.user) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(admin=True) self.api_delete(get_draft_file_attachment_item_url(review_request, file_attachment.pk)) self.check_delete_result(user, review_request, file_attachment)
def setup_basic_put_test(self, user, with_local_site, local_site_name, put_valid_data): review_request = self.create_review_request( with_local_site=with_local_site, submitter=user) file_attachment = self.create_file_attachment(review_request) return (get_draft_file_attachment_item_url(review_request, file_attachment.pk, local_site_name), draft_file_attachment_item_mimetype, {'caption': 'My new caption'}, file_attachment, [])
def test_delete_file_with_non_owner_superuser(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as superuser """ review_request = self.create_review_request(submitter=self.user) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(admin=True) self.api_delete( get_draft_file_attachment_item_url(review_request, file_attachment.pk)) self.check_delete_result(user, review_request, file_attachment)
def test_put_file_attachment_with_site_no_access(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with a local site and Permission Denied error""" review_request, file_attachment_id = \ self.test_post_file_attachments_with_site() review_request.publish(User.objects.get(username='******')) self._login_user() rsp = self.apiPut(get_draft_file_attachment_item_url( review_request, file_attachment_id, self.local_site_name), {'caption': 'test'}, expected_status=403) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
def test_put_file_attachment_with_site_no_access(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with a local site and Permission Denied error""" review_request, file_attachment_id = \ self.test_post_file_attachments_with_site() review_request.publish(User.objects.get(username='******')) self._login_user() rsp = self.apiPut( get_draft_file_attachment_item_url(review_request, file_attachment_id, self.local_site_name), {'caption': 'test'}, expected_status=403) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
def test_delete_file_with_non_owner_local_site_admin(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as LocalSite admin """ review_request = self.create_review_request(submitter=self.user, with_local_site=True, publish=True) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(local_site=True, admin=True) self.assertNotEqual(user, self.user) self.api_delete(get_draft_file_attachment_item_url( review_request, file_attachment.pk, self.local_site_name)) self.check_delete_result(user, review_request, file_attachment)
def test_delete_file_with_publish(self): """Testing delete the published DraftFileAttachment""" review_request = self.create_review_request() self._login_user(admin=True) file_attachment = self.create_file_attachment(review_request, draft=True) review_request.get_draft().publish() self.api_delete(get_draft_file_attachment_item_url(review_request, file_attachment.pk)) draft = review_request.get_draft() file_attachment = FileAttachment.objects.get(pk=file_attachment.pk) self.assertFalse(file_attachment.inactive_review_request.exists()) self.assertIsNotNone(draft) self.assertIn(file_attachment, draft.inactive_file_attachments.all()) self.assertNotIn(file_attachment, draft.file_attachments.all())
def test_delete_file_with_non_owner_local_site_admin(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as LocalSite admin """ review_request = self.create_review_request(submitter=self.user, with_local_site=True, publish=True) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(local_site=True, admin=True) self.assertNotEqual(user, self.user) self.api_delete( get_draft_file_attachment_item_url(review_request, file_attachment.pk, self.local_site_name)) self.check_delete_result(user, review_request, file_attachment)
def test_delete_file_with_publish(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with published file attachment """ review_request = self.create_review_request(submitter=self.user) file_attachment = self.create_file_attachment(review_request, draft=True) review_request.get_draft().publish() self.api_delete( get_draft_file_attachment_item_url(review_request, file_attachment.pk)) draft = review_request.get_draft() file_attachment = FileAttachment.objects.get(pk=file_attachment.pk) self.assertFalse(file_attachment.inactive_review_request.exists()) self.assertIsNotNone(draft) self.assertIn(file_attachment, draft.inactive_file_attachments.all()) self.assertNotIn(file_attachment, draft.file_attachments.all())
def test_put_with_site_no_access(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with a local site and Permission Denied error """ review_request = self.create_review_request(submitter=self.user, with_local_site=True, publish=True) file_attachment = self.create_file_attachment(review_request) self._login_user() rsp = self.apiPut( get_draft_file_attachment_item_url(review_request, file_attachment.pk, self.local_site_name), {'caption': 'test'}, expected_status=403) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
def test_delete_file_with_publish(self): """Testing the DELETE review-requests/<id>/draft/file-attachments/<id>/ API with published file attachment """ review_request = self.create_review_request(submitter=self.user) file_attachment = self.create_file_attachment(review_request, draft=True) review_request.get_draft().publish() self.api_delete(get_draft_file_attachment_item_url(review_request, file_attachment.pk)) draft = review_request.get_draft() file_attachment = FileAttachment.objects.get(pk=file_attachment.pk) self.assertFalse(file_attachment.inactive_review_request.exists()) self.assertIsNotNone(draft) self.assertIn(file_attachment, draft.inactive_file_attachments.all()) self.assertNotIn(file_attachment, draft.file_attachments.all())
def test_put_with_non_owner_superuser(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with non-owner as superuser """ review_request = self.create_review_request(submitter=self.user) file_attachment = self.create_file_attachment(review_request, draft=True) user = self._login_user(admin=True) self.assertNotEqual(user, self.user) rsp = self.api_put( get_draft_file_attachment_item_url(review_request, file_attachment.pk), { 'caption': 'My new caption', }, expected_mimetype=draft_file_attachment_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.check_put_result(user, rsp['draft_file_attachment'], file_attachment)
def test_put_file_attachment(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API""" draft_caption = 'The new caption' review_request = self.create_review_request(submitter=self.user, publish=True) file_attachment = self.create_file_attachment(review_request) # Now modify the caption. rsp = self.apiPut( get_draft_file_attachment_item_url(review_request, file_attachment.id), {'caption': draft_caption}, expected_mimetype=draft_file_attachment_item_mimetype) self.assertEqual(rsp['stat'], 'ok') draft = review_request.get_draft(self.user) self.assertNotEqual(draft, None) file_attachment = FileAttachment.objects.get(pk=file_attachment.id) self.assertEqual(file_attachment.draft_caption, draft_caption)
def test_put_file_attachment_with_site(self): """Testing the PUT review-requests/<id>/draft/file-attachments/<id>/ API with a local site""" draft_caption = 'The new caption' user = User.objects.get(username='******') review_request, file_attachment_id = \ self.test_post_file_attachments_with_site() review_request.publish(user) rsp = self.apiPut( get_draft_file_attachment_item_url(review_request, file_attachment_id, self.local_site_name), {'caption': draft_caption}, expected_mimetype=draft_file_attachment_item_mimetype) self.assertEqual(rsp['stat'], 'ok') draft = review_request.get_draft(user) self.assertNotEqual(draft, None) file_attachment = FileAttachment.objects.get(pk=file_attachment_id) self.assertEqual(file_attachment.draft_caption, draft_caption)