From e73e4ac9346e4a1faa4afede64f2333cad0b766a Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Tue, 19 Jan 2016 17:23:17 +0000 Subject: [PATCH 1/4] Use new version of client. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a699a09ab..0201307fc 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/notifications-python-client.git@0.1.6#egg=notifications-python-client==0.1.6 +git+https://github.com/alphagov/notifications-python-client.git@0.1.7#egg=notifications-python-client==0.1.7 git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3 From 4a73e9315c3d66e38e4b2cbd16f7a4e0c0c55c00 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Wed, 20 Jan 2016 09:46:48 +0000 Subject: [PATCH 2/4] Implemented send_sms from client. --- app/notify_client/api_client.py | 18 ++++++++++++++++-- requirements.txt | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index 50217721b..df33884c5 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -12,7 +12,7 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): "secret") def init_app(self, application): - self.base_url = application.config['NOTIFY_API_URL'] + self.base_url = application.config['API_HOST_NAME'] self.client_id = application.config['NOTIFY_API_CLIENT'] self.secret = application.config['NOTIFY_API_SECRET'] @@ -83,6 +83,20 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): endpoint = "/service/{0}/template".format(service_id) return self.post(endpoint, data) + def update_service_template(self, id_, name, type_, content, service_id): + """ + Update a service template. + """ + data = { + 'id': id_, + 'name': name, + 'template_type': type_, + 'content': content, + 'service': service_id + } + endpoint = "/service/{0}/template/{1}".format(service_id, id_) + return self.put(endpoint, data) + def get_service_template(self, service_id, template_id, *params): """ Retrieve a service template. @@ -114,7 +128,7 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): message, job_id=None, description=None): - pass + self.send_sms_notification(mobile_number, message) def send_email(self, email_address, diff --git a/requirements.txt b/requirements.txt index 0201307fc..b3657eab5 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/notifications-python-client.git@0.1.7#egg=notifications-python-client==0.1.7 +git+https://github.com/alphagov/notifications-python-client.git@0.1.8#egg=notifications-python-client==0.1.8 git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3 From 2cc9dc6995a422b66f461ca84371834dd7cda57d Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Wed, 20 Jan 2016 11:46:39 +0000 Subject: [PATCH 3/4] Work in progress. --- app/main/forms.py | 6 ++++-- app/main/views/add_service.py | 2 +- app/notify_client/api_client.py | 9 ++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index df9515a5c..bb235d064 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -61,8 +61,10 @@ class UKMobileNumber(StringField): if len(self.data) != 9: return - - self.data = '+44 7{} {} {}'.format(*re.findall('...', self.data)) + # TODO implement in the render field method. + # API's require no spaces in the number + #self.data = '+44 7{} {} {}'.format(*re.findall('...', self.data)) + self.data = '+447{}{}{}'.format(*re.findall('...', self.data)) def mobile_number(): diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 7402ab497..3d01a005f 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -16,7 +16,7 @@ def add_service(): heading = 'Add a new service' if form.validate_on_submit(): user = users_dao.get_user_by_id(session['user_id']) - service_id = services_dao.insert_new_service(form.name.data, user) + service_id = services_dao.insert_new_service(form.name.data, user.id) return redirect(url_for('main.service_dashboard', service_id=service_id)) else: return render_template( diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index df33884c5..c60afc3d2 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -13,8 +13,8 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): def init_app(self, application): self.base_url = application.config['API_HOST_NAME'] - self.client_id = application.config['NOTIFY_API_CLIENT'] - self.secret = application.config['NOTIFY_API_SECRET'] + self.client_id = application.config['ADMIN_CLIENT_USER_NAME'] + self.secret = application.config['ADMIN_CLIENT_SECRET'] def create_service(self, service_name, active, limit, restricted, user_id): """ @@ -128,6 +128,8 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): message, job_id=None, description=None): + print("{0} {1} {2} {3}".format( + mobile_number, message, job_id, description)) self.send_sms_notification(mobile_number, message) def send_email(self, @@ -137,4 +139,5 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): subject, job_id=None, description=None): - pass + print("{0} {1} {2} {3} {4} {5}".format( + email_address, message, from_address, subject, job_id, description)) From 75d7110642f5894d98df4d10373e1bcd33a7d1cd Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Wed, 20 Jan 2016 14:45:50 +0000 Subject: [PATCH 4/4] Updated to send email through the client send_email. --- app/main/forms.py | 2 +- app/notify_client/api_client.py | 5 +---- app/notify_client/user_api_client.py | 2 +- requirements.txt | 2 +- tests/app/main/test_phone_number_form_field.py | 2 +- tests/app/main/views/test_code_not_received.py | 2 +- 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index bb235d064..70af82666 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -63,7 +63,7 @@ class UKMobileNumber(StringField): return # TODO implement in the render field method. # API's require no spaces in the number - #self.data = '+44 7{} {} {}'.format(*re.findall('...', self.data)) + # self.data = '+44 7{} {} {}'.format(*re.findall('...', self.data)) self.data = '+447{}{}{}'.format(*re.findall('...', self.data)) diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index c60afc3d2..2ec75b79f 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -128,8 +128,6 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): message, job_id=None, description=None): - print("{0} {1} {2} {3}".format( - mobile_number, message, job_id, description)) self.send_sms_notification(mobile_number, message) def send_email(self, @@ -139,5 +137,4 @@ class NotificationsAdminAPIClient(NotificationsAPIClient): subject, job_id=None, description=None): - print("{0} {1} {2} {3} {4} {5}".format( - email_address, message, from_address, subject, job_id, description)) + self.send_email_notification(email_address, message, from_address, subject) diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index d351bbab0..a6858eba7 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -22,7 +22,7 @@ class UserApiClient(BaseAPIClient): "password": password } user_data = self.post("/user", data) - return User(user_data, max_failed_login_count=self.user_max_failed_login_count) + return User(user_data['data'], max_failed_login_count=self.user_max_failed_login_count) class User(object): diff --git a/requirements.txt b/requirements.txt index b3657eab5..560964a4a 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/notifications-python-client.git@0.1.8#egg=notifications-python-client==0.1.8 +git+https://github.com/alphagov/notifications-python-client.git@0.1.9#egg=notifications-python-client==0.1.9 git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3 diff --git a/tests/app/main/test_phone_number_form_field.py b/tests/app/main/test_phone_number_form_field.py index c7a10583a..086e4bff0 100644 --- a/tests/app/main/test_phone_number_form_field.py +++ b/tests/app/main/test_phone_number_form_field.py @@ -72,4 +72,4 @@ def test_phone_number_rejects_invalid_values(phone_number, error_message): def test_phone_number_outputs_in_correct_format(phone_number): form = FormExample(phone_number=phone_number) form.validate() - assert form.phone_number.data == '+44 7123 456 789' + assert form.phone_number.data == '+447123456789' diff --git a/tests/app/main/views/test_code_not_received.py b/tests/app/main/views/test_code_not_received.py index b941911e8..bf7aaba73 100644 --- a/tests/app/main/views/test_code_not_received.py +++ b/tests/app/main/views/test_code_not_received.py @@ -107,7 +107,7 @@ def test_should_update_mobile_number_resend_code(app_, assert response.status_code == 302 assert response.location == url_for('main.verify', _external=True) updated_user = users_dao.get_user_by_id(user.id) - assert updated_user.mobile_number == '+44 7700 900 460' + assert updated_user.mobile_number == '+447700900460' def test_should_render_verification_code_not_received(app_,