mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 13:18:57 -04:00
Feedback page working with all tests passing.
Updated to include team id. Give Feedback -> Give feedback
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from flask import url_for
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from unittest.mock import ANY
|
||||
|
||||
import app
|
||||
|
||||
@@ -255,7 +256,6 @@ def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(a
|
||||
assert response.status_code == 302
|
||||
assert response.location == expected_redirect_location
|
||||
|
||||
from unittest.mock import ANY
|
||||
mock_send_verify_code.assert_called_once_with(ANY, 'sms', data['mobile_number'])
|
||||
|
||||
mock_register_user.assert_called_with(data['name'],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
from flask import url_for
|
||||
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_,
|
||||
@@ -14,3 +17,85 @@ def test_logged_in_user_redirects_to_choose_service(app_,
|
||||
|
||||
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.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={
|
||||
'agent_team_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',
|
||||
'agent_team_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',
|
||||
'agent_team_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()))
|
||||
|
||||
Reference in New Issue
Block a user