Added new notification-python-client removed check on old one, fixed tests, live service will be broken.

This commit is contained in:
Nicholas Staples
2016-01-14 14:55:07 +00:00
parent 96f7034ed3
commit d42ee85f93
9 changed files with 84 additions and 30 deletions

View File

@@ -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)

View File

@@ -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):