Exemplo n.º 1
0
    def upload(self, generated_images):
        """
        Upload auto generated images to S3.
        """
        if self.settings['onsite_worker'] is True:
            s3_connection = S3Connection(
                self.settings['edx_access_key_id'],
                self.settings['edx_secret_access_key'])
        else:
            s3_connection = S3Connection()

        try:
            bucket = s3_connection.get_bucket(
                self.settings['aws_video_images_bucket'])
        except S3ResponseError:
            logger.error(': Invalid Storage Bucket for Video Images')
            return

        image_keys = []
        for generated_image in generated_images:
            upload_key = Key(bucket)
            upload_key.key = build_url(
                self.settings['instance_prefix'],
                self.settings['aws_video_images_prefix'],
                os.path.basename(generated_image))
            # image path is stored in edxval without `instance_prefix`
            image_keys.append(
                build_url(self.settings['aws_video_images_prefix'],
                          os.path.basename(generated_image)))
            upload_key.set_contents_from_filename(generated_image)
            upload_key.set_acl('public-read')

        return image_keys
Exemplo n.º 2
0
    def test_build_url(self, urls, params, expected_url):
        """
        Tests that utils.build_url works as expected.
        """
        url = utils.build_url(*urls, **params)

        generated_url_object = six.moves.urllib.parse.urlparse(url)
        generated_query_params = generated_url_object.query

        generated_query_netloc = generated_url_object.netloc
        generated_query_path = generated_url_object.path

        generated_query_params = six.moves.urllib.parse.parse_qsl(
            generated_query_params)
        generated_query_params = sorted(generated_query_params)

        expected_url_object = six.moves.urllib.parse.urlparse(expected_url)
        expected_query_params = expected_url_object.query

        expected_query_netloc = expected_url_object.netloc
        expected_query_path = expected_url_object.path

        expected_query_params = six.moves.urllib.parse.parse_qsl(
            expected_query_params)
        expected_query_params = sorted(expected_query_params)

        self.assertEqual(generated_query_params, expected_query_params)

        self.assertEqual(generated_query_netloc, expected_query_netloc)

        self.assertEqual(generated_query_path, expected_query_path)
Exemplo n.º 3
0
 def test_build_url(self, urls, params, expected_url):
     """
     Tests that utils.build_url works as expected.
     """
     url = utils.build_url(*urls, **params)
     self.assertEqual(url, expected_url)