def test_exception(self, mock_export): # pylint: disable=unused-argument """ The export task should fail gracefully if an exception is thrown """ key = str(self.course.location.course_key) result = export_olx.delay(self.user.id, key, u'en') self._assert_failed(result, json.dumps({u'raw_error_msg': u'Boom!'}))
def test_non_course_author(self): """ Verify that users who aren't authors of the course are unable to export it """ _, nonstaff_user = self.create_non_staff_authed_user_client() key = str(self.course.location.course_key) result = export_olx.delay(nonstaff_user.id, key, u'en') self._assert_failed(result, u'Permission denied')
def test_invalid_user_id(self): """ Verify that attempts to export a course as an invalid user fail """ user_id = User.objects.order_by(u'-id').first().pk + 100 key = str(self.course.location.course_key) result = export_olx.delay(user_id, key, u'en') self._assert_failed(result, u'Unknown User ID: {}'.format(user_id))
def test_invalid_user_id(self, mock_raise_exc): # pylint: disable=unused-argument """ Verify that attempts to export a course as an invalid user fail """ user = UserFactory(id=User.objects.order_by('-id').first().pk + 100) key = str(self.course.location.course_key) result = export_olx.delay(user.id, key, 'en') self._assert_failed(result, f'Unknown User ID: {user.id}')
def test_success(self): """ Verify that a routine course export task succeeds """ key = str(self.course.location.course_key) result = export_olx.delay(self.user.id, key, u'en') status = UserTaskStatus.objects.get(task_id=result.id) self.assertEqual(status.state, UserTaskStatus.SUCCEEDED) artifacts = UserTaskArtifact.objects.filter(status=status) self.assertEqual(len(artifacts), 1) output = artifacts[0] self.assertEqual(output.name, 'Output')