Update config to use logo cdn

This commit is contained in:
Ken Tsang
2017-07-21 16:06:12 +01:00
parent 3878ece9ea
commit 3e6e75998b
3 changed files with 16 additions and 37 deletions

View File

@@ -115,7 +115,6 @@ class Config(object):
PAGE_SIZE = 50
API_PAGE_SIZE = 250
SMS_CHAR_COUNT_LIMIT = 495
BRANDING_PATH = '/images/email-template/crests/'
TEST_MESSAGE_FILENAME = 'Test message'
ONE_OFF_MESSAGE_FILENAME = 'Report'
MAX_VERIFY_CODE_COUNT = 10

View File

@@ -145,34 +145,22 @@ def provider_to_use(notification_type, notification_id, international=False):
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
def get_logo_url(base_url, branding_path, logo_file):
"""
Get the complete URL for a given logo.
We have to convert the base_url into a static url. Our hosted environments all have their own cloudfront instances,
found at the static subdomain (eg https://static.notifications.service.gov.uk).
If running locally (dev environment), don't try and use cloudfront - just stick to the actual underlying source
({URL}/static/{PATH})
"""
def get_logo_url(base_url, logo_file):
base_url = parse.urlparse(base_url)
netloc = base_url.netloc
# covers both preview and staging
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
path = '/static' + branding_path + logo_file
else:
if base_url.netloc.startswith('www'):
if base_url.netloc.startswith('localhost'):
netloc = 'notify.tools'
elif base_url.netloc.startswith('www'):
# strip "www."
netloc = base_url.netloc[4:]
netloc = 'static.' + netloc
path = branding_path + logo_file
netloc = 'static-logos.' + netloc
logo_url = parse.ParseResult(
scheme=base_url.scheme,
netloc=netloc,
path=path,
path=logo_file,
params=base_url.params,
query=base_url.query,
fragment=base_url.fragment
@@ -185,7 +173,6 @@ def get_html_email_options(service):
if service.organisation:
logo_url = get_logo_url(
current_app.config['ADMIN_BASE_URL'],
current_app.config['BRANDING_PATH'],
service.organisation.logo
)

View File

@@ -435,29 +435,22 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api):
renderer = send_to_providers.get_html_email_options(service)
assert renderer['brand_logo'] == 'http://localhost:6012/static/images/email-template/crests/justice-league.png'
assert renderer['brand_logo'] == 'http://static-logos.notify.tools/justice-league.png'
@pytest.mark.parametrize('base_url, expected_url', [
# don't change localhost to prevent errors when testing locally
('http://localhost:6012', 'http://localhost:6012/static/sub-path/filename.png'),
# on other environments, replace www with staging
('https://www.notifications.service.gov.uk', 'https://static.notifications.service.gov.uk/sub-path/filename.png'),
# staging and preview do not have cloudfront running, so should act as localhost
pytest.mark.xfail(('https://www.notify.works', 'https://static.notify.works/sub-path/filename.png')),
pytest.mark.xfail(('https://www.staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
pytest.mark.xfail(('https://notify.works', 'https://static.notify.works/sub-path/filename.png')),
pytest.mark.xfail(('https://staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
# these tests should be removed when cloudfront works on staging/preview
('https://www.notify.works', 'https://www.notify.works/static/sub-path/filename.png'),
('https://www.staging-notify.works', 'https://www.staging-notify.works/static/sub-path/filename.png'),
('http://localhost:6012', 'http://static-logos.notify.tools/filename.png'),
('https://www.notifications.service.gov.uk', 'https://static-logos.notifications.service.gov.uk/filename.png'),
('https://notify.works', 'https://static-logos.notify.works/filename.png'),
('https://staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
('https://www.notify.works', 'https://static-logos.notify.works/filename.png'),
('https://www.staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
])
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
branding_path = '/sub-path/'
logo_file = 'filename.png'
logo_url = send_to_providers.get_logo_url(base_url, branding_path, logo_file)
logo_url = send_to_providers.get_logo_url(base_url, logo_file)
assert logo_url == expected_url