Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 56d5d31

Browse files
Add Tests for PR#1285
1 parent abadaf4 commit 56d5d31

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

webhook_handlers/tests/test_github.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,3 +1420,70 @@ def test_repo_creation_doesnt_crash_for_forked_repo(self):
14201420
)
14211421

14221422
assert owner.repository_set.filter(name="testrepo").exists()
1423+
1424+
def test_check_codecov_ai_auto_enabled_reviews(self):
1425+
"""
1426+
Tests the check_codecov_ai_auto_enabled_reviews method directly
1427+
for both enabled and disabled AI PR review cases
1428+
"""
1429+
# Create an organization with AI PR review enabled
1430+
org_with_ai_enabled = OwnerFactory(
1431+
service=Service.GITHUB.value,
1432+
yaml={"ai_pr_review": {"auto_review": True}}
1433+
)
1434+
1435+
# Create an organization with AI PR review disabled
1436+
org_with_ai_disabled = OwnerFactory(
1437+
service=Service.GITHUB.value,
1438+
yaml={"ai_pr_review": {"auto_review": False}}
1439+
)
1440+
1441+
# Create an organization with no AI PR review configuration
1442+
org_with_no_ai_config = OwnerFactory(
1443+
service=Service.GITHUB.value,
1444+
yaml={}
1445+
)
1446+
1447+
handler = GithubWebhookHandler()
1448+
1449+
# Test with AI PR review enabled
1450+
request = self.factory.post("/", data={"organization": {"id": org_with_ai_enabled.service_id}})
1451+
response = handler.check_codecov_ai_auto_enabled_reviews(request)
1452+
assert response.data == {"auto_review_enabled": True}
1453+
1454+
# Test with AI PR review disabled
1455+
request = self.factory.post("/", data={"organization": {"id": org_with_ai_disabled.service_id}})
1456+
response = handler.check_codecov_ai_auto_enabled_reviews(request)
1457+
assert response.data == {"auto_review_enabled": False}
1458+
1459+
# Test with no AI PR review configuration
1460+
request = self.factory.post("/", data={"organization": {"id": org_with_no_ai_config.service_id}})
1461+
response = handler.check_codecov_ai_auto_enabled_reviews(request)
1462+
assert response.data == {"auto_review_enabled": False}
1463+
1464+
def test_repo_creation_doesnt_crash_for_forked_repo(self):
1465+
owner = OwnerFactory(service=Service.GITHUB.value, integration_id=4850403)
1466+
self._post_event_data(
1467+
event=GitHubWebhookEvents.REPOSITORY,
1468+
data={
1469+
"action": "publicized",
1470+
"repository": {
1471+
"id": 506003,
1472+
"name": "testrepo",
1473+
"private": False,
1474+
"default_branch": "master",
1475+
"owner": {"id": owner.service_id},
1476+
"fork": True,
1477+
"parent": {
1478+
"name": "mainrepo",
1479+
"language": "python",
1480+
"id": 7940284,
1481+
"private": False,
1482+
"default_branch": "master",
1483+
"owner": {"id": 8495712939, "login": "alogin"},
1484+
},
1485+
},
1486+
},
1487+
)
1488+
1489+
assert owner.repository_set.filter(name="testrepo").exists()

0 commit comments

Comments
 (0)