From d27dcbfa4601ee3a5421444ad27cd63765678773 Mon Sep 17 00:00:00 2001 From: notoraptor Date: Fri, 6 Dec 2024 09:34:17 -0500 Subject: [PATCH] =?UTF-8?q?[CW-567]=20Modifier=20la=20g=C3=A9n=C3=A9ration?= =?UTF-8?q?=20des=20fake=20data=20afin=20de=20s'assurer=20qu'elles=20conti?= =?UTF-8?q?ennent=20toujours=20au=20moins=20un=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ensure_one_fake_admin_in_db.py | 33 ------------------- .../launch_frontend_tests_in_clockwork_dev.sh | 3 -- scripts/produce_fake_users.py | 5 +++ slurm_report/.gitignore | 4 +++ test_common/fake_data.json | 3 +- 5 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 scripts/ensure_one_fake_admin_in_db.py create mode 100644 slurm_report/.gitignore diff --git a/scripts/ensure_one_fake_admin_in_db.py b/scripts/ensure_one_fake_admin_in_db.py deleted file mode 100644 index 8761b2d8..00000000 --- a/scripts/ensure_one_fake_admin_in_db.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Helper script to make sure testing db contains at least 1 admin user. -Used for frontend admin tests. -""" - -from slurm_state.mongo_client import get_mongo_client -from slurm_state.config import get_config - - -def main(): - client = get_mongo_client() - db = client[get_config("mongo.database_name")] - users_collection = db["users"] - users = sorted( - users_collection.find({}), key=lambda user: user["mila_email_username"] - ) - admin_users = [user for user in users if user.get("admin_access", False)] - if not admin_users and users: - future_admin_user = users[0] - users_collection.update_one( - {"mila_email_username": future_admin_user["mila_email_username"]}, - {"$set": {"admin_access": True}}, - ) - assert list( - user - for user in users_collection.find({}) - if user.get("admin_access", False) - ) - print("Admin user registered.") - - -if __name__ == "__main__": - main() diff --git a/scripts/launch_frontend_tests_in_clockwork_dev.sh b/scripts/launch_frontend_tests_in_clockwork_dev.sh index d23b966b..66c84798 100755 --- a/scripts/launch_frontend_tests_in_clockwork_dev.sh +++ b/scripts/launch_frontend_tests_in_clockwork_dev.sh @@ -6,9 +6,6 @@ playwright install chromium echo Store fake data python3 scripts/store_fake_data_in_db.py -echo Ensure at least 1 fake admin user -python3 scripts/ensure_one_fake_admin_in_db.py - echo Launch clockwork web server in background python3 -m flask run --host="0.0.0.0" & diff --git a/scripts/produce_fake_users.py b/scripts/produce_fake_users.py index 3c5d9749..efa79627 100644 --- a/scripts/produce_fake_users.py +++ b/scripts/produce_fake_users.py @@ -53,6 +53,10 @@ def gen_single_user(n): # This is useful for testing permissions. cc_account_username = "ccuser%0.2d" % n if not n % 20 == 6 else None + # One out of 20 of the users will be an admin + # (actually matching student02 in 20 first users). + admin_rights = {"admin_access": True} if n % 20 == 2 else {} + D_user = { "mila_email_username": "student%0.2d@mila.quebec" % n, "status": status, @@ -73,6 +77,7 @@ def gen_single_user(n): "dark_mode": False, "language": "en" if (n % 2 == 0) else "fr", }, + **admin_rights, } if cc_account_username is not None: diff --git a/slurm_report/.gitignore b/slurm_report/.gitignore new file mode 100644 index 00000000..3657f6c6 --- /dev/null +++ b/slurm_report/.gitignore @@ -0,0 +1,4 @@ +# As this folder is used to generate test data, +# Git could ignore everything here, except README file. +* +!README.md diff --git a/test_common/fake_data.json b/test_common/fake_data.json index a94291e8..efaee8af 100644 --- a/test_common/fake_data.json +++ b/test_common/fake_data.json @@ -37,7 +37,8 @@ "nbr_items_per_page": 40, "dark_mode": false, "language": "en" - } + }, + "admin_access": true }, { "mila_email_username": "student03@mila.quebec",