From c43fde0ac023712427814c79304f5f6fd4bc07bb Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Mon, 22 Aug 2016 16:35:14 +0100 Subject: [PATCH 1/5] For the brief moment when we have incompatible API versions out, We won't call template stats by template id as the format has changed. So just ask the question "do you want to delete" without the context. --- app/main/views/templates.py | 4 +--- tests/app/main/views/test_templates.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 6711e29fd..17183f671 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -186,9 +186,7 @@ def delete_service_template(service_id, template_id): template['template_content'] = template['content'] form = form_objects[template['template_type']](**template) - template_statistics = template_statistics_client.get_template_statistics_for_template(service_id, template['id']) - last_use_message = get_last_use_message(form.name.data, template_statistics) - flash('{}. Are you sure you want to delete it?'.format(last_use_message), 'delete') + flash('Are you sure you want to delete it?', 'delete') return render_template( 'views/edit-{}-template.html'.format(template['template_type']), h1='Edit template', diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 009b7f08f..8f296c653 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -249,7 +249,6 @@ def test_should_show_delete_template_page(app_, assert 'Two week reminder' in content assert 'Your vehicle tax is about to expire' in content mock_get_service_template.assert_called_with(service_id, template_id) - mock_get_template_statistics_for_template.assert_called_with(service_id, template_id) def test_should_redirect_when_deleting_a_template(app_, From 0f6a090470530fc7c1504cc6160ff77535c82fbc Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 23 Aug 2016 10:15:22 +0100 Subject: [PATCH 2/5] Fix admin app putting service into research mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We changed the `update_service` method to only update indivdual attributes of a service, and only allow it to update specified attributes: https://github.com/alphagov/notifications-admin/commit/0cfe10639a0018553080885569b4ba125341122d We neglected to specify `research_mode` as one of the allowed attributes. This broke the app’s ability to put a service in or out of research mode. This commit: - makes sure the tests cover this eventuality - fixes the bug by specifying `research_mode` as one of the allowed attributes --- app/notify_client/service_api_client.py | 1 + tests/app/main/views/test_service_settings.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 0e67f28ca..db837e53c 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -89,6 +89,7 @@ class ServiceAPIClient(NotificationsAPIClient): 'restricted', 'email_from', 'reply_to_email_address', + 'research_mode', 'sms_sender', 'created_by', 'branding', diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 8b214b647..6b54934ed 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -602,14 +602,18 @@ def test_switch_service_to_research_mode( mocker): with app_.test_request_context(): with app_.test_client() as client: - mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one) + mocker.patch('app.service_api_client.post', return_value=service_one) client.login(active_user_with_permissions) response = client.get(url_for('main.service_switch_research_mode', service_id=service_one['id'])) assert response.status_code == 302 assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True) - app.service_api_client.update_service_with_properties.assert_called_with( - service_one['id'], {"research_mode": True} + app.service_api_client.post.assert_called_with( + '/service/{}'.format(service_one['id']), + { + 'research_mode': True, + 'created_by': active_user_with_permissions.id + } ) From f8db73ecc7cc09e69d3d11a7c2c4a30fa91ca89f Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 23 Aug 2016 10:16:05 +0100 Subject: [PATCH 3/5] Reduce uneccessary indentation --- tests/app/main/views/test_service_settings.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 6b54934ed..77817e033 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -592,29 +592,29 @@ def test_if_reply_to_email_address_set_then_form_populated(app_, def test_switch_service_to_research_mode( - app_, - service_one, - mock_login, - mock_get_user, - active_user_with_permissions, - mock_get_service, - mock_has_permissions, - mocker): - with app_.test_request_context(): - with app_.test_client() as client: - mocker.patch('app.service_api_client.post', return_value=service_one) + app_, + service_one, + mock_login, + mock_get_user, + active_user_with_permissions, + mock_get_service, + mock_has_permissions, + mocker +): + with app_.test_request_context(), app_.test_client() as client: + mocker.patch('app.service_api_client.post', return_value=service_one) - client.login(active_user_with_permissions) - response = client.get(url_for('main.service_switch_research_mode', service_id=service_one['id'])) - assert response.status_code == 302 - assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True) - app.service_api_client.post.assert_called_with( - '/service/{}'.format(service_one['id']), - { - 'research_mode': True, - 'created_by': active_user_with_permissions.id - } - ) + client.login(active_user_with_permissions) + response = client.get(url_for('main.service_switch_research_mode', service_id=service_one['id'])) + assert response.status_code == 302 + assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True) + app.service_api_client.post.assert_called_with( + '/service/{}'.format(service_one['id']), + { + 'research_mode': True, + 'created_by': active_user_with_permissions.id + } + ) def test_switch_service_from_research_mode_to_normal( From d7324136ae2d94cd6353e3dc261a4a3890a0c5e7 Mon Sep 17 00:00:00 2001 From: bandesz Date: Tue, 23 Aug 2016 13:35:21 +0100 Subject: [PATCH 4/5] Fix version file generation, remove master deploys from travis --- .travis.yml | 20 -------------------- Makefile | 6 ++++++ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a0a62f10..5f3ba9161 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,26 +26,6 @@ notifications: rooms: secure: A6n6Gdz3dsE+KQcOd1nWTvdjOF2YbgItT1E40r25poG6p04WHd8qWtC4T2FuZaxPN/TQdKr/dKa/WCkmiEdxT5O0SOwAnAD3u6Fn2nthoI4M5916UrK1ZrqupvnFPSQc8Ivh51PGkcmB4wrb0ylRhMB94RmLcUZcVuXLDx57GO8bPFy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XOsH0kzILl7EzvUoBIbFf8+/1EDmvMc88J5yg4QCmVnIhw5JqnC1uQyDUy41VOsdqgwVUHy7hJuXtKMnUSYuDOltP2fdkArLby0VFgcQgoT+N87I4xcjVzLjEvNgwlZ1nHuBf9v+aB0aD9e/LB03gIt23Nrucu9ON1M= - local_dir: dpl_cd_upload - skip_cleanup: true - region: eu-west-1 - on: &2 - repo: alphagov/notifications-admin - bucket: notify.works-notifications-admin-codedeploy -- provider: codedeploy - access_key_id: AKIAJLWYN4T4D5WU4APA - secret_access_key: *1 - bucket: notify.works-notifications-admin-codedeploy - key: notifications-admin-$TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER-$TRAVIS_COMMIT.zip - bundle_type: zip - application: admin - deployment_group: notifications_admin_deployment_group - region: eu-west-1 - on: *2 - provider: s3 access_key_id: AKIAJCOSRR7IFXS2WJUA secret_access_key: &1 diff --git a/Makefile b/Makefile index f046f9c04..37a19a736 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,9 @@ build-with-docker: prepare-docker-build-image ## Build inside a Docker container --name "${DOCKER_CONTAINER_PREFIX}-build" \ -v `pwd`:/var/project \ -v ${PIP_ACCEL_CACHE}:/var/project/cache/pip-accel \ + -e GIT_COMMIT=${GIT_COMMIT} \ + -e BUILD_NUMBER=${BUILD_NUMBER} \ + -e BUILD_URL=${BUILD_URL} \ ${DOCKER_BUILDER_IMAGE_NAME} \ make build @@ -109,6 +112,9 @@ test-with-docker: prepare-docker-build-image ## Run tests inside a Docker contai docker run -i --rm \ --name "${DOCKER_CONTAINER_PREFIX}-test" \ -v `pwd`:/var/project \ + -e GIT_COMMIT=${GIT_COMMIT} \ + -e BUILD_NUMBER=${BUILD_NUMBER} \ + -e BUILD_URL=${BUILD_URL} \ ${DOCKER_BUILDER_IMAGE_NAME} \ make test From 62605a2ed530360e0c20121eaa8b1b5135573301 Mon Sep 17 00:00:00 2001 From: bandesz Date: Tue, 23 Aug 2016 16:45:40 +0100 Subject: [PATCH 5/5] Disable Travis deploys for staging --- .travis.yml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f3ba9161..b8a69bb8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,27 +26,6 @@ notifications: rooms: secure: A6n6Gdz3dsE+KQcOd1nWTvdjOF2YbgItT1E40r25poG6p04WHd8qWtC4T2FuZaxPN/TQdKr/dKa/WCkmiEdxT5O0SOwAnAD3u6Fn2nthoI4M5916UrK1ZrqupvnFPSQc8Ivh51PGkcmB4wrb0ylRhMB94RmLcUZcVuXLDx57GO8bPFyLC3E9bgcVVFWaX45sKs74sBSQWi9EBbzHIuduLdjIpW7wX07dA++HlY14W5WgiurmiYohfP11VdAMmMxJs2WdWk16O/qy0HZXaldNIsSnuDBkhAZOMeSrcvp+62yOiN8jK0nSa1IRr3IoUkITdC9YGys3xFJb8gyIQE9T3hUnTYAKCcgsgpVFS6UzsRN42JUAJ8rFTgK9/J299yTk4lqL8uWzcV1QcKXIPNoG0QfqkmlB9B1fKbXuE/KkPEXPCKAcVQpCzEon09FgTCrlVZqJ6HxQonnLcPlIpVzWHAFokLZVHLAFMKYJnGBcZ6zaRK5pdc1babcOXMIPBC8j028G5bhBaCviDvZlimxOsUK1sJTpjzMU0tBQZa8lI+0O5otvMKiX8jPyaedjVvUmsftF2O5FH5nz2ofJC7BThb76/Tac2pNTCn0pWiVz9wi/YXALOMdIzkYgHnyZdEqAjRlpFwZuOrzR6MuvivBebPxjYaRWzCjOeC1uIwz+48E= deploy: -- provider: s3 - access_key_id: AKIAJCOSRR7IFXS2WJUA - secret_access_key: &1 - secure: LBprDWBFawNvG9M0AVHJkS0txP4IapXG6K8OIzY6T3yDJP8vTnN6M34C++AprkZEqehzug36Vms5PVv9p2gkJOjZkwBKMRFZtjdxGXfRaZnbGQgcBbleMhdXsDWlGJm7RnMS/SX79tiezQ2h6GYyb96vBT0mdfyo/OPr5HJ6IWa/fblUXzZF1a5kCvP2uvR+nXKutsfNnP7lFzrFiH6efyeI1XPD18TU7Nuy6xOZDkDlX2RAvq+Qe5zX0o7VzXFkFdf7NfVT7AswoAEEVZeWNrm84oQJsH88QymDgpdLLzAlwmrWHDTGQtRCOQvXWhK6HvZMgP9n4EcWSIq4WMCjXMcnUqW6mvB+dBjJEe3I+oVgf1TWpdCSAWyffkJ805/xSF/BP92KHg8PAYJKlzrpHWuHaysf05a0QyKsFW09SzzQbpMrs0KLErqOLbG9NKZ5MaUepnsMyuKTr3shysNzlbcC5TghpGQO+D2yj/cJYmKp835Nx9tSU49woDbMDycdgF0rIczfwM8+OrywPw4fY6NAir6uAGx3aYrCx2BNEsGW4tjY7ab8EGCk4pgWpBw1/ERclA6D5sx7ppLI3wnVKsUyPUDvjOFjqdWkBrsONM4xHENRyaJupzQEuzJt/nxtHHGsayyKqYWT24+6ira8p4vJVqnJ+qBM3C7IYVIVXM8= - local_dir: dpl_cd_upload - skip_cleanup: true - region: eu-west-1 - on: &2 - repo: alphagov/notifications-admin - branch: staging - bucket: staging-notify.works-notifications-admin-codedeploy -- provider: codedeploy - access_key_id: AKIAJCOSRR7IFXS2WJUA - secret_access_key: *1 - bucket: staging-notify.works-notifications-admin-codedeploy - key: notifications-admin-$TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER-$TRAVIS_COMMIT.zip - bundle_type: zip - application: admin - deployment_group: notifications_admin_deployment_group - region: eu-west-1 - on: *2 - provider: s3 access_key_id: AKIAIFLN7IJIIQT6S37Q secret_access_key: &1