From b75ab7c3df5d82c45fbc51f90399994dff8dd0ef Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 19 Apr 2016 10:54:26 +0100 Subject: [PATCH] Make new service current service on first use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When you add a new service, it’s probably the one you want to do stuff with. When you get invited, the service you’ve been invited to is probably the one you want to use. This commit adds the ID of the new service or service you’ve been invited to to the session. --- app/main/views/add_service.py | 2 +- app/main/views/dashboard.py | 1 + tests/app/main/views/test_accept_invite.py | 4 ++-- tests/app/main/views/test_add_service.py | 19 +++++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 432eee2ea..e8610f822 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -42,7 +42,7 @@ def add_service(): restricted=True, user_id=session['user_id'], email_from=email_from) - + session['service_id'] = service_id return redirect(url_for('main.tour', page=1)) else: return render_template( diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 7271a32bf..df5076e82 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -34,6 +34,7 @@ def service_dashboard(service_id): if session.get('invited_user'): session.pop('invited_user', None) + session['service_id'] = service_id return redirect(url_for("main.tour", page=1)) statistics = statistics_api_client.get_statistics_for_service(service_id)['data'] diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index 7cfbd8142..740888484 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -1,4 +1,4 @@ -from flask import url_for +from flask import url_for, session from bs4 import BeautifulSoup @@ -372,8 +372,8 @@ def test_new_invited_user_verifies_and_added_to_service(app_, mock_add_user_to_service.assert_called_with(data['service'], new_user_id, expected_permissions) mock_accept_invite.assert_called_with(data['service'], sample_invite['id']) mock_check_verify_code.assert_called_once_with(new_user_id, '12345', 'sms') + assert service_one['id'] == session['service_id'] raw_html = response.data.decode('utf-8') page = BeautifulSoup(raw_html, 'html.parser') element = page.find('h2').text == 'Trial mode' - assert service_one['id'] in raw_html diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 32e110b5c..bb6eb3f76 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -1,4 +1,4 @@ -from flask import url_for +from flask import url_for, session import app @@ -25,15 +25,18 @@ def test_should_add_service_and_redirect_to_next_page(app_, response = client.post( url_for('main.add_service'), data={'name': 'testing the post'}) + assert mock_get_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) - assert mock_get_services.called - mock_create_service.asset_called_once_with(service_name='testing the post', - active=False, - limit=app_.config['DEFAULT_SERVICE_LIMIT'], - restricted=True, - user_id=api_user_active.id, - email_from='testing.the.post') def test_should_return_form_errors_when_service_name_is_empty(app_,