Skip to content

Commit e7b4d7c

Browse files
cfsmp3claude
authored andcommitted
test(ci): Add tests to improve code coverage
Add missing test cases to increase patch coverage: - Test whitespace stripping in is_valid_commit_hash() - Test rejection of hashes > 40 characters - Test release webhook with existing test entry (covers baseline update path) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cc625be commit e7b4d7c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/test_ci/test_controllers.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,19 @@ def test_is_valid_commit_hash_invalid_chars(self):
21742174
self.assertFalse(is_valid_commit_hash('xyz1234567890'))
21752175
self.assertFalse(is_valid_commit_hash('ghijklm'))
21762176

2177+
def test_is_valid_commit_hash_with_whitespace(self):
2178+
"""Test is_valid_commit_hash strips whitespace correctly."""
2179+
# Valid hash with whitespace should be accepted (whitespace stripped)
2180+
self.assertTrue(is_valid_commit_hash(' 1978060bf7d2edd119736ba3ba88341f3bec3323 '))
2181+
self.assertTrue(is_valid_commit_hash('\t1978060\n'))
2182+
2183+
def test_is_valid_commit_hash_too_long(self):
2184+
"""Test is_valid_commit_hash rejects hashes > 40 characters."""
2185+
# 41 characters - too long
2186+
self.assertFalse(is_valid_commit_hash('1978060bf7d2edd119736ba3ba88341f3bec33231'))
2187+
# 50 characters - way too long
2188+
self.assertFalse(is_valid_commit_hash('1978060bf7d2edd119736ba3ba88341f3bec332312345678'))
2189+
21772190
@mock.patch('mod_ci.controllers.add_test_entry')
21782191
@mock.patch('github.Github.get_repo')
21792192
@mock.patch('requests.get', side_effect=mock_api_request_github)
@@ -2270,6 +2283,42 @@ def test_webhook_release_invalid_commit_fallback(self, mock_request, mock_repo):
22702283
self.assertIsNotNone(release)
22712284
self.assertEqual(release.commit, fallback_commit)
22722285

2286+
@mock.patch('github.Github.get_repo')
2287+
@mock.patch('requests.get', side_effect=mock_api_request_github)
2288+
def test_webhook_release_with_existing_test(self, mock_request, mock_repo):
2289+
"""Test release webhook updates baseline when test entry exists for commit."""
2290+
# Setup mock for tag ref (lightweight tag)
2291+
commit_hash = "eeee555566667777888899990000aaaabbbbcccc"
2292+
mock_tag_ref = MagicMock()
2293+
mock_tag_ref.object.type = "commit"
2294+
mock_tag_ref.object.sha = commit_hash
2295+
mock_repo.return_value.get_git_ref.return_value = mock_tag_ref
2296+
2297+
# Create a test entry for this commit
2298+
from mod_test.models import Fork
2299+
fork = Fork.query.first()
2300+
test = Test(TestPlatform.linux, TestType.commit, fork.id, "master", commit_hash, 0)
2301+
g.db.add(test)
2302+
g.db.commit()
2303+
2304+
with self.app.test_client() as c:
2305+
data = {
2306+
'action': 'published',
2307+
'release': {
2308+
'prerelease': False,
2309+
'published_at': '2018-05-30T20:18:44Z',
2310+
'tag_name': 'v2.6'
2311+
}
2312+
}
2313+
response = c.post(
2314+
'/start-ci', environ_overrides=WSGI_ENVIRONMENT,
2315+
data=json.dumps(data), headers=self.generate_header(data, 'release'))
2316+
2317+
# Release should be created with the commit from tag
2318+
release = CCExtractorVersion.query.filter_by(version='2.6').first()
2319+
self.assertIsNotNone(release)
2320+
self.assertEqual(release.commit, commit_hash)
2321+
22732322
@mock.patch('github.Github.get_repo')
22742323
@mock.patch('requests.get', side_effect=mock_api_request_github)
22752324
def test_webhook_release_no_valid_commit_fails(self, mock_request, mock_repo):

0 commit comments

Comments
 (0)