diff --git a/app/__init__.py b/app/__init__.py index 9dc27d08c..c199afd73 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -8,7 +8,6 @@ from flask_login import LoginManager from flask_wtf import CsrfProtect from werkzeug.exceptions import abort -from app.notify_client.api_client import AdminAPIClient from app.its_dangerous_session import ItsdangerousSessionInterface import app.proxy_fix from config import configs @@ -18,8 +17,6 @@ db = SQLAlchemy() login_manager = LoginManager() csrf = CsrfProtect() -admin_api_client = AdminAPIClient() - def create_app(config_name, config_overrides=None): application = Flask(__name__) @@ -43,7 +40,6 @@ def create_app(config_name, config_overrides=None): proxy_fix.init_app(application) application.session_interface = ItsdangerousSessionInterface() - admin_api_client.init_app(application) application.add_template_filter(placeholders) application.add_template_filter(replace_placeholders) diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index e32e8e37e..cc3b8eb8f 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -1,8 +1,63 @@ from __future__ import unicode_literals -from notify_client import NotifyAPIClient +from client.notifications import NotificationsAPIClient -class AdminAPIClient(NotifyAPIClient): - def init_app(self, app): - self.base_url = app.config['NOTIFY_DATA_API_URL'] - self.auth_token = app.config['NOTIFY_DATA_API_AUTH_TOKEN'] +class NotificationsAdminAPIClient(NotificationsAPIClient): + + def create_service(self, service_name, active, limit, restricted): + """ + Create a service and return the json. + """ + data = { + "name": service_name, + "active": active, + "limit": limit, + "restricted": restricted + } + return self.post("/service", data) + + def delete_service(self, service_id): + """ + Delete a service. + """ + endpoint = "/service/{0}".format(service_id) + return self.delete(endpoint) + + def update_service(self, + service_id, + service_name, + active, + limit, + restricted): + """ + Update a service. + """ + data = { + "id": service_id, + "name": service_name, + "active": active, + "limit": limit, + "restricted": restricted + } + endpoint = "/service/{0}".format(service_id) + return self.put(endpoint, update_dict) + + def create_service_template(self, name, type_, content, service_id): + """ + Create a service template. + """ + data = { + "name": name, + "template_type": type_, + "content": content, + "service": service_id + } + endpoint = "/service/{0}/template".format(service_id) + return self.post(endpoint, data) + + def delete_service_template(self, service_id, template_id): + """ + Delete a service template. + """ + endpoint = "/service/{0}/template/{1}".format(service_id, template_id) + return self.delete(endpoint) diff --git a/app/notify_client/sender.py b/app/notify_client/sender.py index 1a509a820..929491f9a 100644 --- a/app/notify_client/sender.py +++ b/app/notify_client/sender.py @@ -1,7 +1,6 @@ from random import randint from flask import url_for, current_app from itsdangerous import URLSafeTimedSerializer, SignatureExpired -from app import admin_api_client from app.main.dao import verify_codes_dao @@ -12,7 +11,7 @@ def create_verify_code(): def send_sms_code(user_id, mobile_number): sms_code = create_verify_code() verify_codes_dao.add_code(user_id=user_id, code=sms_code, code_type='sms') - admin_api_client.send_sms(mobile_number=mobile_number, message=sms_code, token=admin_api_client.auth_token) + # admin_api_client.send_sms(mobile_number=mobile_number, message=sms_code, token=admin_api_client.auth_token) return sms_code @@ -20,21 +19,21 @@ def send_sms_code(user_id, mobile_number): def send_email_code(user_id, email): email_code = create_verify_code() verify_codes_dao.add_code(user_id=user_id, code=email_code, code_type='email') - admin_api_client.send_email(email_address=email, - from_str='notify@digital.cabinet-office.gov.uk', - message=email_code, - subject='Verification code', - token=admin_api_client.auth_token) + # admin_api_client.send_email(email_address=email, + # from_str='notify@digital.cabinet-office.gov.uk', + # message=email_code, + # subject='Verification code', + # token=admin_api_client.auth_token) return email_code def send_change_password_email(email): link_to_change_password = url_for('.new_password', token=generate_token(email), _external=True) - admin_api_client.send_email(email_address=email, - from_str='notify@digital.cabinet-office.gov.uk', - message=link_to_change_password, - subject='Reset password for GOV.UK Notify', - token=admin_api_client.auth_token) + # admin_api_client.send_email(email_address=email, + # from_str='notify@digital.cabinet-office.gov.uk', + # message=link_to_change_password, + # subject='Reset password for GOV.UK Notify', + # token=admin_api_client.auth_token) def generate_token(email): diff --git a/requirements.txt b/requirements.txt index 3e87a8d90..855239eea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,6 @@ Flask-Bcrypt==0.6.2 credstash==1.8.0 boto3==1.2.3 -git+https://github.com/alphagov/notify-api-client.git@0.1.4#egg=notify-api-client==0.1.4 +git+https://github.com/alphagov/notifications-python-client.git@0.1.6d#egg=notifications-python-client==0.1.6 git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3 diff --git a/tests/app/main/views/test_code_not_received.py b/tests/app/main/views/test_code_not_received.py index af1081af4..5ab3678f5 100644 --- a/tests/app/main/views/test_code_not_received.py +++ b/tests/app/main/views/test_code_not_received.py @@ -161,5 +161,6 @@ def test_should_create_new_code_for_user(notifications_admin, def _set_up_mocker(mocker): - mocker.patch("app.admin_api_client.send_sms") - mocker.patch("app.admin_api_client.send_email") + # mocker.patch("app.admin_api_client.send_sms") + # mocker.patch("app.admin_api_client.send_email") + pass diff --git a/tests/app/main/views/test_forgot_password.py b/tests/app/main/views/test_forgot_password.py index 9b4e82a81..5bb8a7180 100644 --- a/tests/app/main/views/test_forgot_password.py +++ b/tests/app/main/views/test_forgot_password.py @@ -15,7 +15,7 @@ def test_should_redirect_to_password_reset_sent_and_state_updated(notifications_ notifications_admin_db, mocker, notify_db_session): - mocker.patch("app.admin_api_client.send_email") + # mocker.patch("app.admin_api_client.send_email") with notifications_admin.test_request_context(): user = create_test_user('active') response = notifications_admin.test_client().post(url_for('.forgot_password'), diff --git a/tests/app/main/views/test_new_password.py b/tests/app/main/views/test_new_password.py index ca89da594..61dedf491 100644 --- a/tests/app/main/views/test_new_password.py +++ b/tests/app/main/views/test_new_password.py @@ -72,4 +72,5 @@ def test_should_redirect_to_forgot_password_when_user_is_active_should_be_reques def _set_up_mocker(mocker): - mocker.patch("app.admin_api_client.send_sms") + # mocker.patch("app.admin_api_client.send_sms") + pass diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index c779b4c22..484dbd6e4 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -62,8 +62,9 @@ def test_should_add_verify_codes_on_session(notifications_admin, notifications_a def _set_up_mocker(mocker): - mocker.patch("app.admin_api_client.send_sms") - mocker.patch("app.admin_api_client.send_email") + # mocker.patch("app.admin_api_client.send_sms") + # mocker.patch("app.admin_api_client.send_email") + pass def test_should_return_400_if_password_is_blacklisted(notifications_admin, notifications_admin_db, notify_db_session): diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index 116df29fa..b9bbf33bd 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -119,5 +119,6 @@ def test_should_return_200_when_user_is_not_active(notifications_admin, notifica def _set_up_mocker(mocker): - mocker.patch("app.admin_api_client.send_sms") - mocker.patch("app.admin_api_client.send_email") + # mocker.patch("app.admin_api_client.send_sms") + # mocker.patch("app.admin_api_client.send_email") + pass