Merge branch 'master' into running-without-six

This commit is contained in:
Chris Hill-Scott
2017-09-19 09:53:40 +01:00
committed by GitHub
7 changed files with 90 additions and 14 deletions

View File

@@ -15,9 +15,16 @@ from app.dao.provider_details_dao import (
)
from app.celery.research_mode_tasks import send_sms_response, send_email_response
from app.dao.templates_dao import dao_get_template_by_id
from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFICATION_TECHNICAL_FAILURE, \
NOTIFICATION_SENT, NOTIFICATION_SENDING
from app.models import (
SMS_TYPE,
KEY_TYPE_TEST,
BRANDING_ORG,
BRANDING_GOVUK,
EMAIL_TYPE,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_SENT,
NOTIFICATION_SENDING
)
from app.celery.statistics_tasks import create_initial_notification_statistic_tasks
@@ -168,7 +175,7 @@ def get_logo_url(base_url, logo_file):
def get_html_email_options(service):
govuk_banner = service.branding != BRANDING_ORG
if service.organisation:
if service.organisation and service.branding != BRANDING_GOVUK:
logo_url = get_logo_url(
current_app.config['ADMIN_BASE_URL'],
service.organisation.logo

View File

@@ -16,6 +16,7 @@ from notifications_utils.recipients import (
InvalidPhoneError,
InvalidEmailError
)
from notifications_utils.letter_timings import get_letter_timings
from app.encryption import (
hashpw,
@@ -1029,6 +1030,10 @@ class Notification(db.Model):
serialized['line_5'] = self.personalisation.get('address_line_5')
serialized['line_6'] = self.personalisation.get('address_line_6')
serialized['postcode'] = self.personalisation['postcode']
serialized['estimated_delivery'] = \
get_letter_timings(serialized['created_at'])\
.earliest_delivery\
.strftime(DATETIME_FORMAT)
return serialized

View File

@@ -14,8 +14,8 @@ marshmallow-sqlalchemy==0.13.1
marshmallow==2.13.6
monotonic==1.3
psycopg2==2.7.3.1
PyJWT==1.5.2
SQLAlchemy-Utils==0.32.14
PyJWT==1.5.3
SQLAlchemy-Utils==0.32.16
SQLAlchemy==1.1.14
statsd==3.2.1

View File

@@ -1,7 +1,7 @@
-r requirements.txt
pycodestyle==2.3.1
pytest==3.2.2
pytest-mock==1.6.2
pytest-mock==1.6.3
pytest-cov==2.5.1
pytest-xdist==1.20.0
coveralls==1.2.0

View File

@@ -568,12 +568,12 @@ def sample_notification(
@pytest.fixture
def sample_letter_notification(sample_letter_template):
address = {
'addressline1': 'A1',
'addressline2': 'A2',
'addressline3': 'A3',
'addressline4': 'A4',
'addressline5': 'A5',
'addressline6': 'A6',
'address_line_1': 'A1',
'address_line_2': 'A2',
'address_line_3': 'A3',
'address_line_4': 'A4',
'address_line_5': 'A5',
'address_line_6': 'A6',
'postcode': 'A_POST'
}
return create_notification(sample_letter_template, personalisation=address)

View File

@@ -19,6 +19,7 @@ from app.models import (
KEY_TYPE_TEST,
KEY_TYPE_TEAM,
BRANDING_ORG,
BRANDING_GOVUK,
BRANDING_BOTH)
from tests.app.db import create_service, create_template, create_notification, create_inbound_number
@@ -426,6 +427,18 @@ def test_get_html_email_renderer_with_branding_details(branding_type, govuk_bann
assert options['brand_name'] == 'Justice League'
def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_only(notify_db, sample_service):
sample_service.branding = BRANDING_GOVUK
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
sample_service.organisation = org
notify_db.session.add_all([sample_service, org])
notify_db.session.commit()
options = send_to_providers.get_html_email_options(sample_service)
assert options == {'govuk_banner': True}
def test_get_html_email_renderer_prepends_logo_path(notify_api):
Service = namedtuple('Service', ['branding', 'organisation'])
Organisation = namedtuple('Organisation', ['colour', 'name', 'logo'])

View File

@@ -1,4 +1,4 @@
import datetime
import pytest
from flask import json
@@ -9,6 +9,11 @@ from tests.app.db import (
create_template,
create_service)
from tests.app.conftest import (
sample_notification,
sample_email_notification,
)
@pytest.mark.parametrize('billable_units, provider', [
(1, 'mmg'),
@@ -207,6 +212,52 @@ def test_get_notification_by_id_invalid_id(client, sample_notification, id):
}
@pytest.mark.parametrize('created_at_month, estimated_delivery', [
(
12, '2000-12-06T16:00:00.000000Z', # 4pm GMT in winter
),
(
6, '2000-06-05T15:00:00.000000Z', # 4pm BST in summer
),
])
def test_get_notification_adds_delivery_estimate_for_letters(
client,
sample_letter_notification,
created_at_month,
estimated_delivery,
):
sample_letter_notification.created_at = datetime.date(2000, created_at_month, 1)
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
response = client.get(
path='/v2/notifications/{}'.format(sample_letter_notification.id),
headers=[('Content-Type', 'application/json'), auth_header]
)
json_response = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert json_response['estimated_delivery'] == estimated_delivery
@pytest.mark.parametrize('notification_mock', [
sample_notification,
sample_email_notification,
])
def test_get_notification_doesnt_have_delivery_estimate_for_non_letters(
client,
notify_db,
notify_db_session,
notification_mock,
):
mocked_notification = notification_mock(notify_db, notify_db_session)
auth_header = create_authorization_header(service_id=mocked_notification.service_id)
response = client.get(
path='/v2/notifications/{}'.format(mocked_notification.id),
headers=[('Content-Type', 'application/json'), auth_header]
)
assert response.status_code == 200
assert 'estimated_delivery' not in json.loads(response.get_data(as_text=True))
def test_get_all_notifications_returns_200(client, sample_template):
notifications = [create_notification(template=sample_template) for _ in range(2)]
notification = notifications[-1]