mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 17:19:48 -04:00
Redirect to dashboard if this isn't the first service
There's no need to show the tour again if the user has previously created a service so just redirect to the dashboard instead.
This commit is contained in:
@@ -43,7 +43,12 @@ def add_service():
|
|||||||
user_id=session['user_id'],
|
user_id=session['user_id'],
|
||||||
email_from=email_from)
|
email_from=email_from)
|
||||||
session['service_id'] = service_id
|
session['service_id'] = service_id
|
||||||
return redirect(url_for('main.tour', page=1))
|
|
||||||
|
services = service_api_client.get_services({'user_id': session['user_id']}).get('data', [])
|
||||||
|
if (len(services) > 1):
|
||||||
|
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||||||
|
else:
|
||||||
|
return redirect(url_for('main.tour', page=1))
|
||||||
else:
|
else:
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/add-service.html',
|
'views/add-service.html',
|
||||||
|
|||||||
@@ -14,11 +14,36 @@ def test_get_should_render_add_service_template(app_,
|
|||||||
assert 'Which service do you want to set up notifications for?' in response.get_data(as_text=True)
|
assert 'Which service do you want to set up notifications for?' in response.get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
def test_should_add_service_and_redirect_to_next_page(app_,
|
def test_should_add_service_and_redirect_to_tour_when_no_services(app_,
|
||||||
mocker,
|
mocker,
|
||||||
mock_create_service,
|
mock_create_service,
|
||||||
mock_get_services,
|
mock_get_services_with_no_services,
|
||||||
api_user_active):
|
api_user_active):
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(api_user_active, mocker)
|
||||||
|
response = client.post(
|
||||||
|
url_for('main.add_service'),
|
||||||
|
data={'name': 'testing the post'})
|
||||||
|
assert mock_get_services_with_no_services.called
|
||||||
|
mock_create_service.assert_called_once_with(
|
||||||
|
service_name='testing the post',
|
||||||
|
active=False,
|
||||||
|
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
||||||
|
restricted=True,
|
||||||
|
user_id=api_user_active.id,
|
||||||
|
email_from='testing.the.post'
|
||||||
|
)
|
||||||
|
assert session['service_id'] == 101
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == url_for('main.tour', page=1, _external=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(app_,
|
||||||
|
mocker,
|
||||||
|
mock_create_service,
|
||||||
|
mock_get_services,
|
||||||
|
api_user_active):
|
||||||
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, mocker)
|
client.login(api_user_active, mocker)
|
||||||
@@ -36,7 +61,7 @@ def test_should_add_service_and_redirect_to_next_page(app_,
|
|||||||
)
|
)
|
||||||
assert session['service_id'] == 101
|
assert session['service_id'] == 101
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.tour', page=1, _external=True)
|
assert response.location == url_for('main.service_dashboard', service_id=101, _external=True)
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_form_errors_when_service_name_is_empty(app_,
|
def test_should_return_form_errors_when_service_name_is_empty(app_,
|
||||||
|
|||||||
@@ -147,6 +147,18 @@ def mock_get_services(mocker, fake_uuid, user=None):
|
|||||||
'app.service_api_client.get_services', side_effect=_create)
|
'app.service_api_client.get_services', side_effect=_create)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_services_with_no_services(mocker, fake_uuid, user=None):
|
||||||
|
if user is None:
|
||||||
|
user = active_user_with_permissions(fake_uuid)
|
||||||
|
|
||||||
|
def _create(user_id=None):
|
||||||
|
return {'data': []}
|
||||||
|
|
||||||
|
return mocker.patch(
|
||||||
|
'app.service_api_client.get_services', side_effect=_create)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_services_with_one_service(mocker, fake_uuid, user=None):
|
def mock_get_services_with_one_service(mocker, fake_uuid, user=None):
|
||||||
if user is None:
|
if user is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user