From 7ef70c39b9d4af3d7ac9a2b5d9f832aa06f910a3 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 2 Apr 2024 11:43:01 -0700 Subject: [PATCH] show all users --- app/commands.py | 20 ++++++++++++++++++++ tests/app/test_commands.py | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/app/commands.py b/app/commands.py index 725e7ee99..38d49f198 100644 --- a/app/commands.py +++ b/app/commands.py @@ -1006,3 +1006,23 @@ def add_test_users_to_db(generate, state, admin): platform_admin=admin, ) print(f"{num} {user.email_address} created") + + +@notify_command(name="show-users") +def show_users(): + + sql = """ + + select users.name, users.email_address, users.mobile_number, services.name as service_name + from users + inner join user_to_service on users.id=user_to_service.user_id + inner join services on services.id=user_to_service.service_id + order by services.name asc, users.name asc + """ + users = db.session.execute(sql) + report = "Name,Email address,Mobile number,Service name" + print(report) + for row in users: + print(f"{row.name},{row.email_address},{row.mobile_number},{row.service_name}") + report = f"{report}\n{row.name},{row.email_address},{row.mobile_number},{row.service_name}" + return report diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index a96eae599..0f52a904c 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -16,6 +16,7 @@ from app.commands import ( populate_organizations_from_file, promote_user_to_platform_admin, purge_functional_test_data, + show_users, update_jobs_archived_flag, ) from app.dao.inbound_numbers_dao import dao_get_available_inbound_numbers @@ -440,3 +441,11 @@ def test_promote_user_to_platform_admin_no_result_found( ) assert "NoResultFound" in str(result) assert sample_user.platform_admin is False + + +def test_show_users(notify_db_session, notify_api, sample_user): + result = notify_api.test_cli_runner().invoke( + show_users, + [], + ) + assert "Name,Email address,Mobile number,Service name" in str(result)