Merge branch 'master' into pyup-update-pyexcel-0.5.8-to-0.5.9

This commit is contained in:
Chris Hill-Scott
2018-09-03 09:52:01 +01:00
committed by GitHub
18 changed files with 150 additions and 146 deletions

1
.gitignore vendored
View File

@@ -40,6 +40,7 @@ htmlcov/
.coverage .coverage
.coverage.* .coverage.*
.cache .cache
.pytest_cache
coverage.xml coverage.xml
test_results.xml test_results.xml
*,cover *,cover

View File

@@ -5,18 +5,16 @@
const root = this, const root = this,
$ = this.jQuery; $ = this.jQuery;
let branding_type = $('.multiple-choice input[name="branding_type"]:checked');
let branding_style = $('.multiple-choice input[name="branding_style"]:checked'); let branding_style = $('.multiple-choice input[name="branding_style"]:checked');
if (!branding_type.length || !branding_style.length) { return; } if (!branding_style.length) { return; }
branding_type = branding_type.val();
branding_style = branding_style.val(); branding_style = branding_style.val();
const $paneWrapper = $('<div class="column-full"></div>'); const $paneWrapper = $('<div class="column-full"></div>');
const $form = $('form'); const $form = $('form');
const $previewPane = $('<iframe src="/_email?' + const $previewPane = $('<iframe src="/_email?' +
buildQueryString(['branding_type', branding_type], ['branding_style', branding_style]) + buildQueryString(['branding_style', branding_style]) +
'" class="email-branding-preview"></iframe>'); '" class="email-branding-preview"></iframe>');
function buildQueryString () { function buildQueryString () {
@@ -25,13 +23,10 @@
function setPreviewPane (e) { function setPreviewPane (e) {
const $target = $(e.target); const $target = $(e.target);
if ($target.attr('name') == 'branding_type') {
branding_type = $target.val();
}
if ($target.attr('name') == 'branding_style') { if ($target.attr('name') == 'branding_style') {
branding_style = $target.val(); branding_style = $target.val();
} }
$previewPane.attr('src', '/_email?' + buildQueryString(['branding_type', branding_type], ['branding_style', branding_style])); $previewPane.attr('src', '/_email?' + buildQueryString(['branding_style', branding_style]));
} }
$paneWrapper.append($previewPane); $paneWrapper.append($previewPane);
@@ -39,5 +34,5 @@
$form.attr('action', location.pathname.replace(/set-email-branding$/, 'preview-email-branding')); $form.attr('action', location.pathname.replace(/set-email-branding$/, 'preview-email-branding'));
$form.find('button[type="submit"]').text('Save'); $form.find('button[type="submit"]').text('Save');
$('fieldset').on('change', 'input[name="branding_type"], input[name="branding_style"]', setPreviewPane); $('fieldset').on('change', 'input[name="branding_style"]', setPreviewPane);
})(); })();

View File

@@ -682,23 +682,6 @@ class ServiceSwitchLettersForm(StripWhitespaceForm):
class ServiceSetBranding(StripWhitespaceForm): class ServiceSetBranding(StripWhitespaceForm):
def __init__(self, email_branding=[], *args, **kwargs):
self.branding_style.choices = email_branding
super(ServiceSetBranding, self).__init__(*args, **kwargs)
branding_type = RadioField(
'Branding type',
choices=[
('govuk', 'GOV.UK only'),
('both', 'GOV.UK and branding'),
('org', 'Branding only'),
('org_banner', 'Branding banner')
],
validators=[
DataRequired()
]
)
branding_style = RadioField( branding_style = RadioField(
'Branding style', 'Branding style',
validators=[ validators=[
@@ -709,7 +692,6 @@ class ServiceSetBranding(StripWhitespaceForm):
class ServicePreviewBranding(StripWhitespaceForm): class ServicePreviewBranding(StripWhitespaceForm):
branding_type = HiddenField('branding_type')
branding_style = HiddenField('branding_style') branding_style = HiddenField('branding_style')

View File

@@ -91,17 +91,20 @@ def design_content():
@main.route('/_email') @main.route('/_email')
def email_template(): def email_template():
branding_type = request.args.get('branding_type', 'govuk') branding_type = 'govuk'
branding_style = request.args.get('branding_style', 'None') branding_style = request.args.get('branding_style', 'None')
if branding_type == 'govuk' or branding_style == 'None': if branding_style != 'None':
email_branding = email_branding_client.get_email_branding(branding_style)['email_branding']
branding_type = email_branding['brand_type']
if branding_type == 'govuk':
brand_name = None brand_name = None
brand_colour = None brand_colour = None
brand_logo = None brand_logo = None
govuk_banner = True govuk_banner = True
brand_banner = False brand_banner = False
else: else:
email_branding = email_branding_client.get_email_branding(branding_style)['email_branding']
colour = email_branding['colour'] colour = email_branding['colour']
brand_name = email_branding['text'] brand_name = email_branding['text']
brand_colour = colour brand_colour = colour

View File

@@ -874,19 +874,18 @@ def set_free_sms_allowance(service_id):
@user_is_platform_admin @user_is_platform_admin
def service_set_email_branding(service_id): def service_set_email_branding(service_id):
email_branding = email_branding_client.get_all_email_branding() email_branding = email_branding_client.get_all_email_branding()
branding_type = current_service.get('branding')
form = ServiceSetBranding(branding_type=branding_type) form = ServiceSetBranding()
# dynamically create org choices, including the null option # dynamically create org choices, including the null option
email_brandings = sorted(get_branding_as_value_and_label(email_branding), email_brandings = sorted(get_branding_as_value_and_label(email_branding),
key=lambda tup: tup[1].lower()) key=lambda tup: tup[1].lower())
form.branding_style.choices = [('None', 'None')] + email_brandings form.branding_style.choices = [('None', 'GOV.UK')] + email_brandings
if form.validate_on_submit(): if form.validate_on_submit():
branding_style = None if form.branding_style.data == 'None' else form.branding_style.data branding_style = None if form.branding_style.data == 'None' else form.branding_style.data
return redirect(url_for('.service_preview_email_branding', service_id=service_id, return redirect(url_for('.service_preview_email_branding', service_id=service_id,
branding_type=form.branding_type.data, branding_style=branding_style)) branding_style=branding_style))
form.branding_style.data = current_service['email_branding'] or 'None' form.branding_style.data = current_service['email_branding'] or 'None'
@@ -903,16 +902,14 @@ def service_set_email_branding(service_id):
@login_required @login_required
@user_is_platform_admin @user_is_platform_admin
def service_preview_email_branding(service_id): def service_preview_email_branding(service_id):
branding_type = request.args.get('branding_type', None)
branding_style = request.args.get('branding_style', None) branding_style = request.args.get('branding_style', None)
form = ServicePreviewBranding(branding_type=branding_type, branding_style=branding_style) form = ServicePreviewBranding(branding_style=branding_style)
if form.validate_on_submit(): if form.validate_on_submit():
branding_style = None if form.branding_style.data == 'None' else form.branding_style.data branding_style = None if form.branding_style.data == 'None' else form.branding_style.data
service_api_client.update_service( service_api_client.update_service(
service_id, service_id,
branding=form.branding_type.data,
email_branding=branding_style email_branding=branding_style
) )
return redirect(url_for('.service_settings', service_id=service_id)) return redirect(url_for('.service_settings', service_id=service_id))
@@ -992,8 +989,15 @@ def link_service_to_organisation(service_id):
@user_has_permissions('manage_service') @user_has_permissions('manage_service')
def branding_request(service_id): def branding_request(service_id):
branding_type = 'govuk'
if current_service.email_branding:
email_branding = email_branding_client.get_email_branding(
current_service.email_branding)['email_branding']
branding_type = email_branding['brand_type']
form = BrandingOptionsEmail( form = BrandingOptionsEmail(
options=current_service.branding options=branding_type
) )
if form.validate_on_submit(): if form.validate_on_submit():

View File

@@ -270,7 +270,6 @@ class Service(dict):
ALLOWED_PROPERTIES = { ALLOWED_PROPERTIES = {
'active', 'active',
'branding',
'dvla_organisation', 'dvla_organisation',
'email_branding', 'email_branding',
'email_from', 'email_from',
@@ -293,7 +292,7 @@ class Service(dict):
def __getattr__(self, attr): def __getattr__(self, attr):
if attr in self.ALLOWED_PROPERTIES: if attr in self.ALLOWED_PROPERTIES:
return self[attr] return self[attr]
raise AttributeError raise AttributeError('`{}` is not a service attribute'.format(attr))
@property @property
def trial_mode(self): def trial_mode(self):

View File

@@ -93,21 +93,21 @@
<div class="bottom-gutter-3-2"> <div class="bottom-gutter-3-2">
{% call mapping_table( {% call mapping_table(
caption='Letter pricing', caption='Letter pricing',
field_headings=['', 'Crown bodies', 'Other public sector organisations'], field_headings=['', 'Current price', 'Price from 1 October 2018'],
field_headings_visible=True, field_headings_visible=True,
caption_visible=False caption_visible=False
) %} ) %}
{% for sheets, central, local in [ {% for sheets, current, future in [
('1 sheet', '30', '33'), ('1 sheet', '30', '30'),
('2 sheets', '33', '39'), ('2 sheets', '33', '35'),
('3 sheets', '36', '45'), ('3 sheets', '36', '40'),
('4 sheets', '39', '51'), ('4 sheets', '39', '45'),
('5 sheets', '42', '57'), ('5 sheets', '42', '50'),
] %} ] %}
{% call row() %} {% call row() %}
{% call row_heading() %} {{ sheets }} (double-sided) {% endcall %} {% call row_heading() %} {{ sheets }} (double-sided) {% endcall %}
{{ text_field(central + 'p + VAT') }} {{ text_field(current + 'p + VAT') }}
{{ text_field(local + 'p + VAT') }} {{ text_field(future + 'p + VAT') }}
{% endcall %} {% endcall %}
{% endfor %} {% endfor %}
{% endcall %} {% endcall %}

View File

@@ -101,9 +101,7 @@
{% call settings_row(if_has_permission='email') %} {% call settings_row(if_has_permission='email') %}
{{ text_field('Email branding') }} {{ text_field('Email branding') }}
{{ text_field( {{ text_field('Your branding' if email_branding else 'GOV.UK') }}
'GOV.UK' if current_service.branding == 'govuk' else 'Your branding'
) }}
{{ edit_field( {{ edit_field(
'Change', 'Change',
url_for('.branding_request', service_id=current_service.id), url_for('.branding_request', service_id=current_service.id),
@@ -301,17 +299,7 @@
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}
{{ text_field('Email branding' )}} {{ text_field('Email branding' )}}
{% call field() %} {{ text_field(email_branding.name or 'GOV.UK') }}
{% if current_service.branding == 'govuk' %}
GOV.UK
{% elif current_service.branding == 'both' %}
GOV.UK and {{ email_branding.name if email_branding else None }}
{% elif current_service.branding == 'org' %}
Only {{ email_branding.name if email_branding else None }}
{% elif current_service.branding == 'org_banner' %}
Only {{ email_branding.name if email_branding else None }} banner
{% endif %}
{% endcall %}
{{ edit_field('Change', url_for('.service_set_email_branding', service_id=current_service.id)) }} {{ edit_field('Change', url_for('.service_set_email_branding', service_id=current_service.id)) }}
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}

View File

@@ -9,7 +9,7 @@
<h1 class="heading-large">Preview email branding</h1> <h1 class="heading-large">Preview email branding</h1>
<div class="grid-row"> <div class="grid-row">
<div class="column-full"> <div class="column-full">
<iframe src="{{ url_for('main.email_template', branding_type=form.branding_type.data, branding_style=form.branding_style.data) }}" class="email-branding-preview"></iframe> <iframe src="{{ url_for('main.email_template', branding_style=form.branding_style.data) }}" class="email-branding-preview"></iframe>
<form method="post" action="{{ action }}"> <form method="post" action="{{ action }}">
<div class="form-group"> <div class="form-group">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}

View File

@@ -24,8 +24,8 @@
) }} ) }}
{{ task_list_item( {{ task_list_item(
has_templates, has_templates,
'<a href="{}">Add content to '<a href="{}">Add templates with examples of the content you plan to send
templates to show the kind of messages youll send</a>'.format( </a>'.format(
url_for('main.choose_template', service_id=current_service.id) url_for('main.choose_template', service_id=current_service.id)
)|safe, )|safe,
) }} ) }}

View File

@@ -12,14 +12,11 @@
<h1 class="heading-large">Set email branding</h1> <h1 class="heading-large">Set email branding</h1>
<form method="post"> <form method="post">
<div class="grid-row"> <div class="grid-row">
<div class="column-one-whole"> <div class="column-full preview-pane">
</div> </div>
</div> </div>
<div class="grid-row"> <div class="grid-row">
<div class="column-one-half"> <div class="column-full">
{{ radios(form.branding_type) }}
</div>
<div class="column-one-half brand_styles">
{{ live_search(target_selector='.brand_styles .multiple-choice', show=show_search_box, form=search_form, label='Search branding styles by name') }} {{ live_search(target_selector='.brand_styles .multiple-choice', show=show_search_box, form=search_form, label='Search branding styles by name') }}
{{ radios(form.branding_style) }} {{ radios(form.branding_style) }}
</div> </div>

View File

@@ -23,7 +23,7 @@
<div class="user-list"> <div class="user-list">
{% if not sms_senders %} {% if not sms_senders %}
<div class="user-list-item"> <div class="user-list-item">
<span class="hint">You havent added any sms senders yet</span> <span class="hint">You havent added any text message senders yet</span>
</div> </div>
{% endif %} {% endif %}
{% for item in sms_senders %} {% for item in sms_senders %}
@@ -46,4 +46,7 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<p>
The text message sender tells your users who the message is from.
</p>
{% endblock %} {% endblock %}

View File

@@ -8,7 +8,7 @@ Flask-Login==0.4.1
blinker==1.4 blinker==1.4
pyexcel==0.5.9 pyexcel==0.5.9
pyexcel-io==0.5.8 pyexcel-io==0.5.9
pyexcel-xls==0.5.7 pyexcel-xls==0.5.7
pyexcel-xlsx==0.5.6 pyexcel-xlsx==0.5.6
pyexcel-ods3==0.5.2 pyexcel-ods3==0.5.2

View File

@@ -10,7 +10,7 @@ Flask-Login==0.4.1
blinker==1.4 blinker==1.4
pyexcel==0.5.9 pyexcel==0.5.9
pyexcel-io==0.5.8 pyexcel-io==0.5.9
pyexcel-xls==0.5.7 pyexcel-xls==0.5.7
pyexcel-xlsx==0.5.6 pyexcel-xlsx==0.5.6
pyexcel-ods3==0.5.2 pyexcel-ods3==0.5.2

View File

@@ -1,11 +1,11 @@
-r requirements.txt -r requirements.txt
isort==4.3.4 isort==4.3.4
pytest==3.7.3 pytest==3.7.4
pytest-env==0.6.2 pytest-env==0.6.2
pytest-mock==1.10.0 pytest-mock==1.10.0
pytest-cov==2.5.1 pytest-cov==2.5.1
pytest-xdist==1.23.0 pytest-xdist==1.23.0
coveralls==1.3.0 coveralls==1.4.0
httpretty==0.9.5 httpretty==0.9.5
beautifulsoup4==4.6.3 beautifulsoup4==4.6.3
freezegun==0.3.10 freezegun==0.3.10

View File

@@ -32,9 +32,9 @@ def test_displays_govuk_branding_by_default(client):
assert page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("a", attrs={"href": "https://www.gov.uk"})
def test_displays_govuk_branding(client): def test_displays_govuk_branding(client, mock_get_email_branding_with_govuk_brand_type):
response = client.get(url_for('main.email_template', branding_type="govuk", branding_style="1")) response = client.get(url_for('main.email_template', branding_style="1"))
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
@@ -43,14 +43,14 @@ def test_displays_govuk_branding(client):
assert page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("a", attrs={"href": "https://www.gov.uk"})
def test_displays_both_branding(client, mock_get_email_branding): def test_displays_both_branding(client, mock_get_email_branding_with_both_brand_type):
response = client.get(url_for('main.email_template', branding_type="both", branding_style="1")) response = client.get(url_for('main.email_template', branding_style="1"))
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
assert response.status_code == 200 assert response.status_code == 200
mock_get_email_branding.assert_called_once_with('1') mock_get_email_branding_with_both_brand_type.assert_called_once_with('1')
assert page.find("a", attrs={"href": "https://www.gov.uk"}) assert page.find("a", attrs={"href": "https://www.gov.uk"})
assert page.find("img", attrs={"src": re.compile("example.png$")}) assert page.find("img", attrs={"src": re.compile("example.png$")})
@@ -60,7 +60,8 @@ def test_displays_both_branding(client, mock_get_email_branding):
def test_displays_org_branding(client, mock_get_email_branding): def test_displays_org_branding(client, mock_get_email_branding):
response = client.get(url_for('main.email_template', branding_type="org", branding_style="1")) # mock_get_email_branding has 'brand_type' of 'org'
response = client.get(url_for('main.email_template', branding_style="1"))
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
@@ -74,15 +75,15 @@ def test_displays_org_branding(client, mock_get_email_branding):
.get_text().strip() == 'Organisation text' # brand text is set .get_text().strip() == 'Organisation text' # brand text is set
def test_displays_org_branding_with_banner(client, mock_get_email_branding): def test_displays_org_branding_with_banner(
client, mock_get_email_branding_with_org_banner_brand_type):
response = client.get(url_for('main.email_template', branding_type="org_banner", response = client.get(url_for('main.email_template', branding_style="1"))
branding_style="1"))
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
assert response.status_code == 200 assert response.status_code == 200
mock_get_email_branding.assert_called_once_with('1') mock_get_email_branding_with_org_banner_brand_type.assert_called_once_with('1')
assert not page.find("a", attrs={"href": "https://www.gov.uk"}) assert not page.find("a", attrs={"href": "https://www.gov.uk"})
assert page.find("img", attrs={"src": re.compile("example.png")}) assert page.find("img", attrs={"src": re.compile("example.png")})
@@ -94,8 +95,8 @@ def test_displays_org_branding_with_banner(client, mock_get_email_branding):
def test_displays_org_branding_with_banner_without_brand_text( def test_displays_org_branding_with_banner_without_brand_text(
client, mock_get_email_branding_without_brand_text): client, mock_get_email_branding_without_brand_text):
response = client.get(url_for('main.email_template', branding_type="org_banner", # mock_get_email_branding_without_brand_text has 'brand_type' of 'org_banner'
branding_style="1")) response = client.get(url_for('main.email_template', branding_style="1"))
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser") page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")

View File

@@ -509,9 +509,9 @@ def test_should_raise_duplicate_name_handled(
(2, 'Add a team member who can manage settings, team and usage Completed'), (2, 'Add a team member who can manage settings, team and usage Completed'),
]) ])
@pytest.mark.parametrize('count_of_templates, expected_templates_checklist_item', [ @pytest.mark.parametrize('count_of_templates, expected_templates_checklist_item', [
(0, 'Add content to templates to show the kind of messages youll send Not completed'), (0, 'Add templates with examples of the content you plan to send Not completed'),
(1, 'Add content to templates to show the kind of messages youll send Completed'), (1, 'Add templates with examples of the content you plan to send Completed'),
(2, 'Add content to templates to show the kind of messages youll send Completed'), (2, 'Add templates with examples of the content you plan to send Completed'),
]) ])
@pytest.mark.parametrize('count_of_email_templates, reply_to_email_addresses, expected_reply_to_checklist_item', [ @pytest.mark.parametrize('count_of_email_templates, reply_to_email_addresses, expected_reply_to_checklist_item', [
pytest.mark.xfail((0, [], ''), raises=IndexError), pytest.mark.xfail((0, [], ''), raises=IndexError),
@@ -1021,7 +1021,7 @@ def test_default_option_shows_for_default_sender(
( (
'main.service_sms_senders', 'main.service_sms_senders',
no_sms_senders, no_sms_senders,
'You havent added any sms senders yet' 'You havent added any text message senders yet'
), ),
]) ])
def test_no_senders_message_shows( def test_no_senders_message_shows(
@@ -1846,31 +1846,6 @@ def test_set_letter_branding_saves(
mock_update_service.assert_called_once_with(service_one['id'], dvla_organisation='500') mock_update_service.assert_called_once_with(service_one['id'], dvla_organisation='500')
def test_should_show_branding_types(
logged_in_platform_admin_client,
service_one,
mock_get_all_email_branding,
):
response = logged_in_platform_admin_client.get(url_for(
'main.service_set_email_branding', service_id=service_one['id']
))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk'
assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both'
assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org'
assert page.find('input', attrs={"id": "branding_type-3"})['value'] == 'org_banner'
assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs
assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs
assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs
assert 'checked' not in page.find('input', attrs={"id": "branding_type-3"}).attrs
app.email_branding_client.get_all_email_branding.assert_called_once_with()
app.service_api_client.get_service.assert_called_once_with(service_one['id'])
def test_should_show_branding_styles( def test_should_show_branding_styles(
logged_in_platform_admin_client, logged_in_platform_admin_client,
service_one, service_one,
@@ -1897,7 +1872,7 @@ def test_should_show_branding_styles(
assert branding_style_choices[5]['value'] == '5' assert branding_style_choices[5]['value'] == '5'
# radios should be in alphabetical order, based on their labels # radios should be in alphabetical order, based on their labels
assert radio_labels == ['None', 'org 1', 'org 2', 'org 3', 'org 4', 'org 5'] assert radio_labels == ['GOV.UK', 'org 1', 'org 2', 'org 3', 'org 4', 'org 5']
assert 'checked' in branding_style_choices[0].attrs assert 'checked' in branding_style_choices[0].attrs
assert 'checked' not in branding_style_choices[1].attrs assert 'checked' not in branding_style_choices[1].attrs
@@ -1955,8 +1930,8 @@ def test_should_send_branding_and_organisations_to_preview(
) )
assert response.status_code == 302 assert response.status_code == 302
assert response.location == url_for('main.service_preview_email_branding', assert response.location == url_for('main.service_preview_email_branding',
service_id=service_one['id'], branding_type='org', service_id=service_one['id'], branding_style='1',
branding_style='1', _external=True) _external=True)
mock_get_all_email_branding.assert_called_once_with() mock_get_all_email_branding.assert_called_once_with()
@@ -1975,10 +1950,8 @@ def test_should_preview_email_branding(
iframeURLComponents = urlparse(iframe['src']) iframeURLComponents = urlparse(iframe['src'])
iframeQString = parse_qs(iframeURLComponents.query) iframeQString = parse_qs(iframeURLComponents.query)
assert page.find('input', attrs={"id": "branding_type"})['value'] == 'org'
assert page.find('input', attrs={"id": "branding_style"})['value'] == '1' assert page.find('input', attrs={"id": "branding_style"})['value'] == '1'
assert iframeURLComponents.path == '/_email' assert iframeURLComponents.path == '/_email'
assert iframeQString['branding_type'] == ['org']
assert iframeQString['branding_style'] == ['1'] assert iframeQString['branding_style'] == ['1']
app.service_api_client.get_service.assert_called_once_with(service_one['id']) app.service_api_client.get_service.assert_called_once_with(service_one['id'])
@@ -1994,7 +1967,6 @@ def test_should_set_branding_and_organisations(
'main.service_preview_email_branding', service_id=service_one['id'] 'main.service_preview_email_branding', service_id=service_one['id']
), ),
data={ data={
'branding_type': 'org',
'branding_style': '1' 'branding_style': '1'
} }
) )
@@ -2004,7 +1976,6 @@ def test_should_set_branding_and_organisations(
mock_update_service.assert_called_once_with( mock_update_service.assert_called_once_with(
service_one['id'], service_one['id'],
branding='org',
email_branding='1' email_branding='1'
) )
@@ -2886,13 +2857,16 @@ def test_update_service_organisation_does_not_update_if_same_value(
mock_update_service_organisation.called is False mock_update_service_organisation.called is False
def test_show_email_branding_request_page( def test_show_email_branding_request_page_when_no_email_branding_is_set(
client_request, client_request,
mock_get_email_branding
): ):
page = client_request.get( page = client_request.get(
'.branding_request', service_id=SERVICE_ONE_ID '.branding_request', service_id=SERVICE_ONE_ID
) )
mock_get_email_branding.assert_not_called()
radios = page.select('input[type=radio]') radios = page.select('input[type=radio]')
for index, option in enumerate(( for index, option in enumerate((
@@ -2905,6 +2879,35 @@ def test_show_email_branding_request_page(
assert radios[index]['value'] == option assert radios[index]['value'] == option
def test_show_email_branding_request_page_when_email_branding_is_set(
client_request,
mock_get_email_branding,
active_user_with_permissions,
):
service_one = service_json(email_branding='1234')
client_request.login(active_user_with_permissions, service=service_one)
page = client_request.get(
'.branding_request', service_id=SERVICE_ONE_ID
)
mock_get_email_branding.called_once_with('1234')
radios = page.select('input[type=radio]')
for index, option in enumerate((
'govuk',
'both',
'org',
'org_banner',
)):
assert radios[index]['name'] == 'options'
assert radios[index]['value'] == option
if option == 'org':
assert 'checked' in radios[index].attrs
@pytest.mark.parametrize('choice, requested_branding', ( @pytest.mark.parametrize('choice, requested_branding', (
('govuk', 'GOV.UK only'), ('govuk', 'GOV.UK only'),
('both', 'GOV.UK and logo'), ('both', 'GOV.UK and logo'),

View File

@@ -2519,20 +2519,57 @@ def mock_no_email_branding(mocker):
) )
def create_email_branding(id, non_standard_values={}):
branding = {
'logo': 'example.png',
'name': 'Organisation name',
'text': 'Organisation text',
'id': id,
'colour': '#f00',
'domain': 'sample.com',
'brand_type': 'org',
}
if bool(non_standard_values):
branding.update(non_standard_values)
return {'email_branding': branding}
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_email_branding(mocker, fake_uuid): def mock_get_email_branding(mocker, fake_uuid):
def _get_email_branding(id): def _get_email_branding(id):
return { return create_email_branding(fake_uuid)
'email_branding': {
'logo': 'example.png', return mocker.patch(
'name': 'Organisation name', 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding
'text': 'Organisation text', )
'id': fake_uuid,
'colour': '#f00',
'domain': 'sample.com', @pytest.fixture(scope='function')
'brand_type': 'org', def mock_get_email_branding_with_govuk_brand_type(mocker, fake_uuid):
} def _get_email_branding(id):
} return create_email_branding(fake_uuid, {'brand_type': 'govuk'})
return mocker.patch(
'app.email_branding_client.get_email_branding', side_effect=_get_email_branding
)
@pytest.fixture(scope='function')
def mock_get_email_branding_with_both_brand_type(mocker, fake_uuid):
def _get_email_branding(id):
return create_email_branding(fake_uuid, {'brand_type': 'both'})
return mocker.patch(
'app.email_branding_client.get_email_branding', side_effect=_get_email_branding
)
@pytest.fixture(scope='function')
def mock_get_email_branding_with_org_banner_brand_type(mocker, fake_uuid):
def _get_email_branding(id):
return create_email_branding(fake_uuid, {'brand_type': 'org_banner'})
return mocker.patch( return mocker.patch(
'app.email_branding_client.get_email_branding', side_effect=_get_email_branding 'app.email_branding_client.get_email_branding', side_effect=_get_email_branding
@@ -2542,16 +2579,7 @@ def mock_get_email_branding(mocker, fake_uuid):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_email_branding_without_brand_text(mocker, fake_uuid): def mock_get_email_branding_without_brand_text(mocker, fake_uuid):
def _get_email_branding_without_brand_text(id): def _get_email_branding_without_brand_text(id):
return { return create_email_branding(fake_uuid, {'text': '', 'brand_type': 'org_banner'})
'email_branding': {
'logo': 'example.png',
'name': 'Organisation name',
'text': '',
'id': fake_uuid,
'colour': '#f00',
'brand_type': 'org_banner'
}
}
return mocker.patch( return mocker.patch(
'app.email_branding_client.get_email_branding', 'app.email_branding_client.get_email_branding',