Added NoDataFoundException

This commit is contained in:
Rebecca Law
2016-01-07 17:41:21 +00:00
parent a860f713d2
commit 35619553c8
3 changed files with 26 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ from datetime import datetime
from sqlalchemy.orm import load_only
from app import db, login_manager
from app.main.exceptions import NoDataFoundException
from app.models import User
from app.main.encryption import hashpw
@@ -61,11 +62,14 @@ def update_mobile_number(id, mobile_number):
def update_password(email, password):
user = get_user_by_email(email)
user.password = hashpw(password)
user.password_changed_at = datetime.now()
db.session.add(user)
db.session.commit()
return user
if user:
user.password = hashpw(password)
user.password_changed_at = datetime.now()
db.session.add(user)
db.session.commit()
return user
else:
raise NoDataFoundException('The user does not exist')
def find_all_email_address():

View File

@@ -1,5 +1,8 @@
class AdminApiClientException(Exception):
def __init__(self, message):
self.value = message
class NoDataFoundException(Exception):
def __init__(self, message):
self.value = message

View File

@@ -1,5 +1,8 @@
from pytest import fail
from app.main.dao import users_dao
from app.main.encryption import check_hash
from app.main.exceptions import NoDataFoundException
from app.main.views import generate_token
from tests.app.main import create_test_user
@@ -39,11 +42,15 @@ def test_should_redirect_to_forgot_password_with_flash_message_when_token_is_exp
notifications_admin.config['TOKEN_MAX_AGE_SECONDS'] = 86400
def test_should_return_500_error_page_when_email_addres_does_not_exist(notifications_admin, notifications_admin_db,
notify_db_session):
def test_should_return_raise_no_data_found_exception_when_email_address_does_not_exist(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
token = generate_token('doesnotexist@it.gov.uk')
response = client.post('/new-password/{}'.format(token),
data={'new_password': 'a-new_password'})
assert response.status_code == 500
try:
client.post('/new-password/{}'.format(token),
data={'new_password': 'a-new_password'})
fail('Expected NoDataFoundException')
except NoDataFoundException:
pass