From fe353145890c7089feefdb7701392dce0de22355 Mon Sep 17 00:00:00 2001 From: Theo Beers Date: Tue, 10 Dec 2024 09:12:04 -0500 Subject: [PATCH] Do a bit more refactoring --- src/pykubegrader/validate.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/pykubegrader/validate.py b/src/pykubegrader/validate.py index bc7166c..e7bd983 100644 --- a/src/pykubegrader/validate.py +++ b/src/pykubegrader/validate.py @@ -139,7 +139,7 @@ def get_last_entry(data: list[str], field_name: str) -> str: return entry return "" - def get_len_of_entries(data, question_number) -> int: + def get_entries_len(data: list[str], question_number: int) -> int: """function to get the unique entries by length Args: @@ -180,7 +180,7 @@ def get_len_of_entries(data, question_number) -> int: # Collect entries for each question in a list. entries = [ entry - for j in range(1, get_len_of_entries(data, i)) + for j in range(1, get_entries_len(data, i)) if (entry := get_last_entry(data, f"q{i}_{j}")) != "" ] @@ -246,7 +246,7 @@ def get_len_of_entries(data, question_number) -> int: print("Writing to results.json") json.dump(result_structure, file, indent=4) - login_(login_data, login_url) + verify_login(login_data, login_url) # The file to be uploaded. Ensure the path is correct. file_path = "results.json" @@ -281,15 +281,9 @@ def get_len_of_entries(data, question_number) -> int: submission_message(response) -def login_(login_data, login_url): - login_response = requests.post( - login_url, auth=HTTPBasicAuth(login_data["username"], login_data["password"]) - ) - - if login_response.status_code == 200: - print("Login successful") - else: - Exception("Login failed") +# +# Helper functions +# def submission_message(response) -> None: @@ -309,3 +303,14 @@ def submission_message(response) -> None: pass else: print("results.json was not present") + + +def verify_login(login_data, login_url): + login_response = requests.post( + login_url, auth=HTTPBasicAuth(login_data["username"], login_data["password"]) + ) + + if login_response.status_code == 200: + print("Login successful") + else: + Exception("Login failed")