mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 14:18:24 -04:00
Added NoDataFoundException
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import datetime
|
|||||||
from sqlalchemy.orm import load_only
|
from sqlalchemy.orm import load_only
|
||||||
|
|
||||||
from app import db, login_manager
|
from app import db, login_manager
|
||||||
|
from app.main.exceptions import NoDataFoundException
|
||||||
from app.models import User
|
from app.models import User
|
||||||
from app.main.encryption import hashpw
|
from app.main.encryption import hashpw
|
||||||
|
|
||||||
@@ -61,11 +62,14 @@ def update_mobile_number(id, mobile_number):
|
|||||||
|
|
||||||
def update_password(email, password):
|
def update_password(email, password):
|
||||||
user = get_user_by_email(email)
|
user = get_user_by_email(email)
|
||||||
user.password = hashpw(password)
|
if user:
|
||||||
user.password_changed_at = datetime.now()
|
user.password = hashpw(password)
|
||||||
db.session.add(user)
|
user.password_changed_at = datetime.now()
|
||||||
db.session.commit()
|
db.session.add(user)
|
||||||
return user
|
db.session.commit()
|
||||||
|
return user
|
||||||
|
else:
|
||||||
|
raise NoDataFoundException('The user does not exist')
|
||||||
|
|
||||||
|
|
||||||
def find_all_email_address():
|
def find_all_email_address():
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
class AdminApiClientException(Exception):
|
class AdminApiClientException(Exception):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
self.value = message
|
self.value = message
|
||||||
|
|
||||||
|
|
||||||
|
class NoDataFoundException(Exception):
|
||||||
|
def __init__(self, message):
|
||||||
|
self.value = message
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
from pytest import fail
|
||||||
|
|
||||||
from app.main.dao import users_dao
|
from app.main.dao import users_dao
|
||||||
from app.main.encryption import check_hash
|
from app.main.encryption import check_hash
|
||||||
|
from app.main.exceptions import NoDataFoundException
|
||||||
from app.main.views import generate_token
|
from app.main.views import generate_token
|
||||||
from tests.app.main import create_test_user
|
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
|
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,
|
def test_should_return_raise_no_data_found_exception_when_email_address_does_not_exist(notifications_admin,
|
||||||
notify_db_session):
|
notifications_admin_db,
|
||||||
|
notify_db_session):
|
||||||
with notifications_admin.test_request_context():
|
with notifications_admin.test_request_context():
|
||||||
with notifications_admin.test_client() as client:
|
with notifications_admin.test_client() as client:
|
||||||
token = generate_token('doesnotexist@it.gov.uk')
|
token = generate_token('doesnotexist@it.gov.uk')
|
||||||
response = client.post('/new-password/{}'.format(token),
|
try:
|
||||||
data={'new_password': 'a-new_password'})
|
client.post('/new-password/{}'.format(token),
|
||||||
assert response.status_code == 500
|
data={'new_password': 'a-new_password'})
|
||||||
|
fail('Expected NoDataFoundException')
|
||||||
|
except NoDataFoundException:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user