Esempio n. 1
0
    def test_video_image(self):
        """
        Test video image is saved.
        """
        edx_video_id = 'test1'
        video_image_upload_url = self.get_url_for_course_key(
            self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
                dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH,
                            settings.VIDEO_IMAGE_MIN_HEIGHT), ) as image_file:
            response = self.client.post(video_image_upload_url,
                                        {'file': image_file},
                                        format='multipart')
            image_url1 = self.verify_image_upload_reponse(
                self.course.id, edx_video_id, response)

        # upload again to verify that new image is uploaded successfully
        with make_image_file(
                dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH,
                            settings.VIDEO_IMAGE_MIN_HEIGHT), ) as image_file:
            response = self.client.post(video_image_upload_url,
                                        {'file': image_file},
                                        format='multipart')
            image_url2 = self.verify_image_upload_reponse(
                self.course.id, edx_video_id, response)

        self.assertNotEqual(image_url1, image_url2)
Esempio n. 2
0
    def test_video_image_validation_message(self, image_data, error_message):
        """
        Test video image validation gives proper error message.

        Arguments:
            image_data (Dict): Specific data to create image file.
            error_message (String): Error message
        """
        edx_video_id = 'test1'
        video_image_upload_url = self.get_url_for_course_key(
            self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
                dimensions=(image_data.get('width',
                                           settings.VIDEO_IMAGE_MIN_WIDTH),
                            image_data.get('height',
                                           settings.VIDEO_IMAGE_MIN_HEIGHT)),
                prefix=image_data.get('prefix', 'videoimage'),
                extension=image_data.get('extension', '.png'),
                force_size=image_data.get(
                    'size',
                    settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'])
        ) as image_file:
            response = self.client.post(video_image_upload_url,
                                        {'file': image_file},
                                        format='multipart')
            if error_message:
                self.verify_error_message(response, error_message)
            else:
                self.verify_image_upload_reponse(self.course.id, edx_video_id,
                                                 response)
Esempio n. 3
0
    def setUp(self):
        super(ScrapeVideoThumbnailsTestCase, self).setUp()
        course_ids = [unicode(self.course.id)]
        profiles = ['youtube']
        created = datetime.now(pytz.utc)
        previous_uploads = [
            {
                'edx_video_id': 'test1',
                'client_video_id': 'test1.mp4',
                'duration': 42.0,
                'status': 'upload',
                'courses': course_ids,
                'encoded_videos': [],
                'created': created
            },
            {
                'edx_video_id': 'test-youtube-video-1',
                'client_video_id': 'test-youtube-id.mp4',
                'duration': 128.0,
                'status': 'file_complete',
                'courses': course_ids,
                'created': created,
                'encoded_videos': [
                    {
                        'profile': 'youtube',
                        'url': '3_yD_cEKoCk',
                        'file_size': 1600,
                        'bitrate': 100,
                    }
                ],
            },
            {
                'edx_video_id': 'test-youtube-video-2',
                'client_video_id': 'test-youtube-id.mp4',
                'image': 'image2.jpg',
                'duration': 128.0,
                'status': 'file_complete',
                'courses': course_ids,
                'created': created,
                'encoded_videos': [
                    {
                        'profile': 'youtube',
                        'url': '3_yD_cEKoCk',
                        'file_size': 1600,
                        'bitrate': 100,
                    }
                ],
            },
        ]
        for profile in profiles:
            create_profile(profile)

        for video in previous_uploads:
            create_video(video)

        # Create video images.
        with make_image_file() as image_file:
            update_video_image(
                'test-youtube-video-2', unicode(self.course.id), image_file, 'image.jpg'
            )
    def setUp(self):
        super(ScrapeVideoThumbnailsTestCase, self).setUp()
        course_ids = [unicode(self.course.id)]
        profiles = ['youtube']
        created = datetime.now(pytz.utc)
        previous_uploads = [
            {
                'edx_video_id': 'test1',
                'client_video_id': 'test1.mp4',
                'duration': 42.0,
                'status': 'upload',
                'courses': course_ids,
                'encoded_videos': [],
                'created': created
            },
            {
                'edx_video_id': 'test-youtube-video-1',
                'client_video_id': 'test-youtube-id.mp4',
                'duration': 128.0,
                'status': 'file_complete',
                'courses': course_ids,
                'created': created,
                'encoded_videos': [
                    {
                        'profile': 'youtube',
                        'url': '3_yD_cEKoCk',
                        'file_size': 1600,
                        'bitrate': 100,
                    }
                ],
            },
            {
                'edx_video_id': 'test-youtube-video-2',
                'client_video_id': 'test-youtube-id.mp4',
                'image': 'image2.jpg',
                'duration': 128.0,
                'status': 'file_complete',
                'courses': course_ids,
                'created': created,
                'encoded_videos': [
                    {
                        'profile': 'youtube',
                        'url': '3_yD_cEKoCk',
                        'file_size': 1600,
                        'bitrate': 100,
                    }
                ],
            },
        ]
        for profile in profiles:
            create_profile(profile)

        for video in previous_uploads:
            create_video(video)

        # Create video images.
        with make_image_file() as image_file:
            update_video_image(
                'test-youtube-video-2', unicode(self.course.id), image_file, 'image.jpg'
            )
Esempio n. 5
0
    def test_no_video_image(self):
        """
        Test image url is set to None if no video image.
        """
        edx_video_id = 'test1'
        get_videos_url = reverse_course_url('videos_handler', self.course.id)
        video_image_upload_url = self.get_url_for_course_key(
            self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
                dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH,
                            settings.VIDEO_IMAGE_MIN_HEIGHT), ) as image_file:
            self.client.post(video_image_upload_url, {'file': image_file},
                             format='multipart')

        val_image_url = get_course_video_image_url(course_id=self.course.id,
                                                   edx_video_id=edx_video_id)

        response = self.client.get_json(get_videos_url)
        self.assertEqual(response.status_code, 200)
        response_videos = json.loads(response.content)["videos"]
        for response_video in response_videos:
            if response_video['edx_video_id'] == edx_video_id:
                self.assertEqual(response_video['course_video_image_url'],
                                 val_image_url)
            else:
                self.assertEqual(response_video['course_video_image_url'],
                                 None)
Esempio n. 6
0
 def create_profile_image(self, user, storage):
     """
     Creates profile image for user and checks that created image exists in storage
     """
     with make_image_file() as image_file:
         create_profile_images(image_file, get_profile_image_names(user.username))
         self.check_images(user, storage)
         set_has_profile_image(user.username, True, self.TEST_PROFILE_IMAGE_UPLOADED_AT)
Esempio n. 7
0
 def create_profile_image(self, user, storage):
     """
     Creates profile image for user and checks that created image exists in storage
     """
     with make_image_file() as image_file:
         create_profile_images(image_file, get_profile_image_names(user.username))
         self.check_images(user, storage)
         set_has_profile_image(user.username, True, self.TEST_PROFILE_IMAGE_UPLOADED_AT)
Esempio n. 8
0
    def test_video_image(self):
        """
        Test video image is saved.
        """
        edx_video_id = 'test1'
        video_image_upload_url = self.get_url_for_course_key(self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
            dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH, settings.VIDEO_IMAGE_MIN_HEIGHT),
        ) as image_file:
            response = self.client.post(video_image_upload_url, {'file': image_file}, format='multipart')
            image_url1 = self.verify_image_upload_reponse(self.course.id, edx_video_id, response)

        # upload again to verify that new image is uploaded successfully
        with make_image_file(
            dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH, settings.VIDEO_IMAGE_MIN_HEIGHT),
        ) as image_file:
            response = self.client.post(video_image_upload_url, {'file': image_file}, format='multipart')
            image_url2 = self.verify_image_upload_reponse(self.course.id, edx_video_id, response)

        self.assertNotEqual(image_url1, image_url2)
Esempio n. 9
0
    def test_get_user_info_cookie_data(self):
        with make_image_file() as image_file:
            create_profile_images(image_file,
                                  get_profile_image_names(self.user.username))
            self.user.profile.profile_image_uploaded_at = date.today()
            self.user.profile.save()

        actual = cookies_api._get_user_info_cookie_data(
            self.request, self.user)  # pylint: disable=protected-access

        expected = {
            'version': settings.EDXMKTG_USER_INFO_COOKIE_VERSION,
            'username': self.user.username,
            'header_urls': self._get_expected_header_urls(),
            'user_image_urls': self._get_expected_image_urls(),
        }

        self.assertDictEqual(actual, expected)
Esempio n. 10
0
    def test_transcript_upload_handler_with_image(self):
        """
        Tests the transcript upload handler with an image file.
        """
        with make_image_file() as image_file:
            # Make request to transcript upload handler
            response = self.client.post(self.view_url, {
                'edx_video_id': '123',
                'language_code': 'en',
                'new_language_code': 'es',
                'file': image_file,
            },
                                        format='multipart')

            self.assertEqual(response.status_code, 400)
            self.assertEqual(
                json.loads(response.content)['error'],
                u'There is a problem with this transcript file. Try to upload a different file.'
            )
Esempio n. 11
0
    def test_no_video_image(self):
        """
        Test image url is set to None if no video image.
        """
        edx_video_id = 'test1'
        get_videos_url = reverse_course_url('videos_handler', self.course.id)
        video_image_upload_url = self.get_url_for_course_key(self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
            dimensions=(settings.VIDEO_IMAGE_MIN_WIDTH, settings.VIDEO_IMAGE_MIN_HEIGHT),
        ) as image_file:
            self.client.post(video_image_upload_url, {'file': image_file}, format='multipart')

        val_image_url = get_course_video_image_url(course_id=self.course.id, edx_video_id=edx_video_id)

        response = self.client.get_json(get_videos_url)
        self.assertEqual(response.status_code, 200)
        response_videos = json.loads(response.content)["videos"]
        for response_video in response_videos:
            if response_video['edx_video_id'] == edx_video_id:
                self.assertEqual(response_video['course_video_image_url'], val_image_url)
            else:
                self.assertEqual(response_video['course_video_image_url'], None)
    def test_transcript_upload_handler_with_image(self):
        """
        Tests the transcript upload handler with an image file.
        """
        with make_image_file() as image_file:
            # Make request to transcript upload handler
            response = self.client.post(
                self.view_url,
                {
                    'edx_video_id': '123',
                    'language_code': 'en',
                    'new_language_code': 'es',
                    'file': image_file,
                },
                format='multipart'
            )

            self.assertEqual(response.status_code, 400)
            self.assertEqual(
                json.loads(response.content)['error'],
                u'There is a problem with this transcript file. Try to upload a different file.'
            )
Esempio n. 13
0
    def mocked_youtube_thumbnail_response(
        self,
        mocked_content=None,
        error_response=False,
        image_width=settings.VIDEO_IMAGE_MIN_WIDTH,
        image_height=settings.VIDEO_IMAGE_MIN_HEIGHT
    ):
        """
        Returns a mocked youtube thumbnail response.
        """
        image_content = ''
        with make_image_file(dimensions=(image_width, image_height), ) as image_file:
            image_content = image_file.read()

        if mocked_content or error_response:
            image_content = mocked_content

        mocked_response = requests.Response()
        mocked_response.status_code = requests.codes.ok if image_content else requests.codes.not_found  # pylint: disable=no-member
        mocked_response._content = image_content    # pylint: disable=protected-access
        mocked_response.headers = {'content-type': 'image/jpeg'}
        return mocked_response
Esempio n. 14
0
    def mocked_youtube_thumbnail_response(
            self,
            mocked_content=None,
            error_response=False,
            image_width=settings.VIDEO_IMAGE_MIN_WIDTH,
            image_height=settings.VIDEO_IMAGE_MIN_HEIGHT):
        """
        Returns a mocked youtube thumbnail response.
        """
        image_content = ''
        with make_image_file(dimensions=(image_width,
                                         image_height), ) as image_file:
            image_content = image_file.read()

        if mocked_content or error_response:
            image_content = mocked_content

        mocked_response = requests.Response()
        mocked_response.status_code = requests.codes.ok if image_content else requests.codes.not_found  # pylint: disable=no-member
        mocked_response._content = image_content  # pylint: disable=protected-access
        mocked_response.headers = {'content-type': 'image/jpeg'}
        return mocked_response
Esempio n. 15
0
    def test_video_image_validation_message(self, image_data, error_message):
        """
        Test video image validation gives proper error message.

        Arguments:
            image_data (Dict): Specific data to create image file.
            error_message (String): Error message
        """
        edx_video_id = 'test1'
        video_image_upload_url = self.get_url_for_course_key(self.course.id, {'edx_video_id': edx_video_id})
        with make_image_file(
            dimensions=(
                image_data.get('width', settings.VIDEO_IMAGE_MIN_WIDTH),
                image_data.get('height', settings.VIDEO_IMAGE_MIN_HEIGHT)
            ),
            prefix=image_data.get('prefix', 'videoimage'),
            extension=image_data.get('extension', '.png'),
            force_size=image_data.get('size', settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MIN_BYTES'])
        ) as image_file:
            response = self.client.post(video_image_upload_url, {'file': image_file}, format='multipart')
            if error_message:
                self.verify_error_message(response, error_message)
            else:
                self.verify_image_upload_reponse(self.course.id, edx_video_id, response)
    def handle(self, *args, **options):
        """
        Execute the command.
        """

        username = options['username'] if options['username'] else 'gdpr_test_user'
        email = options['email'] if options['email'] else '*****@*****.**'
        course_uuid = options['course'] if options['course'] else uuid4().hex

        user, __ = User.objects.get_or_create(
            username=username,
            email=email
        )
        user_info = {
            'email': email,
            'first_name': "GDPR",
            'last_name': "Test",
            'is_active': True
        }
        for field, value in user_info.items():
            setattr(user, field, value)
        user.set_password('gdpr test password')
        user.save()

        # UserProfile
        profile_image_uploaded_date = datetime(2018, 5, 3, tzinfo=UTC)
        user_profile, __ = UserProfile.objects.get_or_create(
            user=user
        )
        user_profile_info = {
            'name': 'gdpr test name',
            'meta': '{}',
            'location': 'gdpr test location',
            'year_of_birth': 1950,
            'gender': 'gdpr test gender',
            'mailing_address': 'gdpr test mailing address',
            'city': 'Boston',
            'country': 'US',
            'bio': 'gdpr test bio',
            'profile_image_uploaded_at': profile_image_uploaded_date
        }
        for field, value in user_profile_info.items():
            setattr(user_profile, field, value)
        user_profile.save()

        # Profile images
        with make_image_file() as image_file:
            create_profile_images(
                image_file,
                {10: "ten.jpg"}
            )

        # DataSharingConsent
        enterprise_customer, __ = EnterpriseCustomer.objects.get_or_create(  # pylint: disable=no-member
            name='test gdpr enterprise customer',
            active=True,
            branding_configuration=None,
            catalog=None,
            enable_audit_enrollment=False,
            enable_data_sharing_consent=False,
            enforce_data_sharing_consent='at_enrollment',
            replace_sensitive_sso_username=True,
            site_id=1
        )

        DataSharingConsent.objects.get_or_create(
            username=username,
            enterprise_customer_id=enterprise_customer.uuid
        )

        # Sapsf data transmission
        enterprise_customer_user, __ = EnterpriseCustomerUser.objects.get_or_create(
            user_id=user.id,
            enterprise_customer_id=enterprise_customer.uuid
        )
        audit, __ = EnterpriseCourseEnrollment.objects.get_or_create(
            enterprise_customer_user=enterprise_customer_user
        )
        SapSuccessFactorsLearnerDataTransmissionAudit.objects.get_or_create(
            enterprise_course_enrollment_id=audit.id,
            completed_timestamp=10
        )

        # PendingEnterpriseCustomerUser
        PendingEnterpriseCustomerUser.objects.get_or_create(
            user_email=user.email,
            enterprise_customer_id=enterprise_customer.uuid
        )

        # EntitlementSupportDetail
        course_entitlement, __ = CourseEntitlement.objects.get_or_create(
            user_id=user.id,
            course_uuid=course_uuid
        )
        CourseEntitlementSupportDetail.objects.get_or_create(
            support_user=user,
            comments='test comments',
            entitlement_id=course_entitlement.id
        )

        # Misc. models that may contain PII of this user
        SoftwareSecurePhotoVerification.objects.get_or_create(
            user=user,
            name='gdpr test',
            face_image_url='https://fake_image_url.com',
            photo_id_image_url='gdpr_test',
            photo_id_key='gdpr_test'
        )
        PendingEmailChange.objects.get_or_create(
            user=user,
            activation_key=uuid4().hex
        )
        UserOrgTag.objects.get_or_create(
            user=user
        )

        course_id = CourseKey.from_string("course-v1:edX+DemoX+Demo_Course")
        # Objects linked to the user via their original email
        CourseEnrollmentAllowed.objects.get_or_create(
            email=user.email
        )
        course_user_group, __ = CourseUserGroup.objects.get_or_create(
            name='test course user group',
            course_id=course_id
        )
        UnregisteredLearnerCohortAssignments.objects.get_or_create(
            email=user.email,
            course_user_group_id=course_user_group.id
        )

        # Enroll the user in a course
        CourseEnrollment.objects.get_or_create(
            course_id=course_id,
            user_id=user.id,
        )
    def handle(self, *args, **options):
        """
        Execute the command.
        """

        username = options['username'] if options[
            'username'] else 'gdpr_test_user'
        email = options['email'] if options[
            'email'] else '*****@*****.**'
        course_uuid = options['course'] if options['course'] else uuid4().hex

        user, __ = User.objects.get_or_create(username=username, email=email)
        user_info = {
            'email': email,
            'first_name': "GDPR",
            'last_name': "Test",
            'is_active': True
        }
        for field, value in user_info.items():
            setattr(user, field, value)
        user.set_password('gdpr test password')
        user.save()

        # UserProfile
        profile_image_uploaded_date = datetime(2018, 5, 3, tzinfo=UTC)
        user_profile, __ = UserProfile.objects.get_or_create(user=user)
        user_profile_info = {
            'name': 'gdpr test name',
            'meta': '{}',
            'location': 'gdpr test location',
            'year_of_birth': 1950,
            'gender': 'gdpr test gender',
            'mailing_address': 'gdpr test mailing address',
            'city': 'Boston',
            'country': 'US',
            'bio': 'gdpr test bio',
            'profile_image_uploaded_at': profile_image_uploaded_date
        }
        for field, value in user_profile_info.items():
            setattr(user_profile, field, value)
        user_profile.save()

        # Profile images
        with make_image_file() as image_file:
            create_profile_images(image_file, {10: "ten.jpg"})

        # DataSharingConsent
        enterprise_customer, __ = EnterpriseCustomer.objects.get_or_create(  # pylint: disable=no-member
            name='test gdpr enterprise customer',
            active=True,
            branding_configuration=None,
            catalog=None,
            enable_audit_enrollment=False,
            enable_data_sharing_consent=False,
            enforce_data_sharing_consent='at_enrollment',
            replace_sensitive_sso_username=True,
            site_id=1)

        DataSharingConsent.objects.get_or_create(
            username=username, enterprise_customer_id=enterprise_customer.uuid)

        # Sapsf data transmission
        enterprise_customer_user, __ = EnterpriseCustomerUser.objects.get_or_create(
            user_id=user.id, enterprise_customer_id=enterprise_customer.uuid)
        audit, __ = EnterpriseCourseEnrollment.objects.get_or_create(
            enterprise_customer_user=enterprise_customer_user)
        SapSuccessFactorsLearnerDataTransmissionAudit.objects.get_or_create(
            enterprise_course_enrollment_id=audit.id, completed_timestamp=10)

        # PendingEnterpriseCustomerUser
        PendingEnterpriseCustomerUser.objects.get_or_create(
            user_email=user.email,
            enterprise_customer_id=enterprise_customer.uuid)

        # EntitlementSupportDetail
        course_entitlement, __ = CourseEntitlement.objects.get_or_create(
            user_id=user.id, course_uuid=course_uuid)
        CourseEntitlementSupportDetail.objects.get_or_create(
            support_user=user,
            comments='test comments',
            entitlement_id=course_entitlement.id)

        # Misc. models that may contain PII of this user
        SoftwareSecurePhotoVerification.objects.get_or_create(
            user=user,
            name='gdpr test',
            face_image_url='https://fake_image_url.com',
            photo_id_image_url='gdpr_test',
            photo_id_key='gdpr_test')
        PendingEmailChange.objects.get_or_create(user=user,
                                                 activation_key=uuid4().hex)
        UserOrgTag.objects.get_or_create(user=user)

        course_id = CourseKey.from_string("course-v1:edX+DemoX+Demo_Course")
        # Objects linked to the user via their original email
        CourseEnrollmentAllowed.objects.get_or_create(email=user.email)
        course_user_group, __ = CourseUserGroup.objects.get_or_create(
            name='test course user group', course_id=course_id)
        UnregisteredLearnerCohortAssignments.objects.get_or_create(
            email=user.email, course_user_group_id=course_user_group.id)

        # Enroll the user in a course
        CourseEnrollment.objects.get_or_create(
            course_id=course_id,
            user_id=user.id,
        )