Skip to content

Commit ef1659c

Browse files
committed
Add a test for code commit model
Signed-off-by: ziad hany <[email protected]>
1 parent eccbb45 commit ef1659c

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

vulnerabilities/migrations/0103_codecommit_impactedpackage_affecting_commits_and_more.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.22 on 2025-10-30 23:37
1+
# Generated by Django 4.2.22 on 2025-10-31 14:49
22

33
from django.db import migrations, models
44

@@ -27,7 +27,9 @@ class Migration(migrations.Migration):
2727
),
2828
(
2929
"vcs_url",
30-
models.URLField(help_text="URL of the repository containing the commit."),
30+
models.URLField(
31+
help_text="URL of the repository containing the commit.", max_length=1024
32+
),
3133
),
3234
(
3335
"commit_rank",

vulnerabilities/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,7 @@ class CodeCommit(models.Model):
33943394

33953395
commit_hash = models.CharField(max_length=64, help_text="Unique commit identifier (e.g., SHA).")
33963396
vcs_url = models.URLField(
3397-
max_length=200, help_text="URL of the repository containing the commit."
3397+
max_length=1024, help_text="URL of the repository containing the commit."
33983398
)
33993399

34003400
commit_rank = models.IntegerField(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from datetime import datetime
2+
3+
import pytest
4+
5+
from vulnerabilities.models import AdvisoryV2
6+
from vulnerabilities.models import CodeCommit
7+
from vulnerabilities.models import ImpactedPackage
8+
9+
10+
@pytest.mark.django_db
11+
class TestCodeCommit:
12+
def setup_method(self):
13+
date = datetime.now()
14+
adv = AdvisoryV2.objects.create(
15+
unique_content_id="test_id",
16+
url="https://example.com",
17+
summary="summary",
18+
date_imported=date,
19+
date_collected=date,
20+
advisory_id="test_id",
21+
avid="test_pipeline/test_id",
22+
datasource_id="test_pipeline",
23+
)
24+
25+
self.impacted = ImpactedPackage.objects.create(
26+
advisory=adv,
27+
base_purl="pkg:pypi/redis",
28+
)
29+
30+
self.code_commit1 = CodeCommit.objects.create(
31+
commit_hash="8c001a11dbcb3eb6d851e18f4cefa080af5fb398",
32+
vcs_url="https://github.com/aboutcode-org/test1/",
33+
commit_author="tester1",
34+
commit_message="test message1",
35+
commit_date=datetime.now(),
36+
)
37+
38+
self.code_commit2 = CodeCommit.objects.create(
39+
commit_hash="8c001a1",
40+
vcs_url="https://github.com/aboutcode-org/test1/",
41+
)
42+
43+
self.impacted.fixed_by_commits.add(self.code_commit1)
44+
self.impacted.affecting_commits.add(self.code_commit2)
45+
46+
def test_commits_are_created(self):
47+
commits = CodeCommit.objects.all()
48+
assert commits.count() == 2
49+
50+
def test_commit_fields(self):
51+
commit = CodeCommit.objects.get(commit_hash="8c001a11dbcb3eb6d851e18f4cefa080af5fb398")
52+
assert commit.commit_author == "tester1"
53+
assert "test message1" == commit.commit_message
54+
assert commit.commit_date is not None
55+
56+
def test_impacted_packages_creation(self):
57+
assert ImpactedPackage.objects.count() == 1
58+
assert self.code_commit1 == self.impacted.fixed_by_commits.first()

0 commit comments

Comments
 (0)