mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
109526520: Add custom validators for the VerifyForm
If the email_code or sms_code entered does not pass check password, then add errors to the form.
This commit is contained in:
@@ -51,7 +51,8 @@ def test_should_return_400_when_sms_code_is_wrong(notifications_admin, notificat
|
||||
data={'sms_code': '98765',
|
||||
'email_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert '"sms_code": "does not match"' in response.get_data(as_text=True)
|
||||
assert 'sms_code' in response.get_data(as_text=True)
|
||||
assert 'Code does not match' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_return_400_when_email_code_is_wrong(notifications_admin, notifications_admin_db):
|
||||
@@ -65,21 +66,35 @@ def test_should_return_400_when_email_code_is_wrong(notifications_admin, notific
|
||||
data={'sms_code': '12345',
|
||||
'email_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert '"email_code": "does not match"' in response.get_data(as_text=True)
|
||||
print(response.get_data(as_text=True))
|
||||
assert 'email_code' in response.get_data(as_text=True)
|
||||
assert 'Code does not match' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_return_400_when_sms_code_is_missing(notifications_admin, notifications_admin_db):
|
||||
response = notifications_admin.test_client().post('/verify',
|
||||
data={'email_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert 'SMS code can not be empty' in response.get_data(as_text=True)
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = _create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('12345')
|
||||
session['email_code'] = hashpw('98456')
|
||||
response = client.post('/verify',
|
||||
data={'email_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert 'SMS code can not be empty' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_return_400_when_email_code_is_missing(notifications_admin, notifications_admin_db):
|
||||
response = notifications_admin.test_client().post('/verify',
|
||||
data={'sms_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert 'Email code can not be empty' in response.get_data(as_text=True)
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = _create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('23456')
|
||||
session['email_code'] = hashpw('23456')
|
||||
response = client.post('/verify',
|
||||
data={'sms_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert 'Email code can not be empty' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def _create_test_user():
|
||||
|
||||
Reference in New Issue
Block a user