def test_content_migration_copy_called_with_canvas_course_id_positional_arg(self, content_migrations, **kwargs):
     """
     Test that SDK call to initiate course copy has the canvas_course_id as a positional argument
     """
     start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertTrue(self.canvas_course_id in args)
 def test_content_migration_copy_called_with_expected_migration_type_keyword(self, content_migrations, **kwargs):
     """
     Test that SDK call to initiate course copy has the right migration_type specified
     """
     expected_migration_type = 'course_copy_importer'
     start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertEqual(kwargs.get('migration_type'), expected_migration_type)
 def test_custom_exception_raised_if_no_template_for_school(self, get_default_template_for_school, **kwargs):
     """
     Test that if an NoTemplateExistsForSchool exception gets triggered when retrieving the school
     template, a NoTemplateExistsForCourse exception is raised back to the caller.
     """
     get_default_template_for_school.side_effect = NoTemplateExistsForSchool("")
     with self.assertRaises(NoTemplateExistsForSchool):
         start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
 def test_content_migration_copy_called_with_expected_templated_id_keyword(self, content_migrations,
                                                                           get_default_template_for_school, **kwargs):
     """
     Test that SDK call to initiate course copy has the expected template id specified
     """
     get_default_template_for_school.return_value = self.template
     start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertEqual(kwargs.get('settings_source_course_id'), self.template.template_id)
Example #5
0
 def test_content_migration_copy_called_with_canvas_course_id_positional_arg(
         self, content_migrations, **kwargs):
     """
     Test that SDK call to initiate course copy has the canvas_course_id as a positional argument
     """
     start_course_template_copy(self.sis_course_data, self.canvas_course_id,
                                self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertTrue(self.canvas_course_id in args)
 def test_exception_results_in_worflow_state_getting_updated (self, update_mock, get_default_template_for_school, **kwargs):
     """
     Test that if an NoTemplateExistsForSchool exception gets triggered when retrieving the school
     template,  the update_content_migration_workflow_state is called to set the state to STATUS_SETUP_FAILED
     """
     get_default_template_for_school.side_effect = NoTemplateExistsForSchool("")
     with self.assertRaises(NoTemplateExistsForSchool):
         start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
         update_mock.assert_called_with(self.sis_course_data, CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
Example #7
0
 def test_content_migration_copy_called_with_expected_migration_type_keyword(
         self, content_migrations, **kwargs):
     """
     Test that SDK call to initiate course copy has the right migration_type specified
     """
     expected_migration_type = 'course_copy_importer'
     start_course_template_copy(self.sis_course_data, self.canvas_course_id,
                                self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertEqual(kwargs.get('migration_type'), expected_migration_type)
    def test_get_default_template_for_school_called_with_school_code(self, get_default_template_for_school, **kwargs):
        """
        Test that controller method calls get_default_template_for_school with expected parameter
        """
        # iterable_ccmjob_mock = MagicMock()
        # filter_mock.return_value = iterable_ccmjob_mock
        # iterable_ccmjob_mock.__iter__ = Mock(return_value=iter([self.m_canvas_content_migration_job]))


        start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
        get_default_template_for_school.assert_called_with(self.sis_course_data.school_code)
Example #9
0
 def test_custom_exception_raised_if_no_template_for_school(
         self, get_default_template_for_school, **kwargs):
     """
     Test that if an NoTemplateExistsForSchool exception gets triggered when retrieving the school
     template, a NoTemplateExistsForCourse exception is raised back to the caller.
     """
     get_default_template_for_school.side_effect = NoTemplateExistsForSchool(
         "")
     with self.assertRaises(NoTemplateExistsForSchool):
         start_course_template_copy(self.sis_course_data,
                                    self.canvas_course_id, self.user_id)
Example #10
0
 def test_content_migration_copy_called_with_expected_templated_id_keyword(
         self, content_migrations, get_default_template_for_school,
         **kwargs):
     """
     Test that SDK call to initiate course copy has the expected template id specified
     """
     get_default_template_for_school.return_value = self.template
     start_course_template_copy(self.sis_course_data, self.canvas_course_id,
                                self.user_id)
     args, kwargs = content_migrations.create_content_migration_courses.call_args
     self.assertEqual(kwargs.get('settings_source_course_id'),
                      self.template.template_id)
Example #11
0
    def test_get_default_template_for_school_called_with_school_code(
            self, get_default_template_for_school, **kwargs):
        """
        Test that controller method calls get_default_template_for_school with expected parameter
        """
        # iterable_ccmjob_mock = MagicMock()
        # filter_mock.return_value = iterable_ccmjob_mock
        # iterable_ccmjob_mock.__iter__ = Mock(return_value=iter([self.m_canvas_content_migration_job]))

        start_course_template_copy(self.sis_course_data, self.canvas_course_id,
                                   self.user_id)
        get_default_template_for_school.assert_called_with(
            self.sis_course_data.school_code)
Example #12
0
 def test_exception_results_in_worflow_state_getting_updated(
         self, update_mock, get_default_template_for_school, **kwargs):
     """
     Test that if an NoTemplateExistsForSchool exception gets triggered when retrieving the school
     template,  the update_content_migration_workflow_state is called to set the state to STATUS_SETUP_FAILED
     """
     get_default_template_for_school.side_effect = NoTemplateExistsForSchool(
         "")
     with self.assertRaises(NoTemplateExistsForSchool):
         start_course_template_copy(self.sis_course_data,
                                    self.canvas_course_id, self.user_id)
         update_mock.assert_called_with(
             self.sis_course_data,
             CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
    def test_content_migration_job_row_updated(self,content_migrations, get_course_generation_data_for_sis_course_id,
                                                **kwargs):
        """
        Test that start_course_template_copy results in the content migration job row getting saved with the right params
        """

        get_course_generation_data_for_sis_course_id.return_value = m_canvas_content_migration_job
        ret = start_course_template_copy(self.sis_course_data, self.canvas_course_id, self.user_id)
        m_canvas_content_migration_job.save.assert_called_with(update_fields=['canvas_course_id', 'content_migration_id',
                                                                                'status_url', 'workflow_state',
                                                                              'created_by_user_id'])
Example #14
0
    def test_content_migration_job_row_updated(
            self, content_migrations,
            get_course_generation_data_for_sis_course_id, **kwargs):
        """
        Test that start_course_template_copy results in the content migration job row getting saved with the right params
        """

        get_course_generation_data_for_sis_course_id.return_value = m_canvas_content_migration_job
        ret = start_course_template_copy(self.sis_course_data,
                                         self.canvas_course_id, self.user_id)
        m_canvas_content_migration_job.save.assert_called_with(update_fields=[
            'canvas_course_id', 'content_migration_id', 'status_url',
            'workflow_state', 'created_by_user_id'
        ])
def _init_courses_with_status_setup():
    """
    get all records in the canvas course generation job table that have the status 'setup'.
    These are courses that have not been created, they only have a CanvasCourseGenerationJob with a 'setup' status.
    This method will create the course and update the status to QUEUED
    """

    create_jobs = CanvasCourseGenerationJob.objects.filter_setup_for_bulkjobs()
    # Get the bulk job parent for each course job and map by id for later use
    bulk_jobs = {
        b.id: b
        for b in BulkJob.objects.filter(
            id__in=[j.bulk_job_id for j in create_jobs])
    }

    # for each or the records above, create the course and update the status
    for create_job in create_jobs:
        # for each job we need to get the bulk_job_id, user, and course id, these are
        # needed by the calls to create the course below. If any of these break, mark the course as failed
        # and continue to the next course.
        bulk_job = bulk_jobs.get(create_job.bulk_job_id)
        if not bulk_job:
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue
        bulk_job_id = bulk_job.id

        sis_user_id = create_job.created_by_user_id
        if not sis_user_id:
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        sis_course_id = create_job.sis_course_id
        if not sis_course_id:
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # try to create the canvas course - create_canvas_course has been modified so it will not
        # try to create a new CanvasCourseGenerationJob record if a bulk_job is present
        try:
            logger.info('calling create_canvas_course(%s, %s, bulk_job_id=%s)',
                        sis_course_id, sis_user_id, bulk_job_id)
            course = create_canvas_course(
                sis_course_id,
                sis_user_id,
                bulk_job=bulk_job,
            )
        except (CanvasCourseAlreadyExistsError,
                CourseGenerationJobCreationError, CanvasCourseCreateError,
                CanvasSectionCreateError):
            message = 'content migration error for course with id %s' % sis_course_id
            logger.exception(message)
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # get the course data - this is needed for the start_course_template_copy method
        try:
            sis_course_data = get_course_data(sis_course_id)
        except ObjectDoesNotExist:
            message = 'Course id %s does not exist, skipping....' % sis_course_id
            logger.exception(message)
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # Initiate the async job to copy the course template, if a template was selected for the bulk job
        if bulk_job.template_canvas_course_id:
            try:
                start_course_template_copy(
                    sis_course_data,
                    course['id'],
                    sis_user_id,
                    course_job_id=create_job.pk,
                    bulk_job_id=bulk_job_id,
                    template_id=bulk_job.template_canvas_course_id)
            except Exception:
                logger.exception(
                    'template migration failed for course instance id %s' %
                    sis_course_id)
                create_job.update_workflow_state(
                    CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
        else:
            logger.info('no template selected for  %s' % sis_course_id)
            # When there's no template, it doesn't need any migration and the job is ready to be finalized
            create_job.update_workflow_state(
                CanvasCourseGenerationJob.STATUS_PENDING_FINALIZE)
def _init_courses_with_status_setup():
    """
    get all records in the canvas course generation job table that have the status 'setup'.
    These are courses that have not been created, they only have a CanvasCourseGenerationJob with a 'setup' status.
    This method will create the course and update the status to QUEUED
    """

    create_jobs = CanvasCourseGenerationJob.objects.filter_setup_for_bulkjobs()
    # Get the bulk job parent for each course job and map by id for later use
    bulk_jobs = {b.id: b for b in BulkJob.objects.filter(id__in=[j.bulk_job_id for j in create_jobs])}

    # for each or the records above, create the course and update the status
    for create_job in create_jobs:
        # for each job we need to get the bulk_job_id, user, and course id, these are
        # needed by the calls to create the course below. If any of these break, mark the course as failed
        # and continue to the next course.
        bulk_job = bulk_jobs.get(create_job.bulk_job_id)
        if not bulk_job:
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue
        bulk_job_id = bulk_job.id

        sis_user_id = create_job.created_by_user_id
        if not sis_user_id:
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        sis_course_id = create_job.sis_course_id
        if not sis_course_id:
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # try to create the canvas course - create_canvas_course has been modified so it will not
        # try to create a new CanvasCourseGenerationJob record if a bulk_job is present
        try:
            logger.info(
                'calling create_canvas_course(%s, %s, bulk_job_id=%s)',
                sis_course_id, sis_user_id,
                bulk_job_id
            )
            course = create_canvas_course(
                sis_course_id,
                sis_user_id,
                bulk_job=bulk_job,
            )
        except (CanvasCourseAlreadyExistsError, CourseGenerationJobCreationError, CanvasCourseCreateError,
                CanvasSectionCreateError):
            message = 'content migration error for course with id %s' % sis_course_id
            logger.exception(message)
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # get the course data - this is needed for the start_course_template_copy method
        try:
            sis_course_data = get_course_data(sis_course_id)
        except ObjectDoesNotExist as ex:
            message = 'Course id %s does not exist, skipping....' % sis_course_id
            logger.exception(message)
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
            continue

        # Initiate the async job to copy the course template, if a template was selected for the bulk job
        if bulk_job.template_canvas_course_id:
            try:
                start_course_template_copy(
                    sis_course_data,
                    course['id'],
                    sis_user_id,
                    course_job_id=create_job.pk,
                    bulk_job_id=bulk_job_id,
                    template_id=bulk_job.template_canvas_course_id
                )
            except:
                logger.exception('template migration failed for course instance id %s' % sis_course_id)
                create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_SETUP_FAILED)
        else:
            logger.info('no template selected for  %s' % sis_course_id)
            # When there's no template, it doesn't need any migration and the job is ready to be finalized
            create_job.update_workflow_state(CanvasCourseGenerationJob.STATUS_PENDING_FINALIZE)