mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05:00
Added NoDataFoundException
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
class AdminApiClientException(Exception):
|
||||
def __init__(self, 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.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
|
||||
|
||||
Reference in New Issue
Block a user