def test_list(self):
        """ Verify the endpoint returns a list of all subjects. """
        SubjectFactory.create_batch(8)
        expected = Subject.objects.all()

        with self.assertNumQueries(5):
            response = self.client.get(self.list_path)

        assert response.status_code == 200
        assert response.data['results'] == self.serialize_subject(expected,
                                                                  many=True)
Exemplo n.º 2
0
    def setUp(self):
        super(CreateCoursesTests, self).setUp()

        transcript_languages = LanguageTag.objects.all()[:2]
        self.subjects = SubjectFactory.create_batch(3)
        self.course = CourseFactory(subjects=self.subjects)

        self.command_name = 'import_metadata_courses'
        self.command_args = ['--start_id={}'.format(self.course.id), '--end_id={}'.format(self.course.id)]

        # create multiple course-runs against course.
        course_runs = CourseRunFactory.create_batch(
            3, course=self.course, transcript_languages=transcript_languages,
            language=transcript_languages[0],
            short_description_override='Testing description'
        )

        canonical_course_run = course_runs[0]
        for seat_type in ['honor', 'credit', 'verified']:  # to avoid same type seat creation.
            SeatFactory(course_run=canonical_course_run, type=seat_type)

        staff = PersonFactory.create_batch(2)
        canonical_course_run.staff.add(*staff)

        self.course.canonical_course_run = canonical_course_run
        self.course.save()

        # create org and assign to the course-metadata
        self.forganization_extension = factories.OrganizationExtensionFactory()
        self.organization = self.forganization_extension.organization
        self.course.authoring_organizations.add(self.organization)
    def test_retrieve(self):
        """ The request should return details for a single subject. """
        subject = SubjectFactory()
        url = reverse('api:v1:subject-detail', kwargs={'uuid': subject.uuid})

        with self.assertNumQueries(4):
            response = self.client.get(url)

        assert response.status_code == 200
        assert response.data == self.serialize_subject(subject)
Exemplo n.º 4
0
    def test_data(self):
        subject = SubjectFactory()
        serializer = SubjectSerializer(subject)

        expected = {
            'name': subject.name,
            'description': subject.description,
            'banner_image_url': subject.banner_image_url,
            'card_image_url': subject.card_image_url,
            'subtitle': subject.subtitle,
            'slug': subject.slug,
        }

        self.assertDictEqual(serializer.data, expected)
Exemplo n.º 5
0
    def test_options(self):
        # TODO: Remove draft=True and save lines below as part of DISCO-818
        self.course.draft = True
        self.course.save()

        SubjectFactory(name='Subject1')
        # TODO: Swap commented line with one below it when completing DISCO-818
        # CourseEntitlementFactory(course=self.course, mode=SeatType.objects.get(slug='verified'))
        CourseEntitlementFactory(course=self.course,
                                 mode=SeatType.objects.get(slug='verified'),
                                 draft=True)

        url = reverse('api:v1:course-detail', kwargs={'key': self.course.uuid})
        response = self.client.options(url)
        self.assertEqual(response.status_code, 200)

        data = response.data['actions']['PUT']
        self.assertEqual(data['level_type']['choices'],
                         [{
                             'display_name': self.course.level_type.name,
                             'value': self.course.level_type.name
                         }])
        self.assertEqual(
            data['entitlements']['child']['children']['mode']['choices'],
            [{
                'display_name': 'Audit',
                'value': 'audit'
            }, {
                'display_name': 'Credit',
                'value': 'credit'
            }, {
                'display_name': 'Professional',
                'value': 'professional'
            }, {
                'display_name': 'Verified',
                'value': 'verified'
            }])
        self.assertEqual(data['subjects']['child']['choices'],
                         [{
                             'display_name': 'Subject1',
                             'value': 'subject1'
                         }])
        self.assertFalse(
            'choices' in
            data['partner'])  # we don't whitelist partner to show its choices
    def test_options(self):
        SubjectFactory(name='Subject1')
        CourseEntitlementFactory(course=self.course,
                                 mode=SeatType.objects.get(slug='verified'))

        url = reverse('api:v1:course-detail', kwargs={'key': self.course.uuid})
        response = self.client.options(url)
        self.assertEqual(response.status_code, 200)

        data = response.data['actions']['PUT']
        self.assertEqual(data['level_type']['choices'],
                         [{
                             'display_name': self.course.level_type.name,
                             'value': self.course.level_type.name
                         }])
        self.assertEqual(
            data['entitlements']['child']['children']['mode']['choices'],
            [{
                'display_name': 'Audit',
                'value': 'audit'
            }, {
                'display_name': 'Credit',
                'value': 'credit'
            }, {
                'display_name': 'Professional',
                'value': 'professional'
            }, {
                'display_name': 'Verified',
                'value': 'verified'
            }])
        self.assertEqual(data['subjects']['child']['choices'],
                         [{
                             'display_name': 'Subject1',
                             'value': 'subject1'
                         }])
        self.assertFalse(
            'choices' in
            data['partner'])  # we don't whitelist partner to show its choices
Exemplo n.º 7
0
    def test_courses_with_subjects_and_negative_query(self):
        catalog = CatalogFactory(
            # pylint: disable=line-too-long
            query=
            'subjects:(-"Business & Management" AND -"Economics & Finance" AND -"Data Analysis & Statistics" AND -"Math"  AND -"Engineering") AND org:(-galileox AND -davidsonnext AND -microsoft AND -gtx AND -pekingx AND -asux AND -bux AND -columbiax)'
        )
        Course.objects.all().delete()
        not_included_subject_names = (
            'Business & Management',
            'Economics & Finance',
            'Business & Management',
            'Economics & Finance',
            'Data Analysis & Statistics',
            'math',
            'Engineering',
        )
        for name in not_included_subject_names:
            course_run = CourseRunFactory(
                start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
                status=CourseRunStatus.Published,
                type__is_marketable=True,
                course__subjects=[SubjectFactory(name=name)],
            )
            SeatFactory.create(course_run=course_run)

        included_subject_names = ('Health & Sport', 'Galaxy')
        desired_courses = []
        for name in included_subject_names:
            course_run = CourseRunFactory(
                start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
                status=CourseRunStatus.Published,
                type__is_marketable=True,
                course__subjects=[SubjectFactory(name=name)],
            )
            SeatFactory.create(course_run=course_run)
            desired_courses.append(course_run.course)

        not_included_org_names = ('galileox', 'davidsonnext', 'microsoft',
                                  'gtx', 'pekingx', 'asux', 'bux', 'ColumbiaX')
        for name in not_included_org_names:
            course_run = CourseRunFactory(
                start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
                status=CourseRunStatus.Published,
                type__is_marketable=True,
                key=
                f'{name}/{factory.Faker("word").evaluate(None, None, {"locale":"en"})}/test',
            )
            SeatFactory.create(course_run=course_run)

        included_org_names = ('apple', 'cisco')
        for name in included_org_names:
            course_run = CourseRunFactory(
                start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
                status=CourseRunStatus.Published,
                type__is_marketable=True,
                key=
                f'{name}/{factory.Faker("word").evaluate(None, None, {"locale":"en"})}/test',
            )
            SeatFactory.create(course_run=course_run)
            desired_courses.append(course_run.course)

        call_command('search_index', '--rebuild', '-f')
        url = reverse('api:v1:catalog-courses', kwargs={'id': catalog.id})
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.data['results'] == self.serialize_catalog_course(
            desired_courses, many=True)
 def test_to_internal_value(self):
     subject = SubjectFactory(name='Subject')  # 'name' is a translated field on Subject
     serializer = SlugRelatedTranslatableField(slug_field='name', queryset=Subject.objects.all())
     self.assertEqual(serializer.to_internal_value('Subject'), subject)