From 6e1bcb84050ec777198b1fe76cd8c1b69b60a2d1 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 24 Jul 2017 15:20:40 +0100 Subject: [PATCH] Update emails to use logos cdn --- app/__init__.py | 3 +++ app/config.py | 8 ++++++++ app/utils.py | 10 ++++++++++ tests/app/test_utils.py | 10 ++++++++++ 4 files changed, 31 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 9ff29af79..85f3f0052 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -55,8 +55,11 @@ from app.notify_client.organisations_client import OrganisationsClient from app.notify_client.models import AnonymousUser from app.notify_client.letter_jobs_client import LetterJobsClient from app.utils import get_cdn_domain +<<<<<<< HEAD from app.utils import gmt_timezones +======= +>>>>>>> Update emails to use logos cdn login_manager = LoginManager() csrf = CSRFProtect() diff --git a/app/config.py b/app/config.py index eabd7391f..77a3e0781 100644 --- a/app/config.py +++ b/app/config.py @@ -87,6 +87,8 @@ class Config(object): r"cqc\.org\.uk", ] + LOGO_UPLOAD_BUCKET_NAME = 'local-notifications-logo-upload' + class Development(Config): DEBUG = True @@ -94,6 +96,7 @@ class Development(Config): SESSION_PROTECTION = None STATSD_ENABLED = False CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'development-notifications-logo-upload' class Test(Development): @@ -102,6 +105,7 @@ class Test(Development): STATSD_ENABLED = True WTF_CSRF_ENABLED = False CSV_UPLOAD_BUCKET_NAME = 'test-notifications-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'test-notifications-logo-upload' NOTIFY_ENVIRONMENT = 'test' TEMPLATE_PREVIEW_API_HOST = 'http://localhost:9999' @@ -111,6 +115,7 @@ class Preview(Config): HEADER_COLOUR = '#F499BE' # $baby-pink STATSD_ENABLED = True CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'preview-notifications-logo-upload' NOTIFY_ENVIRONMENT = 'preview' @@ -120,6 +125,7 @@ class Staging(Config): HEADER_COLOUR = '#6F72AF' # $mauve STATSD_ENABLED = True CSV_UPLOAD_BUCKET_NAME = 'staging-notify-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'staging-notifications-logo-upload' NOTIFY_ENVIRONMENT = 'staging' @@ -129,6 +135,7 @@ class Live(Config): HTTP_PROTOCOL = 'https' STATSD_ENABLED = True CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'live-notifications-logo-upload' NOTIFY_ENVIRONMENT = 'live' @@ -142,6 +149,7 @@ class Sandbox(CloudFoundryConfig): HEADER_COLOUR = '#F499BE' # $baby-pink STATSD_ENABLED = True CSV_UPLOAD_BUCKET_NAME = 'cf-sandbox-notifications-csv-upload' + LOGO_UPLOAD_BUCKET_NAME = 'cf-sandbox-notifications-logo-upload' NOTIFY_ENVIRONMENT = 'sandbox' diff --git a/app/utils.py b/app/utils.py index a0c8747e6..23b4d2b3a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,14 +1,21 @@ import re import csv +<<<<<<< HEAD import pytz +======= +from datetime import datetime, timedelta, timezone +>>>>>>> Update emails to use logos cdn from io import StringIO from os import path from functools import wraps import unicodedata from urllib.parse import urlparse +<<<<<<< HEAD from collections import namedtuple from datetime import datetime, timedelta, timezone from dateutil import parser +======= +>>>>>>> Update emails to use logos cdn import dateutil import ago @@ -330,6 +337,7 @@ def email_or_sms_not_enabled(template_type, permissions): return (template_type in ['email', 'sms']) and (template_type not in permissions) +<<<<<<< HEAD def get_letter_timings(upload_time): LetterTimings = namedtuple( @@ -367,6 +375,8 @@ def gmt_timezones(date): return forced_utc.astimezone(pytz.timezone('Europe/London')) +======= +>>>>>>> Update emails to use logos cdn def get_cdn_domain(): parsed_uri = urlparse(current_app.config['ADMIN_BASE_URL']) diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 980f7a6c7..8e2269e32 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -12,7 +12,10 @@ from app.utils import ( generate_previous_dict, generate_next_dict, Spreadsheet, +<<<<<<< HEAD get_letter_timings, +======= +>>>>>>> Update emails to use logos cdn get_cdn_domain ) @@ -156,6 +159,7 @@ def test_generate_notifications_csv_calls_twice_if_next_link(mocker): assert mock_get_notifications.mock_calls[1][2]['page'] == 2 +<<<<<<< HEAD @freeze_time('2017-07-14 14:59:59') # Friday, before print deadline @pytest.mark.parametrize('upload_time, expected_print_time, is_printed, expected_earliest, expected_latest', [ @@ -290,13 +294,19 @@ def test_get_estimated_delivery_date_for_letter( assert timings.latest_delivery.strftime('%A %Y-%m-%d') == expected_latest +======= +>>>>>>> Update emails to use logos cdn def test_get_cdn_domain_on_localhost(client, mocker): mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'http://localhost:6012'}) domain = get_cdn_domain() assert domain == 'static-logos.notify.tools' +<<<<<<< HEAD def test_get_cdn_domain_on_non_localhost(client, mocker): +======= +def test_get_cdn_domain_without_logo_base_domain_env_returns_admin_base_domain(client, mocker): +>>>>>>> Update emails to use logos cdn mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'https://some.admintest.com'}) domain = get_cdn_domain() assert domain == 'static-logos.admintest.com'