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
13 changes: 11 additions & 2 deletions mod_auth/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from flask import (Blueprint, abort, flash, g, redirect, request, session,
url_for)
from pyisemail import is_email
from werkzeug.routing import BuildError
from werkzeug.wrappers.response import Response

from database import EnumSymbol
Expand Down Expand Up @@ -229,7 +230,11 @@ def login() -> Union[Response, Dict[str, Union[str, LoginForm]]]:
flash('You are already logged in!', 'alert')
if len(redirect_location) == 0:
return redirect("/")
return redirect(url_for(redirect_location))
try:
return redirect(url_for(redirect_location))
except BuildError:
# Endpoint requires parameters we don't have, redirect to home
return redirect("/")

form = LoginForm(request.form)
if form.validate_on_submit():
Expand All @@ -238,7 +243,11 @@ def login() -> Union[Response, Dict[str, Union[str, LoginForm]]]:
session['user_id'] = user_to_login.id
if len(redirect_location) == 0:
return redirect("/")
return redirect(url_for(redirect_location))
try:
return redirect(url_for(redirect_location))
except BuildError:
# Endpoint requires parameters we don't have, redirect to home
return redirect("/")

flash('Wrong username or password', 'error-message')

Expand Down
21 changes: 15 additions & 6 deletions mod_ci/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,13 @@ def queue_test(gh_commit: Commit.Commit, commit, test_type, platform, branch="ma
Test.branch == branch,
Test.pr_nr == pr_nr
)).first()

if platform_test is None:
log.error(f"No test record found for commit {commit[:8]}, platform {platform.value}, "
f"test_type {test_type}, pr_nr {pr_nr}. "
"This may indicate the pull_request webhook was not processed.")
return

add_customized_regression_tests(platform_test.id)

if gh_commit is not None:
Expand Down Expand Up @@ -1488,10 +1495,10 @@ def start_ci():
gh_commit = repository.get_commit(test.commit)
# If test run status exists, mark them as cancelled
for status in gh_commit.get_statuses():
if status["context"] == f"CI - {test.platform.value}":
if status.context == f"CI - {test.platform.value}":
target_url = url_for('test.by_id', test_id=test.id, _external=True)
update_status_on_github(gh_commit, Status.FAILURE, "Tests canceled",
status["context"], target_url=target_url)
status.context, target_url=target_url)

elif event == "issues":
g.log.debug('issues event detected')
Expand Down Expand Up @@ -2125,7 +2132,9 @@ def upload_type_request(log, test_id, repo_folder, test, request) -> bool:
if filename == '':
log.warning('empty filename provided for uploading')
return False
temp_path = os.path.join(repo_folder, 'TempFiles', filename)
temp_dir = os.path.join(repo_folder, 'TempFiles')
os.makedirs(temp_dir, exist_ok=True)
temp_path = os.path.join(temp_dir, filename)
# Save to temporary location
uploaded_file.save(temp_path)
# Get hash and check if it's already been submitted
Expand All @@ -2135,9 +2144,9 @@ def upload_type_request(log, test_id, repo_folder, test, request) -> bool:
hash_sha256.update(chunk)
file_hash = hash_sha256.hexdigest()
filename, file_extension = os.path.splitext(filename)
final_path = os.path.join(
repo_folder, 'TestResults', f'{file_hash}{file_extension}'
)
results_dir = os.path.join(repo_folder, 'TestResults')
os.makedirs(results_dir, exist_ok=True)
final_path = os.path.join(results_dir, f'{file_hash}{file_extension}')
os.rename(temp_path, final_path)
rto = RegressionTestOutput.query.filter(
RegressionTestOutput.id == request.form['test_file_id']).first()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_ci/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,10 @@ def test_upload_type_request(self, mock_filename, mock_os, mock_open, mock_iter,

mock_log.debug.assert_called_once()
mock_filename.assert_called_once()
self.assertEqual(2, mock_os.path.join.call_count)
# 4 calls: temp_dir, temp_path, results_dir, final_path
self.assertEqual(4, mock_os.path.join.call_count)
# 2 calls: makedirs for TempFiles and TestResults directories
self.assertEqual(2, mock_os.makedirs.call_count)
mock_upload_file.save.assert_called_once()
mock_open.assert_called_once_with(mock.ANY, "rb")
mock_os.path.splitext.assert_called_once_with(mock.ANY)
Expand Down