Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions tofupilot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ def create_run_from_openhtf_report(self, file_path: str):
https://www.tofupilot.com/docs/api#create-a-run-from-a-file
"""
# Upload report and create run from file_path
run_id = self.upload_and_create_from_openhtf_report(file_path)
upload_res = self.upload_and_create_from_openhtf_report(file_path)

# If run_id is not a string, it's an error response dictionary
if not isinstance(run_id, str):
if not upload_res.get("success", False):
self._logger.error("OpenHTF import failed")
return run_id
return ""

run_id = upload_res["run_id"]

# Only continue with attachment upload if run_id is valid
test_record = None
Expand Down Expand Up @@ -396,13 +397,12 @@ def delete_unit(self, serial_number: str) -> dict:
def upload_and_create_from_openhtf_report(
self,
file_path: str,
) -> str:
) -> Dict:
"""
Takes a path to an OpenHTF JSON file report, uploads it and creates a run from it.

Returns:
str:
Id of the newly created run
Dict
"""

print("")
Expand Down Expand Up @@ -449,8 +449,8 @@ def upload_and_create_from_openhtf_report(
verify=self._verify,
)

# Return only the ID if successful, otherwise return the full result
if result.get("success", False) is not False:
# Return only the ID if successful, otherwise return the full result
if result.get("success", True) is not False:
run_id = result.get("id")
run_url = result.get("url")

Expand All @@ -460,17 +460,25 @@ def upload_and_create_from_openhtf_report(
elif run_id:
self._logger.success(f"Run imported successfully with ID: {run_id}")

return run_id
return {
"success": True,
"run_id": run_id,
"upload_id": upload_id,
}
else:
return result
return {**result, "upload_id": upload_id,}

def get_connection_credentials(self) -> dict:
"""
Fetches credentials required to livestream test results.

Returns:
values:
a dict containing the emqx server url, the topic to connect to, and the JWT token required to connect
a dict containing
"success":
a bool indicating success
"values" if success:
a dict containing the emqx server url, the topic to connect to, and the JWT token required to connect
other fields as set in handle_http_error and handle_network_error
"""
try:
response = requests.get(
Expand All @@ -481,13 +489,11 @@ def get_connection_credentials(self) -> dict:
)
response.raise_for_status()
values = handle_response(self._logger, response)
return values
return {"success": True, "values": values}
except requests.exceptions.HTTPError as http_err:
handle_http_error(self._logger, http_err)
return None
return handle_http_error(self._logger, http_err)
except requests.RequestException as e:
handle_network_error(self._logger, e)
return None
return handle_network_error(self._logger, e)


def print_version_banner(current_version: str):
Expand Down
Loading