mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #508 from alphagov/request-to-go-live-form
Put a form on the request to go live page
This commit is contained in:
@@ -24,5 +24,6 @@ from app.main.views import (
|
|||||||
manage_users,
|
manage_users,
|
||||||
invites,
|
invites,
|
||||||
all_services,
|
all_services,
|
||||||
tour
|
tour,
|
||||||
|
feedback
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -313,3 +313,10 @@ class Feedback(Form):
|
|||||||
name = StringField('Name')
|
name = StringField('Name')
|
||||||
email_address = StringField('Email address')
|
email_address = StringField('Email address')
|
||||||
feedback = TextAreaField(u'', validators=[DataRequired(message="Can’t be empty")])
|
feedback = TextAreaField(u'', validators=[DataRequired(message="Can’t be empty")])
|
||||||
|
|
||||||
|
|
||||||
|
class RequestToGoLiveForm(Form):
|
||||||
|
usage = TextAreaField(
|
||||||
|
'',
|
||||||
|
validators=[DataRequired(message="Can’t be empty")]
|
||||||
|
)
|
||||||
|
|||||||
42
app/main/views/feedback.py
Normal file
42
app/main/views/feedback.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import markdown
|
||||||
|
import requests
|
||||||
|
from flask import render_template, url_for, redirect, flash, current_app, abort
|
||||||
|
from app.main import main
|
||||||
|
from flask_login import login_required
|
||||||
|
from app.main.forms import Feedback
|
||||||
|
|
||||||
|
from flask.ext.login import current_user
|
||||||
|
|
||||||
|
|
||||||
|
@main.route('/feedback', methods=['GET', 'POST'])
|
||||||
|
def feedback():
|
||||||
|
form = Feedback()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
data = {
|
||||||
|
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||||
|
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
||||||
|
'subject': 'Notify feedback',
|
||||||
|
'message': '{}\n{}\n{}'.format(
|
||||||
|
form.name.data,
|
||||||
|
form.email_address.data,
|
||||||
|
form.feedback.data)
|
||||||
|
}
|
||||||
|
headers = {
|
||||||
|
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
||||||
|
'Content-Type': "application/x-www-form-urlencoded"
|
||||||
|
}
|
||||||
|
resp = requests.post(
|
||||||
|
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
|
||||||
|
data=data,
|
||||||
|
headers=headers)
|
||||||
|
if resp.status_code != 201:
|
||||||
|
current_app.logger.error(
|
||||||
|
"Deskpro create ticket request failed with {} '{}'".format(
|
||||||
|
resp.status_code,
|
||||||
|
resp.json())
|
||||||
|
)
|
||||||
|
abort(500, "Feedback submission failed")
|
||||||
|
flash("Your feedback has been submitted")
|
||||||
|
return redirect(url_for('.feedback'))
|
||||||
|
|
||||||
|
return render_template('views/feedback.html', form=form)
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import markdown
|
import markdown
|
||||||
import os
|
import os
|
||||||
import requests
|
from flask import (render_template, url_for, redirect, Markup, current_app, abort)
|
||||||
import json
|
|
||||||
from flask import (render_template, url_for, redirect, Markup, flash, current_app, abort)
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from app.main.forms import Feedback
|
|
||||||
|
|
||||||
from flask.ext.login import current_user
|
from flask.ext.login import current_user
|
||||||
from mdx_gfm import GithubFlavoredMarkdownExtension
|
from mdx_gfm import GithubFlavoredMarkdownExtension
|
||||||
@@ -44,40 +41,6 @@ def terms():
|
|||||||
return render_template('views/terms-of-use.html')
|
return render_template('views/terms-of-use.html')
|
||||||
|
|
||||||
|
|
||||||
@main.route('/feedback', methods=['GET', 'POST'])
|
|
||||||
def feedback():
|
|
||||||
form = Feedback()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
data = {
|
|
||||||
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
|
||||||
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
|
||||||
'subject': 'Notify feedback',
|
|
||||||
'message': '{}\n{}\n{}'.format(
|
|
||||||
form.name.data,
|
|
||||||
form.email_address.data,
|
|
||||||
form.feedback.data)
|
|
||||||
}
|
|
||||||
headers = {
|
|
||||||
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
|
||||||
'Content-Type': "application/x-www-form-urlencoded"
|
|
||||||
}
|
|
||||||
resp = requests.post(
|
|
||||||
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
|
|
||||||
data=data,
|
|
||||||
headers=headers)
|
|
||||||
if resp.status_code != 201:
|
|
||||||
current_app.logger.error(
|
|
||||||
"Deskpro create ticket request failed with {} '{}'".format(
|
|
||||||
resp.status_code,
|
|
||||||
resp.json())
|
|
||||||
)
|
|
||||||
abort(500, "Feedback submission failed")
|
|
||||||
flash("Your feedback has been submitted")
|
|
||||||
return redirect(url_for('.feedback'))
|
|
||||||
|
|
||||||
return render_template('views/feedback.html', form=form)
|
|
||||||
|
|
||||||
|
|
||||||
@main.route('/documentation')
|
@main.route('/documentation')
|
||||||
def documentation():
|
def documentation():
|
||||||
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
curr_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
import requests
|
||||||
from flask import (
|
from flask import (
|
||||||
render_template,
|
render_template,
|
||||||
redirect,
|
redirect,
|
||||||
request,
|
request,
|
||||||
url_for,
|
url_for,
|
||||||
session,
|
session,
|
||||||
flash
|
flash,
|
||||||
|
abort,
|
||||||
|
current_app
|
||||||
)
|
)
|
||||||
|
|
||||||
from flask_login import (
|
from flask_login import (
|
||||||
@@ -16,7 +19,7 @@ from notifications_python_client.errors import HTTPError
|
|||||||
from app import service_api_client
|
from app import service_api_client
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.utils import user_has_permissions, email_safe
|
from app.utils import user_has_permissions, email_safe
|
||||||
from app.main.forms import ConfirmPasswordForm, ServiceNameForm
|
from app.main.forms import ConfirmPasswordForm, ServiceNameForm, RequestToGoLiveForm
|
||||||
from app import user_api_client
|
from app import user_api_client
|
||||||
from app import current_service
|
from app import current_service
|
||||||
|
|
||||||
@@ -86,15 +89,45 @@ def service_name_change_confirm(service_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings', admin_override=True)
|
@user_has_permissions('manage_settings', admin_override=True)
|
||||||
def service_request_to_go_live(service_id):
|
def service_request_to_go_live(service_id):
|
||||||
if request.method == 'GET':
|
|
||||||
return render_template(
|
form = RequestToGoLiveForm()
|
||||||
'views/service-settings/request-to-go-live.html'
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'person_email': current_app.config.get('DESKPRO_PERSON_EMAIL'),
|
||||||
|
'department_id': current_app.config.get('DESKPRO_TEAM_ID'),
|
||||||
|
'subject': 'Request to go live',
|
||||||
|
'message': "From {} <{}> on behalf of {} ({})\n\nUsage estimate\n---\n\n{}".format(
|
||||||
|
current_user.name,
|
||||||
|
current_user.email_address,
|
||||||
|
current_service['name'],
|
||||||
|
current_service['id'],
|
||||||
|
form.usage.data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
headers = {
|
||||||
|
"X-DeskPRO-API-Key": current_app.config.get('DESKPRO_API_KEY'),
|
||||||
|
'Content-Type': "application/x-www-form-urlencoded"
|
||||||
|
}
|
||||||
|
resp = requests.post(
|
||||||
|
current_app.config.get('DESKPRO_API_HOST') + '/api/tickets',
|
||||||
|
data=data,
|
||||||
|
headers=headers
|
||||||
)
|
)
|
||||||
elif request.method == 'POST':
|
if resp.status_code != 201:
|
||||||
flash('Thanks your request to go live is being processed', 'default')
|
current_app.logger.error(
|
||||||
# TODO implement whatever this action would do in the real world
|
"Deskpro create ticket request failed with {} '{}'".format(
|
||||||
|
resp.status_code,
|
||||||
|
resp.json())
|
||||||
|
)
|
||||||
|
abort(500, "Request to go live submission failed")
|
||||||
|
|
||||||
|
flash('We’ve received your request to go live', 'default')
|
||||||
return redirect(url_for('.service_settings', service_id=service_id))
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
return render_template('views/service-settings/request-to-go-live.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/service-settings/switch-live")
|
@main.route("/services/<service_id>/service-settings/switch-live")
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{% macro textbox(
|
{% macro textbox(
|
||||||
field,
|
field,
|
||||||
|
label=None,
|
||||||
hint=False,
|
hint=False,
|
||||||
highlight_tags=False,
|
highlight_tags=False,
|
||||||
autofocus=False,
|
autofocus=False,
|
||||||
@@ -12,7 +13,11 @@
|
|||||||
) %}
|
) %}
|
||||||
<div class="form-group{% if field.errors %} error{% endif %}" {% if autofocus %}data-module="autofocus"{% endif %}>
|
<div class="form-group{% if field.errors %} error{% endif %}" {% if autofocus %}data-module="autofocus"{% endif %}>
|
||||||
<label class="form-label" for="{{ field.name }}">
|
<label class="form-label" for="{{ field.name }}">
|
||||||
{{ field.label }}
|
{% if label %}
|
||||||
|
{{ label }}
|
||||||
|
{% else %}
|
||||||
|
{{ field.label }}
|
||||||
|
{% endif %}
|
||||||
{% if hint %}
|
{% if hint %}
|
||||||
<span class="form-hint">
|
<span class="form-hint">
|
||||||
{{ hint }}
|
{{ hint }}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
'link': url_for('.service_name_change', service_id=current_service.id)
|
'link': url_for('.service_name_change', service_id=current_service.id)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'title': 'Request to go live and turn off sending restrictions',
|
'title': 'Request to go live and turn off trial mode',
|
||||||
'link': url_for('.service_request_to_go_live', service_id=current_service.id),
|
'link': url_for('.service_request_to_go_live', service_id=current_service.id),
|
||||||
'hint': 'A live service can send notifications to any phone number or email address',
|
'hint': 'A live service can send notifications to any phone number or email address',
|
||||||
} if current_service.restricted else {
|
} if current_service.restricted else {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "withnav_template.html" %}
|
{% extends "withnav_template.html" %}
|
||||||
|
{% from "components/textbox.html" import textbox %}
|
||||||
{% from "components/page-footer.html" import page_footer %}
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
@@ -10,17 +11,54 @@
|
|||||||
<div class="grid-row">
|
<div class="grid-row">
|
||||||
<div class="column-three-quarters">
|
<div class="column-three-quarters">
|
||||||
|
|
||||||
<h1 class="heading-large">Request to go live</h1>
|
<h1 class="heading-large">Request to go live</h1>
|
||||||
|
|
||||||
<p>GOV.UK Notify is invite-only during the beta.</p>
|
<p>
|
||||||
|
You’ll need to:
|
||||||
|
</p>
|
||||||
|
<ul class="list list-bullet">
|
||||||
|
<li>
|
||||||
|
agree to our <a href="{{ url_for('.terms') }}">terms of use</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
agree to pay for what you use if you send more than 250,000 text messages per year
|
||||||
|
(<a href="{{ url_for("main.pricing") }}">see our pricing</a>)
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<p><a href="{{ url_for('main.feedback') }}">Contact us</a> to request an invite:</p>
|
<form method="post">
|
||||||
|
|
||||||
<ul class="list list-bullet">
|
{{ textbox(
|
||||||
<li>You’ll need to agree to our terms of use</li>
|
form.usage,
|
||||||
<li>If you plan to send more than 250,000 text messages per year, you’ll need to agree to pay for what you use – take a look at our <a href="{{ url_for("main.pricing") }}">pricing</a></li>
|
label='Estimate how many emails and/or text messages you’ll send each month',
|
||||||
<li>We’ll check your templates to make sure they’re consistent with our design patterns, style guide and information security principles</li>
|
hint='If your estimate is likely to change, tell us how ',
|
||||||
</ul>
|
width='1-1',
|
||||||
|
rows=5
|
||||||
|
) }}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
We will:
|
||||||
|
</p>
|
||||||
|
<ul class="list list-bullet">
|
||||||
|
<li>
|
||||||
|
check that your templates follow our
|
||||||
|
<a href="https://designpatterns.hackpad.com/Notifications-5vuitmNqIjZ" rel="external">design patterns</a>,
|
||||||
|
<a href="https://www.gov.uk/topic/government-digital-guidance/content-publishing" rel="external">style guide</a>
|
||||||
|
and
|
||||||
|
<a href="https://docs.google.com/document/d/15-OjaEqDBy31uDU7nLZCpYIQOnzSCJR63-cp3cQI9G8" rel="external">information security guidelines</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
check that you have more than one
|
||||||
|
<a href="{{ url_for('main.manage_users', service_id=current_service.id) }}">team member</a>
|
||||||
|
in case you go on holiday
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
make your service live or get back to you within one working day
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{ page_footer('Request to go live') }}
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
101
tests/app/main/views/test_feedback.py
Normal file
101
tests/app/main/views/test_feedback.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
import pytest
|
||||||
|
from flask import (url_for, current_app)
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
from unittest.mock import Mock, ANY
|
||||||
|
|
||||||
|
|
||||||
|
def test_logged_in_user_redirects_to_choose_service(app_,
|
||||||
|
api_user_active,
|
||||||
|
mock_get_user,
|
||||||
|
mock_get_user_by_email,
|
||||||
|
mock_login):
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(api_user_active)
|
||||||
|
response = client.get(url_for('main.index'))
|
||||||
|
assert response.status_code == 302
|
||||||
|
|
||||||
|
response = client.get(url_for('main.sign_in', follow_redirects=True))
|
||||||
|
assert response.location == url_for('main.choose_service', _external=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_feedback_page(app_):
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
resp = client.get(url_for('main.feedback'))
|
||||||
|
assert resp.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_feedback_with_no_name_email(app_, mocker):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.feedback.requests.post',
|
||||||
|
return_value=Mock(status_code=201))
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
||||||
|
assert resp.status_code == 302
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_feedback_with_no_name_email(app_, mocker):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.feedback.requests.post',
|
||||||
|
return_value=Mock(status_code=201))
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
||||||
|
assert resp.status_code == 302
|
||||||
|
mock_post.assert_called_with(
|
||||||
|
ANY,
|
||||||
|
data={
|
||||||
|
'department_id': ANY,
|
||||||
|
'subject': 'Notify feedback',
|
||||||
|
'message': '\n\nblah',
|
||||||
|
'person_email': ANY},
|
||||||
|
headers=ANY)
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_feedback_with_name_email(app_, mocker):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.feedback.requests.post',
|
||||||
|
return_value=Mock(status_code=201))
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
resp = client.post(
|
||||||
|
url_for('main.feedback'),
|
||||||
|
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
||||||
|
assert resp.status_code == 302
|
||||||
|
mock_post.assert_called_with(
|
||||||
|
ANY,
|
||||||
|
data={
|
||||||
|
'subject': 'Notify feedback',
|
||||||
|
'department_id': ANY,
|
||||||
|
'message': 'Steve Irwin\nrip@gmail.com\nblah',
|
||||||
|
'person_email': ANY},
|
||||||
|
headers=ANY)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_error_on_post(app_, mocker):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.feedback.requests.post',
|
||||||
|
return_value=Mock(
|
||||||
|
status_code=401,
|
||||||
|
json=lambda: {
|
||||||
|
'error_code': 'invalid_auth',
|
||||||
|
'error_message': 'Please provide a valid API key or token'}))
|
||||||
|
with app_.test_request_context():
|
||||||
|
mock_logger = mocker.patch.object(app_.logger, 'error')
|
||||||
|
with app_.test_client() as client:
|
||||||
|
with pytest.raises(InternalServerError):
|
||||||
|
resp = client.post(
|
||||||
|
url_for('main.feedback'),
|
||||||
|
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
||||||
|
mock_post.assert_called_with(
|
||||||
|
ANY,
|
||||||
|
data={
|
||||||
|
'subject': 'Notify feedback',
|
||||||
|
'department_id': ANY,
|
||||||
|
'message': 'Steve Irwin\nrip@gmail.com\nblah',
|
||||||
|
'person_email': ANY},
|
||||||
|
headers=ANY)
|
||||||
|
mock_logger.assert_called_with(
|
||||||
|
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from flask import (url_for, current_app)
|
from flask import url_for
|
||||||
from werkzeug.exceptions import InternalServerError
|
|
||||||
from unittest.mock import Mock, ANY
|
|
||||||
|
|
||||||
|
|
||||||
def test_logged_in_user_redirects_to_choose_service(app_,
|
def test_logged_in_user_redirects_to_choose_service(app_,
|
||||||
@@ -17,85 +15,3 @@ def test_logged_in_user_redirects_to_choose_service(app_,
|
|||||||
|
|
||||||
response = client.get(url_for('main.sign_in', follow_redirects=True))
|
response = client.get(url_for('main.sign_in', follow_redirects=True))
|
||||||
assert response.location == url_for('main.choose_service', _external=True)
|
assert response.location == url_for('main.choose_service', _external=True)
|
||||||
|
|
||||||
|
|
||||||
def test_get_feedback_page(app_):
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
resp = client.get(url_for('main.feedback'))
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
|
||||||
mock_post = mocker.patch(
|
|
||||||
'app.main.views.index.requests.post',
|
|
||||||
return_value=Mock(status_code=201))
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
|
||||||
assert resp.status_code == 302
|
|
||||||
|
|
||||||
|
|
||||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
|
||||||
mock_post = mocker.patch(
|
|
||||||
'app.main.views.index.requests.post',
|
|
||||||
return_value=Mock(status_code=201))
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
|
||||||
assert resp.status_code == 302
|
|
||||||
mock_post.assert_called_with(
|
|
||||||
ANY,
|
|
||||||
data={
|
|
||||||
'department_id': ANY,
|
|
||||||
'subject': 'Notify feedback',
|
|
||||||
'message': '\n\nblah',
|
|
||||||
'person_email': ANY},
|
|
||||||
headers=ANY)
|
|
||||||
|
|
||||||
|
|
||||||
def test_post_feedback_with_name_email(app_, mocker):
|
|
||||||
mock_post = mocker.patch(
|
|
||||||
'app.main.views.index.requests.post',
|
|
||||||
return_value=Mock(status_code=201))
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
resp = client.post(
|
|
||||||
url_for('main.feedback'),
|
|
||||||
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
|
||||||
assert resp.status_code == 302
|
|
||||||
mock_post.assert_called_with(
|
|
||||||
ANY,
|
|
||||||
data={
|
|
||||||
'subject': 'Notify feedback',
|
|
||||||
'department_id': ANY,
|
|
||||||
'message': 'Steve Irwin\nrip@gmail.com\nblah',
|
|
||||||
'person_email': ANY},
|
|
||||||
headers=ANY)
|
|
||||||
|
|
||||||
|
|
||||||
def test_log_error_on_post(app_, mocker):
|
|
||||||
mock_post = mocker.patch(
|
|
||||||
'app.main.views.index.requests.post',
|
|
||||||
return_value=Mock(
|
|
||||||
status_code=401,
|
|
||||||
json=lambda: {
|
|
||||||
'error_code': 'invalid_auth',
|
|
||||||
'error_message': 'Please provide a valid API key or token'}))
|
|
||||||
with app_.test_request_context():
|
|
||||||
mock_logger = mocker.patch.object(app_.logger, 'error')
|
|
||||||
with app_.test_client() as client:
|
|
||||||
with pytest.raises(InternalServerError):
|
|
||||||
resp = client.post(
|
|
||||||
url_for('main.feedback'),
|
|
||||||
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
|
||||||
mock_post.assert_called_with(
|
|
||||||
ANY,
|
|
||||||
data={
|
|
||||||
'subject': 'Notify feedback',
|
|
||||||
'department_id': ANY,
|
|
||||||
'message': 'Steve Irwin\nrip@gmail.com\nblah',
|
|
||||||
'person_email': ANY},
|
|
||||||
headers=ANY)
|
|
||||||
mock_logger.assert_called_with(
|
|
||||||
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
import pytest
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app.utils import email_safe
|
from app.utils import email_safe
|
||||||
from tests import validate_route_permission
|
from tests import validate_route_permission
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY, Mock
|
||||||
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_overview(app_,
|
def test_should_show_overview(app_,
|
||||||
@@ -212,36 +214,74 @@ def test_should_show_request_to_go_live(app_,
|
|||||||
assert mock_get_service.called
|
assert mock_get_service.called
|
||||||
|
|
||||||
|
|
||||||
def test_should_redirect_after_request_to_go_live(app_,
|
def test_should_redirect_after_request_to_go_live(
|
||||||
api_user_active,
|
app_,
|
||||||
mock_get_service,
|
api_user_active,
|
||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_service,
|
||||||
mock_login,
|
mock_has_permissions,
|
||||||
mock_has_permissions,
|
mocker
|
||||||
fake_uuid):
|
):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.feedback.requests.post',
|
||||||
|
return_value=Mock(status_code=201))
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = fake_uuid
|
response = client.post(
|
||||||
response = client.post(url_for(
|
url_for('main.service_request_to_go_live', service_id='6ce466d0-fd6a-11e5-82f5-e0accb9d11a6'),
|
||||||
'main.service_request_to_go_live', service_id=service_id))
|
data={'usage': "One million messages"},
|
||||||
|
follow_redirects=True
|
||||||
assert response.status_code == 302
|
)
|
||||||
settings_url = url_for(
|
assert response.status_code == 200
|
||||||
'main.service_settings', service_id=service_id, _external=True)
|
mock_post.assert_called_with(
|
||||||
assert settings_url == response.location
|
ANY,
|
||||||
assert mock_get_service.called
|
data={
|
||||||
|
'subject': 'Request to go live',
|
||||||
with app_.test_client() as client:
|
'department_id': ANY,
|
||||||
client.login(api_user_active)
|
'message': 'From Test User <test@user.gov.uk> on behalf of Test Service (6ce466d0-fd6a-11e5-82f5-e0accb9d11a6)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
||||||
service_id = fake_uuid
|
'person_email': ANY
|
||||||
response = client.post(url_for(
|
},
|
||||||
'main.service_request_to_go_live', service_id=service_id), follow_redirects=True)
|
headers=ANY
|
||||||
|
)
|
||||||
|
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
flash_banner = page.find('div', class_='banner-default').string.strip()
|
flash_banner = page.find('div', class_='banner-default').string.strip()
|
||||||
assert flash_banner == 'Thanks your request to go live is being processed'
|
h1 = page.find('h1').string.strip()
|
||||||
|
assert flash_banner == 'We’ve received your request to go live'
|
||||||
|
assert h1 == 'Settings'
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_error_on_request_to_go_live(
|
||||||
|
app_,
|
||||||
|
api_user_active,
|
||||||
|
mock_get_user,
|
||||||
|
mock_get_service,
|
||||||
|
mock_has_permissions,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
mock_post = mocker.patch(
|
||||||
|
'app.main.views.service_settings.requests.post',
|
||||||
|
return_value=Mock(
|
||||||
|
status_code=401,
|
||||||
|
json=lambda: {
|
||||||
|
'error_code': 'invalid_auth',
|
||||||
|
'error_message': 'Please provide a valid API key or token'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
with app_.test_request_context():
|
||||||
|
mock_logger = mocker.patch.object(app_.logger, 'error')
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(api_user_active)
|
||||||
|
with pytest.raises(InternalServerError):
|
||||||
|
resp = client.post(
|
||||||
|
url_for('main.service_request_to_go_live', service_id='6ce466d0-fd6a-11e5-82f5-e0accb9d11a6'),
|
||||||
|
data={'usage': 'blah'}
|
||||||
|
)
|
||||||
|
mock_logger.assert_called_with(
|
||||||
|
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_status_page(app_,
|
def test_should_show_status_page(app_,
|
||||||
|
|||||||
Reference in New Issue
Block a user