예제 #1
0
    def setUp(self):
        super().setUp()
        self.user = UserFactory()
        self.client.force_authenticate(self.user)
        self.catalog = CatalogFactory(query='*:*', program_query='*:*', viewers=[self.user])

        self.enrollment_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30)
        self.course_end = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=60)
        self.course_run = CourseRunFactory(enrollment_end=self.enrollment_end, end=self.course_end)
        self.course = self.course_run.course

        # Generate test programs
        self.test_image = make_image_file('test_banner.jpg')
        self.masters_program_type = ProgramType.objects.get(slug=ProgramType.MASTERS)
        self.microbachelors_program_type = ProgramType.objects.get(slug=ProgramType.MICROBACHELORS)
        self.ms_program = ProgramFactory(
            type=self.masters_program_type,
            courses=[self.course],
            banner_image=self.test_image,
        )
        self.program = ProgramFactory(
            type=self.microbachelors_program_type,
            courses=[self.course],
            banner_image=self.test_image,
        )

        self.affiliate_url = reverse('api:v1:partners:programs_affiliate_window-detail', kwargs={'pk': self.catalog.id})
예제 #2
0
    def setUp(self):
        super(CourseStateTests, self).setUp()

        self.course = self.course_state.course
        self.course.image = make_image_file('test_banner.jpg')
        self.course.save()

        self.course.organizations.add(factories.OrganizationExtensionFactory().organization)
예제 #3
0
    def test_course_image(self):
        """ Verify that the wrapper return the url fo thumbnail course image if exists. """
        self.assertIsNone(self.wrapped_course_run.course_image)

        self.course.image = make_image_file('test_banner1.jpg')
        self.course.save()

        self.assertEqual(self.wrapped_course_run.course_image,
                         self.course.image.thumbnail.url)
예제 #4
0
 def _create_course_run_for_publication(self):
     organization = OrganizationFactory()
     transcript_languages = [LanguageTag.objects.first()]
     mock_image_file = make_image_file('test_image.jpg')
     return CourseRunFactory(course__organizations=[organization],
                             course__tertiary_subject=None,
                             course__image__from_file=mock_image_file,
                             lms_course_id='a/b/c',
                             transcript_languages=transcript_languages,
                             staff=PersonFactory.create_batch(2))
예제 #5
0
 def test_banner_image(self):
     self.program.banner_image = make_image_file('test_banner.jpg')
     self.program.save()
     image_url_prefix = '{}media/programs/banner_images/'.format(settings.MEDIA_URL)
     self.assertIn(image_url_prefix, self.program.banner_image.url)
     for size_key in self.program.banner_image.field.variations:
         # Get different sizes specs from the model field
         # Then get the file path from the available files
         sized_file = getattr(self.program.banner_image, size_key, None)
         self.assertIsNotNone(sized_file)
         self.assertIn(image_url_prefix, sized_file.url)
예제 #6
0
 def test_to_representation(self):
     request = make_request()
     program = ProgramFactory(banner_image=make_image_file('test.jpg'))
     field = StdImageSerializerField()
     field._context = {'request': request}  # pylint: disable=protected-access
     expected = {
         size_key: {
             'url': '{}{}'.format('http://testserver', getattr(program.banner_image, size_key).url),
             'width': program.banner_image.field.variations[size_key]['width'],  # pylint: disable=no-member
             'height': program.banner_image.field.variations[size_key]['height']  # pylint: disable=no-member
         } for size_key in program.banner_image.field.variations}  # pylint: disable=no-member
     assert field.to_representation(program.banner_image) == expected
예제 #7
0
 def test_banner_image(self):
     self.program.banner_image = make_image_file('test_banner.jpg')
     self.program.save()
     image_url_prefix = '{}media/programs/banner_images/'.format(
         settings.MEDIA_URL)
     self.assertIn(image_url_prefix, self.program.banner_image.url)
     for size_key in self.program.banner_image.field.variations:
         # Get different sizes specs from the model field
         # Then get the file path from the available files
         sized_file = getattr(self.program.banner_image, size_key, None)
         self.assertIsNotNone(sized_file)
         self.assertIn(image_url_prefix, sized_file.url)
예제 #8
0
    def test_update(self):
        """
        Verify that we can update course workflow state with serializer.
        """
        course = self.course_state.course
        course.image = make_image_file('test_banner.jpg')
        course.save()
        course.organizations.add(OrganizationExtensionFactory().organization)

        self.assertNotEqual(self.course_state, CourseStateChoices.Review)
        serializer = self.serializer_class(self.course_state, context={'request': self.request})
        data = {'name': CourseStateChoices.Review}
        serializer.update(self.course_state, data)

        self.course_state = CourseState.objects.get(course=self.course_state.course)
        self.assertEqual(self.course_state.name, CourseStateChoices.Review)
        self.assertEqual(self.course_state.owner_role, PublisherUserRole.MarketingReviewer)
예제 #9
0
    def setUp(self):
        super(ChangeCourseStateViewTests, self).setUp()
        self.course_state = factories.CourseStateFactory(name=CourseStateChoices.Draft)
        self.user = UserFactory()
        self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))

        self.course = self.course_state.course
        self.course.image = make_image_file('test_banner.jpg')
        self.course.save()

        self.organization_extension = factories.OrganizationExtensionFactory()
        self.course.organizations.add(self.organization_extension.organization)
        factories.UserAttributeFactory(user=self.user, enable_email_notification=True)
        toggle_switch('enable_publisher_email_notifications', True)

        self.change_state_url = reverse('publisher:api:change_course_state', kwargs={'pk': self.course_state.id})

        self.client.login(username=self.user.username, password=USER_PASSWORD)
예제 #10
0
    def create_program(self):
        organizations = [OrganizationFactory()]
        person = PersonFactory()

        course = CourseFactory()
        CourseRunFactory(course=course, staff=[person])

        program = ProgramFactory(
            courses=[course],
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory()
        )
        return program
예제 #11
0
    def test_program_activation_restrictions(self, booleans, label):
        """Verify that program activation requires both a marketing slug and a banner image."""
        has_banner_image, can_be_activated = booleans
        status = getattr(ProgramStatus, label)

        banner_image = make_image_file('test_banner.jpg') if has_banner_image else ''

        data = self._post_data(status=status, marketing_slug='/foo')
        files = {'banner_image': banner_image}

        if status == ProgramStatus.Active:
            if can_be_activated:
                # Transitioning to an active status should require a marketing slug and banner image.
                self.assert_form_valid(data, files)
            else:
                self.assert_form_invalid(data, files)
        else:
            # All other status transitions should be valid regardless of marketing slug and banner image.
            self.assert_form_valid(data, files)
예제 #12
0
    def create_program(self):
        organizations = [OrganizationFactory()]
        person = PersonFactory()

        course = CourseFactory()
        CourseRunFactory(course=course, staff=[person])

        program = ProgramFactory(
            courses=[course],
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(
                1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory())
        return program
예제 #13
0
    def create_program(self):
        organizations = OrganizationFactory.create_batch(2)
        person = PersonFactory()

        courses = CourseFactory.create_batch(3)
        for course in courses:
            CourseRunFactory.create_batch(2, course=course, staff=[person], start=datetime.now())

        return ProgramFactory(
            courses=courses,
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory(),
            order_courses_by_start_date=False,
        )
예제 #14
0
    def test_program_activation_restrictions(self, booleans, label):
        """Verify that program activation requires both a marketing slug and a banner image."""
        has_marketing_slug, has_banner_image, can_be_activated = booleans
        status = getattr(ProgramStatus, label)

        marketing_slug = '/foo' if has_marketing_slug else ''
        banner_image = make_image_file('test_banner.jpg') if has_banner_image else ''

        data = self._post_data(status=status, marketing_slug=marketing_slug)
        files = {'banner_image': banner_image}

        if status == ProgramStatus.Active:
            if can_be_activated:
                # Transitioning to an active status should require a marketing slug and banner image.
                self.assert_form_valid(data, files)
            else:
                self.assert_form_invalid(data, files)
        else:
            # All other status transitions should be valid regardless of marketing slug and banner image.
            self.assert_form_valid(data, files)
예제 #15
0
    def test_course_image_url(self):
        """ Verify that the property returns the course image url. """
        self.assertIsNone(self.course.course_image_url)

        # Create a published course-run with card_image_url.
        course_run = factories.CourseRunFactory(course=self.course)
        factories.CourseRunStateFactory(course_run=course_run,
                                        name=CourseRunStateChoices.Published)
        course_run.card_image_url = 'http://example.com/test.jpg'
        course_run.save()

        # Verify that property returns card_image_url of course-run.
        self.assertEqual(self.course.course_image_url,
                         course_run.card_image_url)

        # Create a course image.
        self.course.image = make_image_file('test_banner1.jpg')
        self.course.save()

        # Verify that property returns course image field url.
        self.assertEqual(self.course.course_image_url, self.course.image.url)
예제 #16
0
    def create_program(self, courses=None):
        organizations = [OrganizationFactory(partner=self.partner)]
        person = PersonFactory()

        if courses is None:
            courses = [CourseFactory(partner=self.partner)]
            CourseRunFactory(course=courses[0], staff=[person])

        program = ProgramFactory(
            courses=courses,
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(
                1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            instructor_ordering=PersonFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory(),
            partner=self.partner)
        return program
예제 #17
0
    def test_to_representation(self):
        request = make_request()
        # TODO Create test-only model to avoid unnecessary dependency on Program model.
        program = ProgramFactory(banner_image=make_image_file('test.jpg'))
        field = StdImageSerializerField()
        field._context = {'request': request}  # pylint: disable=protected-access

        expected = {
            size_key: {
                'url':
                '{}{}'.format('http://testserver',
                              getattr(program.banner_image, size_key).url),
                'width':
                program.banner_image.field.variations[size_key]['width'],
                'height':
                program.banner_image.field.variations[size_key]['height']
            }
            for size_key in program.banner_image.field.variations
        }

        self.assertDictEqual(field.to_representation(program.banner_image),
                             expected)
    def setUp(self):
        super(CreateCoursesTests, self).setUp()

        transcript_languages = LanguageTag.objects.all()[:2]
        self.subjects = SubjectFactory.create_batch(3)
        self.test_image = make_image_file('testimage.jpg')
        self.course = CourseFactory(subjects=self.subjects,
                                    image__from_file=self.test_image)

        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)
예제 #19
0
    def create_program(self):
        organizations = OrganizationFactory.create_batch(2)
        person = PersonFactory()

        courses = CourseFactory.create_batch(3)
        for course in courses:
            CourseRunFactory.create_batch(2,
                                          course=course,
                                          staff=[person],
                                          start=datetime.now())

        return ProgramFactory(
            courses=courses,
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(
                1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory(),
            order_courses_by_start_date=False,
        )