Configurations for filesystem and s3 backends.

TNL-1789
This commit is contained in:
Daniel Friedman
2015-03-24 12:01:21 -04:00
committed by Andy Armstrong
parent 44c78c609c
commit 23f02d9492
8 changed files with 48 additions and 24 deletions

View File

@@ -27,8 +27,9 @@ def get_profile_image_storage():
Configures and returns a django Storage instance that can be used
to physically locate, read and write profile images.
"""
storage_class = get_storage_class(settings.PROFILE_IMAGE_BACKEND)
return storage_class(base_url=(settings.PROFILE_IMAGE_DOMAIN + settings.PROFILE_IMAGE_URL_PATH))
config = settings.PROFILE_IMAGE_BACKEND
storage_class = get_storage_class(config['class'])
return storage_class(**config['options'])
def _make_profile_image_name(username):
@@ -75,7 +76,7 @@ def get_profile_image_urls_for_user(user):
callers will use `_get_default_profile_image_urls` instead to provide
a set of urls that point to placeholder images, when there are no user-
submitted images.
- based on the value of django.conf.settings.PROFILE_IMAGE_DOMAIN,
- based on the value of django.conf.settings.PROFILE_IMAGE_BACKEND,
the URL may be relative, and in that case the caller is responsible for
constructing the full URL if needed.

View File

@@ -34,7 +34,7 @@ class ProfileImageUrlTestCase(TestCase):
"""
self.assertEqual(
actual_url,
'http://example-storage.com/profile_images/{name}_{size}.jpg'.format(
'http://example-storage.com/profile-images/{name}_{size}.jpg'.format(
name=expected_name, size=expected_pixels
)
)

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
from copy import deepcopy
import ddt
import hashlib
import json
@@ -19,6 +20,12 @@ from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
from .. import PRIVATE_VISIBILITY, ALL_USERS_VISIBILITY
# this is used in one test to check the behavior of profile image url
# generation with a relative url in the config.
TEST_PROFILE_IMAGE_BACKEND = deepcopy(settings.PROFILE_IMAGE_BACKEND)
TEST_PROFILE_IMAGE_BACKEND['options']['base_url'] = '/profile-images/'
class UserAPITestCase(APITestCase):
"""
The base class for all tests of the User API
@@ -117,7 +124,7 @@ class TestAccountAPI(UserAPITestCase):
image.
"""
if has_profile_image:
url_root = 'http://example-storage.com/profile_images'
url_root = 'http://example-storage.com/profile-images'
filename = hashlib.md5('secret' + self.user.username).hexdigest()
file_extension = 'jpg'
else:
@@ -593,12 +600,12 @@ class TestAccountAPI(UserAPITestCase):
)
self.assertIsNone(error_response.data["user_message"])
@override_settings(PROFILE_IMAGE_DOMAIN='/')
@override_settings(PROFILE_IMAGE_BACKEND=TEST_PROFILE_IMAGE_BACKEND)
def test_convert_relative_profile_url(self):
"""
Test that when PROFILE_IMAGE_DOMAIN is set to '/', the API
generates the full URL to profile images based on the URL
of the request.
Test that when TEST_PROFILE_IMAGE_BACKEND['base_url'] begins
with a '/', the API generates the full URL to profile images based on
the URL of the request.
"""
self.client.login(username=self.user.username, password=self.test_password)
response = self.send_get(self.client)