mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Merge pull request #3946 from alphagov/refactor-user-fixtures
DRY up user fixtures and factories
This commit is contained in:
+139
-435
@@ -1064,20 +1064,10 @@ def mock_update_service_template_sender(mocker):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_pending(fake_uuid):
|
def api_user_pending(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_user(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
state='pending'
|
||||||
'email_address': 'test@user.gov.uk',
|
)
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'pending',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'platform_admin': False,
|
|
||||||
'permissions': {},
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
@@ -1104,161 +1094,48 @@ def platform_admin_user_no_service_permissions():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_active(fake_uuid):
|
def api_user_active():
|
||||||
user_data = {'id': fake_uuid,
|
return create_api_user_active()
|
||||||
'name': 'Test User',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'services': [],
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'logged_in_at': None,
|
|
||||||
'email_access_validated_at': None
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_active_email_auth(fake_uuid):
|
def api_user_active_email_auth(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_user(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
auth_type='email_auth'
|
||||||
'email_address': 'test@user.gov.uk',
|
)
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'email_auth',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'services': [],
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def active_user_with_permissions_no_mobile(fake_uuid):
|
def active_user_with_permissions_no_mobile(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_service_one_admin(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
mobile_number=None,
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
)
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': None,
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'email_auth',
|
|
||||||
'organisations': [ORGANISATION_ID],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_nongov_user_active(fake_uuid):
|
def api_nongov_user_active(fake_uuid):
|
||||||
user_data = {
|
return create_service_one_admin(
|
||||||
'id': fake_uuid,
|
id=fake_uuid,
|
||||||
'name': 'Test User',
|
email_address='someuser@example.com',
|
||||||
'password': 'somepassword',
|
)
|
||||||
'email_address': 'someuser@example.com',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity',
|
|
||||||
]},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'services': [],
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def active_user_with_permissions(fake_uuid):
|
def active_user_with_permissions(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_active_user_with_permissions()
|
||||||
'name': 'Test User',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [ORGANISATION_ID],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def active_user_with_session(fake_uuid):
|
def active_user_with_session(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_service_one_admin(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
)
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [ORGANISATION_ID],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': fake_uuid,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def active_user_with_permission_to_two_services(fake_uuid):
|
def active_user_with_permission_to_two_services(fake_uuid):
|
||||||
|
|
||||||
permissions = [
|
permissions = [
|
||||||
'send_texts',
|
'send_texts',
|
||||||
'send_emails',
|
'send_emails',
|
||||||
@@ -1270,25 +1147,15 @@ def active_user_with_permission_to_two_services(fake_uuid):
|
|||||||
'view_activity',
|
'view_activity',
|
||||||
]
|
]
|
||||||
|
|
||||||
return {
|
return create_user(
|
||||||
'id': fake_uuid,
|
id=fake_uuid,
|
||||||
'name': 'Test User',
|
permissions={
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {
|
|
||||||
SERVICE_ONE_ID: permissions,
|
SERVICE_ONE_ID: permissions,
|
||||||
SERVICE_TWO_ID: permissions,
|
SERVICE_TWO_ID: permissions,
|
||||||
},
|
},
|
||||||
'platform_admin': False,
|
organisations=[ORGANISATION_ID],
|
||||||
'auth_type': 'sms_auth',
|
services=[SERVICE_ONE_ID, SERVICE_TWO_ID],
|
||||||
'organisations': [ORGANISATION_ID],
|
)
|
||||||
'services': [SERVICE_ONE_ID, SERVICE_TWO_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
@@ -1307,132 +1174,44 @@ def active_user_with_permission_to_other_service(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def active_caseworking_user(fake_uuid):
|
def active_caseworking_user():
|
||||||
|
return create_active_caseworking_user()
|
||||||
user_data = {
|
|
||||||
'id': fake_uuid,
|
|
||||||
'name': 'Test User',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'caseworker@example.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
]},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def active_user_view_permissions(fake_uuid):
|
def active_user_view_permissions():
|
||||||
user_data = {'id': fake_uuid,
|
return create_active_user_view_permissions()
|
||||||
'name': 'Test User With Permissions',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def active_user_no_settings_permission(fake_uuid):
|
def active_user_no_settings_permission():
|
||||||
return {
|
return create_active_user_no_settings_permission()
|
||||||
'id': fake_uuid,
|
|
||||||
'name': 'Test User With Permissions',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'manage_templates',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity',
|
|
||||||
]},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'current_session_id': None,
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'organisations': [],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_locked(fake_uuid):
|
def api_user_locked(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_user(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
failed_login_count=5,
|
||||||
'email_address': 'test@user.gov.uk',
|
password_changed_at=None,
|
||||||
'mobile_number': '07700 900762',
|
)
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 5,
|
|
||||||
'permissions': {},
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'platform_admin': False,
|
|
||||||
'services': [],
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_request_password_reset(fake_uuid):
|
def api_user_request_password_reset(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_user(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
failed_login_count=5,
|
||||||
'email_address': 'test@user.gov.uk',
|
)
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 5,
|
|
||||||
'permissions': {},
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'platform_admin': False,
|
|
||||||
'services': [],
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def api_user_changed_password(fake_uuid):
|
def api_user_changed_password(fake_uuid):
|
||||||
user_data = {'id': fake_uuid,
|
return create_user(
|
||||||
'name': 'Test User',
|
id=fake_uuid,
|
||||||
'password': 'somepassword',
|
failed_login_count=5,
|
||||||
'email_address': 'test@user.gov.uk',
|
password_changed_at=str(datetime.utcnow() + timedelta(minutes=1)),
|
||||||
'mobile_number': '07700 900762',
|
)
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 5,
|
|
||||||
'permissions': {},
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'password_changed_at': str(datetime.utcnow() + timedelta(minutes=1)),
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'platform_admin': False,
|
|
||||||
'services': [],
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
@@ -2362,26 +2141,12 @@ def mock_has_permissions(mocker):
|
|||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_users_by_service(mocker):
|
def mock_get_users_by_service(mocker):
|
||||||
def _get_users_for_service(service_id):
|
def _get_users_for_service(service_id):
|
||||||
data = [{'id': sample_uuid(),
|
return [create_service_one_admin(
|
||||||
'logged_in_at': None,
|
id=sample_uuid(),
|
||||||
'mobile_number': '+447700900986',
|
logged_in_at=None,
|
||||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
mobile_number='+447700900986',
|
||||||
'send_emails',
|
email_address='notify@digital.cabinet-office.gov.uk',
|
||||||
'send_letters',
|
)]
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys']},
|
|
||||||
'state': 'active',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'name': 'Test User',
|
|
||||||
'email_address': 'notify@digital.cabinet-office.gov.uk',
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'organisations': [],
|
|
||||||
'platform_admin': False,
|
|
||||||
}]
|
|
||||||
return [data[0]]
|
|
||||||
|
|
||||||
# You shouldn’t be calling the user API client directly, so it’s the
|
# You shouldn’t be calling the user API client directly, so it’s the
|
||||||
# instance on the model that’s mocked here
|
# instance on the model that’s mocked here
|
||||||
@@ -3789,198 +3554,137 @@ def mock_get_returned_letter_statistics_with_no_returned_letters(mocker):
|
|||||||
|
|
||||||
|
|
||||||
def create_api_user_active(with_unique_id=False):
|
def create_api_user_active(with_unique_id=False):
|
||||||
return {
|
return create_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User',
|
)
|
||||||
'password': 'somepassword',
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'services': [],
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'logged_in_at': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_empty_permissions(with_unique_id=False):
|
def create_active_user_empty_permissions(with_unique_id=False):
|
||||||
return {
|
return create_service_one_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User With Empty Permissions',
|
name='Test User With Empty Permissions',
|
||||||
'password': 'somepassword',
|
)
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900763',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_with_permissions(with_unique_id=False):
|
def create_active_user_with_permissions(with_unique_id=False):
|
||||||
return {
|
return create_service_one_admin(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User',
|
)
|
||||||
'password': 'somepassword',
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['send_texts',
|
|
||||||
'send_emails',
|
|
||||||
'send_letters',
|
|
||||||
'manage_users',
|
|
||||||
'manage_templates',
|
|
||||||
'manage_settings',
|
|
||||||
'manage_api_keys',
|
|
||||||
'view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [ORGANISATION_ID],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_view_permissions(with_unique_id=False):
|
def create_active_user_view_permissions(with_unique_id=False):
|
||||||
return {
|
return create_service_one_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User With Permissions',
|
name='Test User With Permissions',
|
||||||
'password': 'somepassword',
|
permissions={SERVICE_ONE_ID: ['view_activity']},
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
)
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: ['view_activity']},
|
|
||||||
'platform_admin': False,
|
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_caseworking_user(with_unique_id=False):
|
def create_active_caseworking_user(with_unique_id=False):
|
||||||
return {
|
return create_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User',
|
email_address='caseworker@example.gov.uk',
|
||||||
'password': 'somepassword',
|
permissions={SERVICE_ONE_ID: [
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'caseworker@example.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'send_texts',
|
'send_texts',
|
||||||
'send_emails',
|
'send_emails',
|
||||||
'send_letters',
|
'send_letters',
|
||||||
]},
|
]},
|
||||||
'platform_admin': False,
|
services=[SERVICE_ONE_ID],
|
||||||
'auth_type': 'sms_auth',
|
)
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_no_api_key_permission(with_unique_id=False):
|
def create_active_user_no_api_key_permission(with_unique_id=False):
|
||||||
return {
|
return create_service_one_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User With Permissions',
|
name='Test User With Permissions',
|
||||||
'password': 'somepassword',
|
permissions={SERVICE_ONE_ID: [
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'manage_templates',
|
'manage_templates',
|
||||||
'manage_settings',
|
'manage_settings',
|
||||||
'view_activity',
|
'view_activity',
|
||||||
]},
|
]},
|
||||||
'platform_admin': False,
|
)
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'organisations': [],
|
|
||||||
'current_session_id': None,
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_no_settings_permission(with_unique_id=False):
|
def create_active_user_no_settings_permission(with_unique_id=False):
|
||||||
return {
|
return create_service_one_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User With Permissions',
|
name='Test User With Permissions',
|
||||||
'password': 'somepassword',
|
permissions={SERVICE_ONE_ID: [
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
|
||||||
'manage_templates',
|
'manage_templates',
|
||||||
'manage_api_keys',
|
'manage_api_keys',
|
||||||
'view_activity',
|
'view_activity',
|
||||||
]},
|
]},
|
||||||
'platform_admin': False,
|
)
|
||||||
'auth_type': 'sms_auth',
|
|
||||||
'current_session_id': None,
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'organisations': [],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_active_user_manage_template_permissions(with_unique_id=False):
|
def create_active_user_manage_template_permissions(with_unique_id=False):
|
||||||
return {
|
return create_service_one_user(
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
'name': 'Test User With Permissions',
|
name='Test User With Permissions',
|
||||||
|
permissions={SERVICE_ONE_ID: [
|
||||||
|
'manage_templates',
|
||||||
|
'view_activity',
|
||||||
|
]},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_platform_admin_user(with_unique_id=False, auth_type='sms_auth', permissions=None):
|
||||||
|
return create_user(
|
||||||
|
id=str(uuid4()) if with_unique_id else sample_uuid(),
|
||||||
|
name='Platform admin user',
|
||||||
|
email_address='platform@admin.gov.uk',
|
||||||
|
permissions=permissions or {},
|
||||||
|
platform_admin=True,
|
||||||
|
auth_type=auth_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_service_one_admin(**overrides):
|
||||||
|
user_data = {
|
||||||
|
'permissions': {SERVICE_ONE_ID: [
|
||||||
|
'send_texts',
|
||||||
|
'send_emails',
|
||||||
|
'send_letters',
|
||||||
|
'manage_users',
|
||||||
|
'manage_templates',
|
||||||
|
'manage_settings',
|
||||||
|
'manage_api_keys',
|
||||||
|
'view_activity'
|
||||||
|
]},
|
||||||
|
}
|
||||||
|
user_data.update(overrides)
|
||||||
|
return create_service_one_user(**user_data)
|
||||||
|
|
||||||
|
|
||||||
|
def create_service_one_user(**overrides):
|
||||||
|
user_data = {
|
||||||
|
'organisations': [ORGANISATION_ID],
|
||||||
|
'services': [SERVICE_ONE_ID],
|
||||||
|
}
|
||||||
|
user_data.update(overrides)
|
||||||
|
return create_user(**user_data)
|
||||||
|
|
||||||
|
|
||||||
|
def create_user(**overrides):
|
||||||
|
user_data = {
|
||||||
|
'name': 'Test User',
|
||||||
'password': 'somepassword',
|
'password': 'somepassword',
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
|
||||||
'email_address': 'test@user.gov.uk',
|
'email_address': 'test@user.gov.uk',
|
||||||
'mobile_number': '07700 900762',
|
'mobile_number': '07700 900762',
|
||||||
'state': 'active',
|
'state': 'active',
|
||||||
'failed_login_count': 0,
|
'failed_login_count': 0,
|
||||||
'permissions': {SERVICE_ONE_ID: [
|
'permissions': {},
|
||||||
'manage_templates',
|
|
||||||
'view_activity',
|
|
||||||
]},
|
|
||||||
'platform_admin': False,
|
'platform_admin': False,
|
||||||
'auth_type': 'sms_auth',
|
'auth_type': 'sms_auth',
|
||||||
'organisations': [],
|
|
||||||
'services': [SERVICE_ONE_ID],
|
|
||||||
'current_session_id': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_platform_admin_user(with_unique_id=False, auth_type='sms_auth', permissions=None):
|
|
||||||
return {
|
|
||||||
'id': str(uuid4()) if with_unique_id else sample_uuid(),
|
|
||||||
'name': 'Platform admin user',
|
|
||||||
'password': 'somepassword',
|
|
||||||
'email_address': 'platform@admin.gov.uk',
|
|
||||||
'mobile_number': '07700 900762',
|
|
||||||
'state': 'active',
|
|
||||||
'failed_login_count': 0,
|
|
||||||
'permissions': permissions or {},
|
|
||||||
'platform_admin': True,
|
|
||||||
'auth_type': auth_type,
|
|
||||||
'password_changed_at': str(datetime.utcnow()),
|
'password_changed_at': str(datetime.utcnow()),
|
||||||
'services': [],
|
'services': [],
|
||||||
'organisations': [],
|
'organisations': [],
|
||||||
'current_session_id': None,
|
'current_session_id': None,
|
||||||
'logged_in_at': None,
|
'logged_in_at': None,
|
||||||
|
'email_access_validated_at': None
|
||||||
}
|
}
|
||||||
|
user_data.update(overrides)
|
||||||
|
return user_data
|
||||||
|
|
||||||
|
|
||||||
def create_reply_to_email_address(
|
def create_reply_to_email_address(
|
||||||
|
|||||||
Reference in New Issue
Block a user