mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
validate mobile number so that sms auth works
This commit is contained in:
+14
-5
@@ -735,19 +735,28 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
|
|||||||
set_default_free_allowance_for_service(service, year)
|
set_default_free_allowance_for_service(service, year)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_mobile(ctx, param, value):
|
||||||
|
if (len(''.join(i for i in value if i.isdigit())) != 10):
|
||||||
|
raise click.BadParameter("mobile number must have 10 digits")
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
@notify_command(name='create-test-user')
|
@notify_command(name='create-test-user')
|
||||||
@click.option('-n', '--name', required=True, prompt=True)
|
@click.option('-n', '--name', required=True, prompt=True)
|
||||||
@click.option('-e', '--email', required=True, prompt=True)
|
@click.option('-e', '--email', required=True, prompt=True) # TODO: require valid email
|
||||||
@click.option('-m', '--mobile_number', required=True, prompt=True)
|
@click.option('-m', '--mobile_number',
|
||||||
@click.option('-p', '--password', required=True, prompt=True, hide_input=True, confirmation_prompt=True)
|
required=True, prompt=True, callback=validate_mobile)
|
||||||
|
@click.option('-p', '--password',
|
||||||
|
required=True, prompt=True, hide_input=True, confirmation_prompt=True)
|
||||||
@click.option('-a', '--auth_type', default="sms_auth")
|
@click.option('-a', '--auth_type', default="sms_auth")
|
||||||
@click.option('-s', '--state', default="active")
|
@click.option('-s', '--state', default="active")
|
||||||
@click.option('-d', '--admin', default=False, type=bool)
|
@click.option('-d', '--admin', default=False, type=bool)
|
||||||
def create_test_user(name,email, mobile_number, password, auth_type, state, admin):
|
def create_test_user(name, email, mobile_number, password, auth_type, state, admin):
|
||||||
if os.getenv('NOTIFY_ENVIRONMENT', '') not in ['development', 'test']:
|
if os.getenv('NOTIFY_ENVIRONMENT', '') not in ['development', 'test']:
|
||||||
current_app.logger.error('Can only be run in development')
|
current_app.logger.error('Can only be run in development')
|
||||||
return
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'email_address': email,
|
'email_address': email,
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ from tests.app.db import create_annual_billing, create_service
|
|||||||
|
|
||||||
|
|
||||||
def test_create_test_user_command(notify_db_session, notify_api):
|
def test_create_test_user_command(notify_db_session, notify_api):
|
||||||
|
|
||||||
# number of users before adding ours
|
# number of users before adding ours
|
||||||
user_count = User.query.count()
|
user_count = User.query.count()
|
||||||
|
|
||||||
# run the command
|
# run the command
|
||||||
notify_api.test_cli_runner().invoke(
|
notify_api.test_cli_runner().invoke(
|
||||||
create_test_user, [
|
create_test_user, [
|
||||||
@@ -33,7 +33,7 @@ def test_create_test_user_command(notify_db_session, notify_api):
|
|||||||
|
|
||||||
# that user should be the one we added
|
# that user should be the one we added
|
||||||
user = User.query.filter_by(
|
user = User.query.filter_by(
|
||||||
name = 'Fake Personson'
|
name='Fake Personson'
|
||||||
).first()
|
).first()
|
||||||
assert user.email_address == 'somebody@fake.gov'
|
assert user.email_address == 'somebody@fake.gov'
|
||||||
assert user.auth_type == 'sms_auth'
|
assert user.auth_type == 'sms_auth'
|
||||||
|
|||||||
Reference in New Issue
Block a user