Esempio n. 1
0
    def test_update_course_codes(self):
        """
        Ensure that nested program course codes can be updated.
        """
        org = OrganizationFactory.create(key='test-org-key')
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        for n in range(3):
            course_code = CourseCodeFactory.create(
                key='test-course-key-{}'.format(n),
                display_name='test-course-display_name-{}'.format(n),
                organization=org,
            )
            # associate the first and second course codes, not the third.
            if n < 2:
                ProgramCourseCodeFactory.create(program=program,
                                                course_code=course_code)

        # PATCH the course codes: send one already associated, and another not yet associated
        patch_data = {
            u'course_codes': [
                {
                    u'key': 'test-course-key-0',
                    u'organization': {
                        u'key': 'test-org-key',
                    },
                },
                {
                    u'key': 'test-course-key-2',
                    u'organization': {
                        u'key': 'test-org-key',
                    },
                },
            ],
        }
        response = self._make_request(program_id=program.id,
                                      admin=True,
                                      method='patch',
                                      data=patch_data)
        self.assertEqual(response.status_code, 200)

        # check response data
        patched_course_codes = response.data['course_codes']
        self.assertEqual([u'test-course-key-0', u'test-course-key-2'],
                         sorted([cc[u'key'] for cc in patched_course_codes]))

        # check models (ensure things were saved properly)
        db_course_codes = ProgramCourseCode.objects.filter(
            program__id=program.id)
        self.assertEqual([u'test-course-key-0', u'test-course-key-2'],
                         sorted(
                             [pcc.course_code.key for pcc in db_course_codes]))
Esempio n. 2
0
    def test_update_course_codes(self):
        """
        Ensure that nested program course codes can be updated.
        """
        org = OrganizationFactory.create(key='test-org-key')
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        for n in range(3):
            course_code = CourseCodeFactory.create(
                key='test-course-key-{}'.format(n),
                display_name='test-course-display_name-{}'.format(n),
                organization=org,
            )
            # associate the first and second course codes, not the third.
            if n < 2:
                ProgramCourseCodeFactory.create(program=program, course_code=course_code)

        # PATCH the course codes: send one already associated, and another not yet associated
        patch_data = {
            'course_codes': [
                {
                    'key': 'test-course-key-0',
                    'organization': {
                        'key': 'test-org-key',
                    },
                },
                {
                    'key': 'test-course-key-2',
                    'organization': {
                        'key': 'test-org-key',
                    },
                },
            ],
        }
        response = self._make_request(program_id=program.id, admin=True, method='patch', data=patch_data)
        self.assertEqual(response.status_code, 200)

        # check response data
        patched_course_codes = response.data['course_codes']
        self.assertEqual(
            ['test-course-key-0', 'test-course-key-2'],
            sorted([cc['key'] for cc in patched_course_codes])
        )

        # check models (ensure things were saved properly)
        db_course_codes = ProgramCourseCode.objects.filter(program__id=program.id)
        self.assertEqual(
            ['test-course-key-0', 'test-course-key-2'],
            sorted([pcc.course_code.key for pcc in db_course_codes])
        )
Esempio n. 3
0
    def test_program_completion_filtering(self, status, is_admin):
        """Verify that program candidates for completion are filtered."""
        program = ProgramFactory.create(status=status)
        org = OrganizationFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)

        course_code = CourseCodeFactory.create(organization=org)
        program_course_code = ProgramCourseCodeFactory.create(
            program=program,
            course_code=course_code
        )

        course_key = 'org/code/run'
        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
        )

        complete_run_modes = {'completed_courses': [
            {'course_id': course_key, 'mode': 'verified'},
        ]}

        response = self._make_request(method='post', complete=True, data=complete_run_modes, admin=is_admin)

        self.assertEqual(response.status_code, 200)

        program_ids = response.data['program_ids']
        if status in [ProgramStatus.ACTIVE, ProgramStatus.RETIRED]:
            self.assertEqual(program_ids, [1])
        else:
            # No one should be able to complete deleted or unpublished programs.
            self.assertEqual(program_ids, [])
Esempio n. 4
0
    def test_update_run_modes(self):
        """
        Ensure that nested run modes can be updated.
        """
        org = OrganizationFactory.create()
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(organization=org)
        program_course_code = ProgramCourseCodeFactory.create(
            program=program, course_code=course_code)

        for n in range(2):
            ProgramCourseRunModeFactory.create(
                program_course_code=program_course_code,
                course_key='course-v1:org+course+run-{}'.format(n))

        # PATCH the course code's run modes: send one matching an existing record and a second new one
        patch_data = {
            u'course_codes': [
                {
                    u'key':
                    course_code.key,
                    u'organization': {
                        u'key': course_code.organization.key,
                    },
                    u'run_modes': [
                        {
                            u'course_key': u'course-v1:org+course+run-0',
                            u'mode_slug': u'verified',
                        },
                        {
                            u'course_key': u'course-v1:org+course+run-2',
                            u'mode_slug': u'verified',
                            u'start_date': u'2015-12-09T21:20:26.491639Z',
                        },
                    ],
                },
            ],
        }
        response = self._make_request(program_id=program.id,
                                      admin=True,
                                      method='patch',
                                      data=patch_data)
        self.assertEqual(response.status_code, 200)

        # check response data
        patched_run_modes = response.data['course_codes'][0]['run_modes']
        self.assertEqual(
            [u'course-v1:org+course+run-0', u'course-v1:org+course+run-2'],
            sorted([rm[u'course_key'] for rm in patched_run_modes]))

        # check models (ensure things were saved properly)
        db_run_modes = ProgramCourseRunMode.objects.filter(
            program_course_code=program_course_code)
        self.assertEqual(
            [u'course-v1:org+course+run-0', u'course-v1:org+course+run-2'],
            sorted([rm.course_key for rm in db_run_modes]))
Esempio n. 5
0
    def test_update_run_modes(self):
        """
        Ensure that nested run modes can be updated.
        """
        org = OrganizationFactory.create()
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(organization=org)
        program_course_code = ProgramCourseCodeFactory.create(program=program, course_code=course_code)

        for n in range(2):
            ProgramCourseRunModeFactory.create(
                program_course_code=program_course_code,
                course_key='course-v1:org+course+run-{}'.format(n)
            )

        # PATCH the course code's run modes: send one matching an existing record and a second new one
        patch_data = {
            'course_codes': [
                {
                    'key': course_code.key,
                    'organization': {
                        'key': course_code.organization.key,
                    },
                    'run_modes': [
                        {
                            'course_key': 'course-v1:org+course+run-0',
                            'mode_slug': 'verified',
                        },
                        {
                            'course_key': 'course-v1:org+course+run-2',
                            'mode_slug': 'verified',
                            'start_date': '2015-12-09T21:20:26.491639Z',
                        },
                    ],
                },
            ],
        }
        response = self._make_request(program_id=program.id, admin=True, method='patch', data=patch_data)
        self.assertEqual(response.status_code, 200)

        # check response data
        patched_run_modes = response.data['course_codes'][0]['run_modes']
        self.assertEqual(
            ['course-v1:org+course+run-0', 'course-v1:org+course+run-2'],
            sorted([rm['course_key'] for rm in patched_run_modes])
        )

        # check models (ensure things were saved properly)
        db_run_modes = ProgramCourseRunMode.objects.filter(program_course_code=program_course_code)
        self.assertEqual(
            ['course-v1:org+course+run-0', 'course-v1:org+course+run-2'],
            sorted([rm.course_key for rm in db_run_modes])
        )
Esempio n. 6
0
    def test_program_completion_filtering(self, status, is_admin):
        """Verify that program candidates for completion are filtered."""
        program = ProgramFactory.create(status=status)
        org = OrganizationFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)

        course_code = CourseCodeFactory.create(organization=org)
        program_course_code = ProgramCourseCodeFactory.create(
            program=program, course_code=course_code)

        course_key = 'org/code/run'
        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
        )

        complete_run_modes = {
            'completed_courses': [
                {
                    'course_id': course_key,
                    'mode': 'verified'
                },
            ]
        }

        response = self._make_request(method='post',
                                      complete=True,
                                      data=complete_run_modes,
                                      admin=is_admin)

        self.assertEqual(response.status_code, 200)

        program_ids = response.data['program_ids']
        if status in [ProgramStatus.ACTIVE, ProgramStatus.RETIRED]:
            self.assertEqual(program_ids, [1])
        else:
            # No one should be able to complete deleted or unpublished programs.
            self.assertEqual(program_ids, [])
Esempio n. 7
0
    def test_view_with_nested(self):
        """
        Ensure that nested serializers are working in program detail views.
        """
        start_date = datetime.datetime.now(tz=pytz.UTC)
        course_key = "edX/DemoX/Demo_Course"
        run_key = "Demo_Course"

        org = OrganizationFactory.create(key="test-org-key",
                                         display_name="test-org-display_name")
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(
            key="test-course-key",
            display_name="test-course-display_name",
            organization=org,
        )

        program_course_code = ProgramCourseCodeFactory.create(
            program=program, course_code=course_code)

        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
            start_date=start_date)

        response = self._make_request(program_id=program.id, admin=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.data, {
                u"name":
                program.name,
                u"subtitle":
                program.subtitle,
                u"category":
                program.category,
                u"status":
                ProgramStatus.UNPUBLISHED,
                u"organizations": [{
                    u"key": "test-org-key",
                    u"display_name": "test-org-display_name",
                }],
                u"course_codes": [{
                    u"key":
                    "test-course-key",
                    u"display_name":
                    "test-course-display_name",
                    u"organization": {
                        u"key": "test-org-key",
                        u"display_name": "test-org-display_name",
                    },
                    u"run_modes":
                    [{
                        u"course_key": course_key,
                        u"run_key": run_key,
                        u"mode_slug": "verified",
                        u"sku": '',
                        u"start_date": start_date.strftime(DRF_DATE_FORMAT)
                    }],
                }],
                u"id":
                program.id,
                u"created":
                program.created.strftime(DRF_DATE_FORMAT),
                u"modified":
                program.modified.strftime(DRF_DATE_FORMAT),
                u'marketing_slug':
                program.marketing_slug,
                u'banner_image_urls': {}
            })
Esempio n. 8
0
    def test_view_with_nested(self):
        """
        Ensure that nested serializers are working in program detail views.
        """
        start_date = datetime.datetime.now(tz=pytz.UTC)
        course_key = "edX/DemoX/Demo_Course"
        run_key = "Demo_Course"

        org = OrganizationFactory.create(key="test-org-key",
                                         display_name="test-org-display_name")
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(
            key="test-course-key",
            display_name="test-course-display_name",
            organization=org,
        )

        program_course_code = ProgramCourseCodeFactory.create(
            program=program, course_code=course_code)

        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
            start_date=start_date)

        response = self._make_request(program_id=program.id, admin=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.data, {
                'name':
                program.name,
                'subtitle':
                program.subtitle,
                'category':
                program.category,
                'status':
                ProgramStatus.UNPUBLISHED,
                'organizations': [{
                    'key': 'test-org-key',
                    'display_name': 'test-org-display_name',
                }],
                'course_codes': [{
                    'key':
                    'test-course-key',
                    'display_name':
                    'test-course-display_name',
                    'organization': {
                        'key': 'test-org-key',
                        'display_name': 'test-org-display_name',
                    },
                    'run_modes':
                    [{
                        'course_key': course_key,
                        'run_key': run_key,
                        'mode_slug': 'verified',
                        'sku': '',
                        'start_date': start_date.strftime(DRF_DATE_FORMAT)
                    }],
                }],
                'id':
                program.id,
                'created':
                program.created.strftime(DRF_DATE_FORMAT),
                'modified':
                program.modified.strftime(DRF_DATE_FORMAT),
                'marketing_slug':
                program.marketing_slug,
                'banner_image_urls': {},
                'uuid':
                unicode(program.uuid),
            })
Esempio n. 9
0
    def test_view_with_nested(self):
        """
        Ensure that nested serializers are working in program detail views.
        """
        start_date = datetime.datetime.now(tz=pytz.UTC)
        course_key = "edX/DemoX/Demo_Course"
        run_key = "Demo_Course"

        org = OrganizationFactory.create(key="test-org-key", display_name="test-org-display_name")
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(
            key="test-course-key",
            display_name="test-course-display_name",
            organization=org,
        )

        program_course_code = ProgramCourseCodeFactory.create(program=program, course_code=course_code)

        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
            start_date=start_date
        )

        response = self._make_request(program_id=program.id, admin=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.data,
            {
                'name': program.name,
                'subtitle': program.subtitle,
                'category': program.category,
                'status': ProgramStatus.UNPUBLISHED,
                'organizations': [
                    {
                        'key': 'test-org-key',
                        'display_name': 'test-org-display_name',
                    }
                ],
                'course_codes': [
                    {
                        'key': 'test-course-key',
                        'display_name': 'test-course-display_name',
                        'organization': {
                            'key': 'test-org-key',
                            'display_name': 'test-org-display_name',
                        },
                        'run_modes': [
                            {
                                'course_key': course_key,
                                'run_key': run_key,
                                'mode_slug': 'verified',
                                'sku': '',
                                'start_date': start_date.strftime(DRF_DATE_FORMAT)
                            }
                        ],
                    }
                ],
                'id': program.id,
                'created': program.created.strftime(DRF_DATE_FORMAT),
                'modified': program.modified.strftime(DRF_DATE_FORMAT),
                'marketing_slug': program.marketing_slug,
                'banner_image_urls': {},
                'uuid': unicode(program.uuid),
            }
        )
Esempio n. 10
0
    def test_view_with_nested(self):
        """
        Ensure that nested serializers are working in program detail views.
        """
        start_date = datetime.datetime.now(tz=pytz.UTC)
        course_key = "edX/DemoX/Demo_Course"
        run_key = "Demo_Course"

        org = OrganizationFactory.create(key="test-org-key", display_name="test-org-display_name")
        program = ProgramFactory.create()
        ProgramOrganizationFactory.create(program=program, organization=org)
        course_code = CourseCodeFactory.create(
            key="test-course-key",
            display_name="test-course-display_name",
            organization=org,
        )

        program_course_code = ProgramCourseCodeFactory.create(program=program, course_code=course_code)

        ProgramCourseRunModeFactory.create(
            course_key=course_key,
            program_course_code=program_course_code,
            start_date=start_date
        )

        response = self._make_request(program_id=program.id, admin=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.data,
            {
                u"name": program.name,
                u"subtitle": program.subtitle,
                u"category": program.category,
                u"status": ProgramStatus.UNPUBLISHED,
                u"organizations": [
                    {
                        u"key": "test-org-key",
                        u"display_name": "test-org-display_name",
                    }
                ],
                u"course_codes": [
                    {
                        u"key": "test-course-key",
                        u"display_name": "test-course-display_name",
                        u"organization": {
                            u"key": "test-org-key",
                            u"display_name": "test-org-display_name",
                        },
                        u"run_modes": [
                            {
                                u"course_key": course_key,
                                u"run_key": run_key,
                                u"mode_slug": "verified",
                                u"sku": '',
                                u"start_date": start_date.strftime(DRF_DATE_FORMAT)
                            }
                        ],
                    }
                ],
                u"id": program.id,
                u"created": program.created.strftime(DRF_DATE_FORMAT),
                u"modified": program.modified.strftime(DRF_DATE_FORMAT),
                u'marketing_slug': program.marketing_slug,
                u'banner_image_urls': {}
            }
        )