diff --git a/clockwork_frontend_test/test_dashboard.py b/clockwork_frontend_test/test_dashboard.py index d0e63588..186c60fe 100644 --- a/clockwork_frontend_test/test_dashboard.py +++ b/clockwork_frontend_test/test_dashboard.py @@ -23,7 +23,9 @@ DASHBOARD_TABLE_CONTENT.append( [ job["slurm"]["cluster_name"], - job["slurm"]["job_id"], + int( + job["slurm"]["job_id"] + ), # job ID is currently handled as a numeric value job["slurm"]["name"], job["slurm"]["job_state"].lower(), get_default_display_date(job["slurm"]["submit_time"]), @@ -116,7 +118,7 @@ def test_dashboard_table_default_content(page: Page): cols = rows.nth(index_row).locator("td") expect(cols).to_have_count(8) for index_col, content_col in enumerate(content_row): - expect(cols.nth(index_col)).to_contain_text(content_col) + expect(cols.nth(index_col)).to_contain_text(str(content_col)) def test_dashboard_table_sorting(page: Page): @@ -195,4 +197,4 @@ def _check_dashboard_table(page: Page, table_content: list): cols = rows.nth(index_row).locator("td") expect(cols).to_have_count(8) for index_col, content_col in enumerate(content_row): - expect(cols.nth(index_col)).to_contain_text(content_col) + expect(cols.nth(index_col)).to_contain_text(str(content_col)) diff --git a/clockwork_frontend_test/test_jobs_search.py b/clockwork_frontend_test/test_jobs_search.py index 1a7a57e4..8bc6a4ff 100644 --- a/clockwork_frontend_test/test_jobs_search.py +++ b/clockwork_frontend_test/test_jobs_search.py @@ -59,11 +59,13 @@ def _load_all_jobs_search_page(page: Page): page.goto(f"{BASE_URL}/jobs/search?nbr_items_per_page={len(sorted_jobs)}") -def _check_jobs_table(page: Page, table_content: list): +def _check_jobs_table(page: Page, table_content: list, expect_content=True): """Check jobs table contains expected table content. table_content is a list or rows, each row is a list of texts expected in related columns. """ + if expect_content: + assert table_content table = page.locator("table#search_table") expect(table).to_have_count(1) rows = table.locator("tbody tr") @@ -528,7 +530,7 @@ def test_multiple_filters(page: Page): and get_inferred_job_state(job["slurm"]["job_state"]) != "PENDING" ][:40] - _check_jobs_table(page, expected_results) + _check_jobs_table(page, expected_results, expect_content=False) # Reset all filters. @@ -561,6 +563,8 @@ def test_filter_by_job_array(page: Page): for searched_job in sorted_jobs: if searched_job["slurm"]["array_job_id"] != "0": break + else: + raise AssertionError("No job found with a valid array_job_id") searched_array_job_id = searched_job["slurm"]["array_job_id"] expected_results = [ 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/insert_hardcoded_values.py b/scripts/insert_hardcoded_values.py index 6a275c55..002de3e4 100644 --- a/scripts/insert_hardcoded_values.py +++ b/scripts/insert_hardcoded_values.py @@ -7,6 +7,7 @@ import json import os import sys +import random def get_jobs_hardcoded_values(): @@ -80,6 +81,33 @@ def get_job_user_props_hardcoded_values(fake_data: dict): ] +def ensure_admin_users(fake_data: dict): + """Make sure there is at least 1 fake admin.""" + users = fake_data["users"] + admin_users = [user for user in users if user.get("admin_access", False)] + if not admin_users and users: + users[0]["admin_access"] = True + assert [user for user in fake_data["users"] if user.get("admin_access", False)] + + +def ensure_job_arrays(fake_data: dict): + """Make sure some fake jobs belong to valid job arrays.""" + jobs_with_array_id = [ + job for job in fake_data["jobs"] if job["slurm"]["array_job_id"] != "0" + ] + if not jobs_with_array_id: + # No yet jobs in valid job arrays. + # Add 2 jobs to 2 separate job arrays. + nb_fake_jobs = len(fake_data["jobs"]) + assert nb_fake_jobs >= 2 + id_job_1 = random.randint(0, nb_fake_jobs) + id_job_2 = (id_job_1 + 1) % nb_fake_jobs + fake_data["jobs"][id_job_1]["slurm"]["array_job_id"] = "1234" + fake_data["jobs"][id_job_2]["slurm"]["array_job_id"] = "5678" + + assert [job for job in fake_data["jobs"] if job["slurm"]["array_job_id"] != "0"] + + def main(argv): my_parser = argparse.ArgumentParser() @@ -113,6 +141,12 @@ def main(argv): # Insert fake job user props fake_data["job_user_props"] = get_job_user_props_hardcoded_values(fake_data) + # Make sure there are some admin users + ensure_admin_users(fake_data) + + # Make sure some jobs are in valid job arrays + ensure_job_arrays(fake_data) + # Write the new fake data in the output file with open(output_file, "w") as f: json.dump(fake_data, f, indent=2) 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/test_common/fake_data.json b/test_common/fake_data.json index a94291e8..22b61a64 100644 --- a/test_common/fake_data.json +++ b/test_common/fake_data.json @@ -11,7 +11,8 @@ "nbr_items_per_page": 40, "dark_mode": false, "language": "en" - } + }, + "admin_access": true }, { "mila_email_username": "student01@mila.quebec",