Ejemplo n.º 1
0
    def test_add_to_queue(self):
        section = get_section_by_id('2013-summer-TRAIN-101-A')
        course = Course.objects.add_to_queue(section, queue_id=1)
        self.assertEquals(course.queue_id, 1)
        self.assertEquals(course.primary_id, None)

        section = get_section_by_id('2013-summer-TRAIN-100-AB')
        course = Course.objects.add_to_queue(section, queue_id=2)
        self.assertEquals(course.queue_id, 2)
        self.assertEquals(course.primary_id, '2013-summer-TRAIN-100-A')

        Course.objects.all().delete()
Ejemplo n.º 2
0
    def test_update_status(self):
        with self.settings(
                RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File',
                RESTCLIENTS_PWS_DAO_CLASS='restclients.dao_implementation.pws.File'):

            course_id = '2013-summer-TRAIN-101-A'

            section = get_section_by_id(course_id)

            course = Course.objects.add_to_queue(section, queue_id='3')
            Course.objects.update_status(section)
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, '3')
            self.assertEquals(course.provisioned_status, None)
            self.assertEquals(course.priority, PRIORITY_DEFAULT)

            section.is_withdrawn = True
            course = Course.objects.add_to_queue(section, queue_id='4')
            Course.objects.update_status(section)
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, '4')
            self.assertEquals(course.provisioned_status, None)
            self.assertEquals(course.priority, PRIORITY_NONE)

            Course.objects.all().delete()
Ejemplo n.º 3
0
    def test_remove_from_queue(self):
        with self.settings(
                RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File',
                RESTCLIENTS_PWS_DAO_CLASS='restclients.dao_implementation.pws.File'):

            course_id = '2013-summer-TRAIN-101-A'

            section = get_section_by_id(course_id)
            course = Course.objects.add_to_queue(section, queue_id='1')
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, '1')

            Course.objects.remove_from_queue(course_id)
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, None)
            self.assertEquals(course.provisioned_error, None)
            self.assertEquals(course.provisioned_status, None)

            # Remove with error
            course = Course.objects.add_to_queue(section, queue_id='2')
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, '2')

            Course.objects.remove_from_queue(course_id, error='oops')
            course = Course.objects.get(course_id=course_id)
            self.assertEquals(course.queue_id, None)
            self.assertEquals(course.provisioned_error, True)
            self.assertEquals(course.provisioned_status, 'oops')

            Course.objects.all().delete()
Ejemplo n.º 4
0
    def test_add_to_queue(self):
        with self.settings(
                RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File',
                RESTCLIENTS_PWS_DAO_CLASS='restclients.dao_implementation.pws.File'):

            section = get_section_by_id('2013-summer-TRAIN-101-A')
            course = Course.objects.add_to_queue(section, queue_id=1)
            self.assertEquals(course.queue_id, 1)
            self.assertEquals(course.primary_id, None)

            section = get_section_by_id('2013-summer-TRAIN-100-AB')
            course = Course.objects.add_to_queue(section, queue_id=2)
            self.assertEquals(course.queue_id, 2)
            self.assertEquals(course.primary_id, '2013-summer-TRAIN-100-A')

            Course.objects.all().delete()
Ejemplo n.º 5
0
    def test_remove_from_queue(self):
        course_id = '2013-summer-TRAIN-101-A'

        section = get_section_by_id(course_id)
        course = Course.objects.add_to_queue(section, queue_id='1')
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, '1')

        Course.objects.remove_from_queue(course_id)
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, None)
        self.assertEquals(course.provisioned_error, None)
        self.assertEquals(course.provisioned_status, None)

        # Remove with error
        course = Course.objects.add_to_queue(section, queue_id='2')
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, '2')

        Course.objects.remove_from_queue(course_id, error='oops')
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, None)
        self.assertEquals(course.provisioned_error, True)
        self.assertEquals(course.provisioned_status, 'oops')

        Course.objects.all().delete()
Ejemplo n.º 6
0
    def test_add_enrollment(self, mock_logger, mock_is_active_term):
        now_dt = datetime(2013, 1, 1).replace(tzinfo=utc)
        student_data = {
            'Section': get_section_by_id('2013-summer-TRAIN-101-A'),
            'UWRegID': 'BCDEF1234567890ABCDEF1234567890',
            'Role': 'Student',
            'Status': 'Active',
            'LastModified': now_dt,
            'InstructorUWRegID': None
        }

        # Section not in course table
        Enrollment.objects.add_enrollment(student_data)
        mock_logger.info.assert_called_with(
            'ENROLLMENT: IGNORE Inactive section 2013-summer-TRAIN-101-A, '
            'BCDEF1234567890ABCDEF1234567890, Student')

        course, created = Course.objects.get_or_create(
            course_id='2013-summer-TRAIN-101-A')

        # Course model without a provisioned_date
        Enrollment.objects.add_enrollment(student_data)
        mock_logger.info.assert_called_with(
            'ENROLLMENT: IGNORE Unprovisioned course 2013-summer-TRAIN-101-A, '
            'BCDEF1234567890ABCDEF1234567890, Student')

        # Course model with a provisioned_date
        course.provisioned_date = now_dt
        course.save()
        Enrollment.objects.add_enrollment(student_data)
        mock_logger.info.assert_called_with(
            'ENROLLMENT: ADD 2013-summer-TRAIN-101-A, '
            'BCDEF1234567890ABCDEF1234567890, Student, active, '
            '2013-01-01 00:00:00+00:00')

        # Enrollment added again
        Enrollment.objects.add_enrollment(student_data)
        mock_logger.info.assert_called_with(
            'ENROLLMENT: UPDATE 2013-summer-TRAIN-101-A, '
            'BCDEF1234567890ABCDEF1234567890, Student, active, '
            '2013-01-01 00:00:00+00:00')

        # Enrollment added again with deleted status
        student_data['Status'] = 'Deleted'
        Enrollment.objects.add_enrollment(student_data)
        mock_logger.info.assert_called_with(
            'ENROLLMENT: IGNORE 2013-summer-TRAIN-101-A, '
            'BCDEF1234567890ABCDEF1234567890, '
            '2013-01-01 00:00:00+00:00 before 2013-01-01 00:00:00+00:00')

        Course.objects.all().delete()
        Enrollment.objects.all().delete()
Ejemplo n.º 7
0
    def get_section_resource_by_id(self, section_id):
        """
        Fetch the section resource for the passed section ID, and add to queue.
        """
        try:
            section = get_section_by_id(section_id)
            Course.objects.add_to_queue(section, self.queue_id)
            return section

        except (ValueError, CoursePolicyException, DataFailureException) as ex:
            Course.objects.remove_from_queue(section_id, ex)
            self.logger.info("Skip section {}: {}".format(section_id, ex))
            raise
Ejemplo n.º 8
0
    def get_section_resource_by_id(self, section_id):
        """
        Fetch the section resource for the passed section ID.
        """
        try:
            return get_section_by_id(section_id)

        except DataFailureException as err:
            data = json.loads(err.msg)
            Course.objects.remove_from_queue(section_id, "%s: %s %s" % (
                err.url, err.status, data["StatusDescription"]))
            self.logger.info("Skip section %s: %s %s" % (
                section_id, err.status, data["StatusDescription"]))
            raise

        except ValueError as err:
            Course.objects.remove_from_queue(section_id, err)
            self.logger.info("Skip section %s: %s" % (section_id, err))
            raise
Ejemplo n.º 9
0
    def test_update_status(self):
        course_id = '2013-summer-TRAIN-101-A'

        section = get_section_by_id(course_id)

        course = Course.objects.add_to_queue(section, queue_id='3')
        Course.objects.update_status(section)
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, '3')
        self.assertEquals(course.provisioned_status, None)
        self.assertEquals(course.priority, course.PRIORITY_DEFAULT)

        section.delete_flag = section.DELETE_FLAG_WITHDRAWN
        course = Course.objects.add_to_queue(section, queue_id='4')
        Course.objects.update_status(section)
        course = Course.objects.get(course_id=course_id)
        self.assertEquals(course.queue_id, '4')
        self.assertEquals(course.provisioned_status, None)
        self.assertEquals(course.priority, course.PRIORITY_NONE)

        Course.objects.all().delete()
Ejemplo n.º 10
0
    def test_add_enrollment(self, mock_logger):
        with self.settings(
                RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File',
                RESTCLIENTS_PWS_DAO_CLASS='restclients.dao_implementation.pws.File'):

            now_dt = datetime(2013, 1, 1).replace(tzinfo=utc)
            student_data = {'Section': get_section_by_id('2013-summer-TRAIN-101-A'),
                            'UWRegID': 'BCDEF1234567890ABCDEF1234567890',
                            'Role': Enrollment.STUDENT_ROLE,
                            'Status': 'Active',
                            'LastModified': now_dt,
                            'InstructorUWRegID': None}

            # Section not in course table
            Enrollment.objects.add_enrollment(student_data)
            mock_logger.info.assert_called_with('Enrollment: IGNORE Unprovisioned course 2013-summer-TRAIN-101-A, BCDEF1234567890ABCDEF1234567890, Student')

            course = Course.objects.get(course_id='2013-summer-TRAIN-101-A')

            # Course model without a provisioned_date
            Enrollment.objects.add_enrollment(student_data)
            mock_logger.info.assert_called_with('Enrollment: IGNORE Unprovisioned course 2013-summer-TRAIN-101-A, BCDEF1234567890ABCDEF1234567890, Student')

            # Course model with a provisioned_date
            course.provisioned_date = now_dt
            course.save()
            Enrollment.objects.add_enrollment(student_data)
            mock_logger.info.assert_called_with('Enrollment: ADD 2013-summer-TRAIN-101-A, BCDEF1234567890ABCDEF1234567890, Student, active, 2013-01-01 00:00:00+00:00')

            # Enrollment added again
            Enrollment.objects.add_enrollment(student_data)
            mock_logger.info.assert_called_with('Enrollment: UPDATE 2013-summer-TRAIN-101-A, BCDEF1234567890ABCDEF1234567890, Student, active, 2013-01-01 00:00:00+00:00')

            # Enrollment added again with deleted status
            student_data['Status'] = 'Deleted'
            Enrollment.objects.add_enrollment(student_data)
            mock_logger.info.assert_called_with('Enrollment: IGNORE 2013-summer-TRAIN-101-A, BCDEF1234567890ABCDEF1234567890, 2013-01-01 00:00:00+00:00 before 2013-01-01 00:00:00+00:00')

            Course.objects.all().delete()
            Enrollment.objects.all().delete()