Update user_json test function

Since we can't call the `api_user_active` fixture as a function with
Pytest 5, the `user_json` function can be used instead. This updates
the function to
- Stop returning `max_failed_login_count` since this is not a field that
gets returned from the api
- Return fields as strings, not UUIDS, to match the format that api
returns the data in
- Provide a way to use this function to return a user with no
permissions
This commit is contained in:
Katie Smith
2019-12-19 14:24:25 +00:00
parent aec3ccff3a
commit 02253d32c5
+7 -5
View File
@@ -55,15 +55,14 @@ def user_json(
failed_login_count=0, failed_login_count=0,
logged_in_at=None, logged_in_at=None,
state='active', state='active',
max_failed_login_count=3,
platform_admin=False, platform_admin=False,
current_session_id='1234', current_session_id='1234',
organisations=None, organisations=None,
services=None services=None
): ):
if not permissions: if permissions is None:
permissions = {generate_uuid(): [ permissions = {str(generate_uuid()): [
'view_activity', 'view_activity',
'send_texts', 'send_texts',
'send_emails', 'send_emails',
@@ -73,6 +72,10 @@ def user_json(
'manage_settings', 'manage_settings',
'manage_api_keys', 'manage_api_keys',
]} ]}
if services is None:
services = [str(service_id) for service_id in permissions.keys()]
return { return {
'id': id_, 'id': id_,
'name': name, 'name': name,
@@ -84,11 +87,10 @@ def user_json(
'failed_login_count': failed_login_count, 'failed_login_count': failed_login_count,
'logged_in_at': logged_in_at or datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f'), 'logged_in_at': logged_in_at or datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f'),
'state': state, 'state': state,
'max_failed_login_count': max_failed_login_count,
'platform_admin': platform_admin, 'platform_admin': platform_admin,
'current_session_id': current_session_id, 'current_session_id': current_session_id,
'organisations': organisations or [], 'organisations': organisations or [],
'services': list(permissions.keys()) if services is None else services 'services': services
} }