Skip to content
Open
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
3 changes: 2 additions & 1 deletion mod_home/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def before_app_request() -> None:
@template_renderer()
def index():
"""Render index home page."""
last_commit = GeneralData.query.filter(GeneralData.key == 'last_commit').first().value
last_commit_entry = GeneralData.query.filter(GeneralData.key == 'last_commit').first()
last_commit = last_commit_entry.value if last_commit_entry is not None else None
last_release = CCExtractorVersion.query.order_by(CCExtractorVersion.released.desc()).first()
test_access = False
if g.user is not None and g.user.role in [Role.tester, Role.contributor, Role.admin]:
Expand Down
10 changes: 6 additions & 4 deletions mod_sample/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def display_sample_info(sample) -> Dict[str, Any]:
# in case no media info present in the sample
media_info = None

latest_commit = GeneralData.query.filter(GeneralData.key == 'last_commit').first().value
last_release = CCExtractorVersion.query.order_by(CCExtractorVersion.released.desc()).first().commit
latest_commit_entry = GeneralData.query.filter(GeneralData.key == 'last_commit').first()
latest_commit = latest_commit_entry.value if latest_commit_entry is not None else None
last_release_entry = CCExtractorVersion.query.order_by(CCExtractorVersion.released.desc()).first()
last_release = last_release_entry.commit if last_release_entry is not None else None

test_commit = Test.query.filter(Test.commit == latest_commit).first()
test_release = Test.query.filter(Test.commit == last_release).first()
test_commit = Test.query.filter(Test.commit == latest_commit).first() if latest_commit else None
test_release = Test.query.filter(Test.commit == last_release).first() if last_release else None
regression_tests = RegressionTest.query.filter(RegressionTest.sample_id == sample.id).all()
status = 'Unknown'
status_release = 'Unknown'
Expand Down
6 changes: 5 additions & 1 deletion mod_test/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ def latest_commit_info(platform):
g.log.critical(f"platform {platform} is not supported!")
abort(404)
# Look up the hash of the latest commit
commit_hash = GeneralData.query.filter(GeneralData.key == 'fetch_commit_' + platform.value).first().value
commit_entry = GeneralData.query.filter(GeneralData.key == 'fetch_commit_' + platform.value).first()
if commit_entry is None:
g.log.error(f"no commit hash found for platform {str(platform)}")
raise TestNotFoundException(f"There is no commit hash available for {str(platform)}")
commit_hash = commit_entry.value
test = Test.query.filter(Test.commit == commit_hash, Test.platform == platform).first()

if test is None:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_home/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ def test_if_user_has_test_access_rights(self):
self.assertEqual(response.status_code, 200)
self.assert_context('test_access', True)
self.assert_template_used('home/index.html')

def test_root_without_general_data(self):
"""Test the access of the home page when GeneralData and CCExtractorVersion are empty."""
from flask import g

from mod_home.models import CCExtractorVersion, GeneralData

GeneralData.query.delete()
CCExtractorVersion.query.delete()
g.db.commit()

response = self.app.test_client().get('/')
self.assertEqual(response.status_code, 200)
self.assert_context('ccx_latest_commit', None)
self.assert_context('ccx_last_release', None)
self.assert_template_used('home/index.html')
21 changes: 21 additions & 0 deletions tests/test_sample/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ def test_sample_pass(self, mock_media):
self.assertIn('Repository: Pass', str(response.data))
self.assertIn('Last release: Pass', str(response.data))

@mock.patch('mod_sample.media_info_parser.MediaInfoFetcher')
def test_sample_info_without_commit_or_release(self, mock_media):
"""Test sample info page when GeneralData and CCExtractorVersion are empty."""
from flask import g

import mod_sample.controllers
from mod_home.models import CCExtractorVersion, GeneralData

GeneralData.query.delete()
CCExtractorVersion.query.delete()
g.db.commit()

reload(mod_sample.controllers)
response = self.app.test_client().get('/sample/sample1')
self.assertEqual(response.status_code, 200)
self.assert_template_used('sample/sample_info.html')
self.assert_context('latest_commit', 'Unknown')
self.assert_context('latest_commit_test', None)
self.assert_context('latest_release', 'Unknown')
self.assert_context('latest_release_test', None)

@mock.patch('mod_sample.media_info_parser.MediaInfoFetcher')
def test_sample_fail(self, mock_media):
"""Test the access and data of the failed sample info page."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_test/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,17 @@ def test_download_build_log_file(self, mock_g, mock_serve, mock_test, mock_os):
self.assertEqual(response, mock_serve())
mock_test.query.filter.assert_called_once()
mock_os.path.isfile.assert_called_once()

def test_by_platform_no_commit_hash(self):
"""Test by_platform raises TestNotFoundException when no commit hash in GeneralData."""
from flask import g

from mod_home.models import GeneralData
from mod_test.controllers import TestNotFoundException, by_platform

GeneralData.query.delete()
g.db.commit()

with self.app.test_request_context():
with self.assertRaises(TestNotFoundException):
by_platform('linux')