Skip to content

Commit

Permalink
Do a bit more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
theodore-s-beers committed Dec 10, 2024
1 parent 1b77c28 commit fe35314
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/pykubegrader/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}")) != ""
]

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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")

0 comments on commit fe35314

Please sign in to comment.