Skip to content

Commit 6588722

Browse files
committed
Apply changes from second review
1 parent bf17776 commit 6588722

6 files changed

+40
-86
lines changed

api/models/agreement_signature.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class AgreementSignature(models.Model):
2222
contributor_id: int
2323
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)
2424

25-
agreement_id = models.CharField(_("agreement id"), max_length=40)
25+
agreement_id = models.CharField(
26+
_("agreement id"),
27+
max_length=40,
28+
help_text=_("Commit ID of the contribution agreement in workspace."),
29+
)
2630
signed_at = models.DateTimeField(_("signed at"))
2731

2832
class Meta(TypedModelMeta):
@@ -31,6 +35,6 @@ class Meta(TypedModelMeta):
3135
verbose_name_plural = _("agreement signatures")
3236

3337
def __str__(self):
34-
cont = f"Contributor {self.contributor} signed"
38+
cont = f"Contributor {self.contributor.pk} signed"
3539
repo = f"{self.agreement_id[:7]} at {self.signed_at}"
3640
return f"{cont} {repo}"

api/models/agreement_signature_test.py

+7-28
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
"""
55

66
from codeforlife.tests import ModelTestCase
7-
from django.db import IntegrityError
87

98
from .agreement_signature import AgreementSignature
10-
from .contributor import Contributor
119

1210

1311
class TestAgreementSignature(ModelTestCase[AgreementSignature]):
@@ -17,36 +15,17 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]):
1715

1816
def setUp(self):
1917
self.agreement_signature = AgreementSignature.objects.get(pk=1)
20-
self.contributor1 = Contributor.objects.get(pk=1)
2118

2219
def test_str(self):
23-
"""Parsing a contributor object instance to returns its name."""
20+
"""
21+
Parsing an agreement-signature instance to a string
22+
that returns the contributor's primary key,
23+
the first 7 characters of the agreement's commit ID
24+
and the timestamp of when the agreement was signed.
25+
"""
2426
commit_id = self.agreement_signature.agreement_id[:7]
2527
time = self.agreement_signature.signed_at
26-
cont = f"Contributor {self.agreement_signature.contributor} signed"
28+
cont = f"Contributor {self.agreement_signature.contributor.pk} signed"
2729
repo = f"{commit_id} at {time}"
2830
expected_str = f"{cont} {repo}"
2931
assert str(self.agreement_signature) == expected_str
30-
31-
def test_unique_fields(self):
32-
"""Test the unique fields functionality"""
33-
new_contributor = Contributor.objects.create(
34-
id=738237,
35-
36-
name="new contributor",
37-
location="london",
38-
html_url="https://github.com/newcontributor",
39-
avatar_url="https://contributornew.github.io/",
40-
)
41-
AgreementSignature.objects.create(
42-
contributor=new_contributor,
43-
agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga",
44-
signed_at="2024-01-02T12:00:00Z",
45-
)
46-
47-
with self.assertRaises(IntegrityError):
48-
AgreementSignature.objects.create(
49-
contributor=new_contributor,
50-
agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga",
51-
signed_at="2024-01-02T12:00:00Z",
52-
)

api/models/contributor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
class Contributor(models.Model):
1818
"""A contributor that contributes to a repo"""
1919

20-
id = models.IntegerField(primary_key=True)
20+
id = models.IntegerField(
21+
primary_key=True, help_text=_("The contributor's GitHub user-ID.")
22+
)
2123
email = models.EmailField(_("email"))
2224
name = models.TextField(_("name"))
2325
location = models.TextField(_("location"))

api/models/contributor_test.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ class TestContributor(ModelTestCase[Contributor]):
1414
fixtures = ["contributors"]
1515

1616
def setUp(self):
17-
self.contributor1 = Contributor.objects.get(pk=1)
18-
self.contributor2 = Contributor.objects.get(pk=2)
19-
self.contributor3 = Contributor.objects.get(pk=3)
17+
self.contributor = Contributor.objects.get(pk=1)
2018

2119
def test_str(self):
22-
"""Parsing a contributor object instance to returns its name."""
23-
name = self.contributor1.name
24-
email = self.contributor1.email
25-
assert str(self.contributor1) == f"{name} <{email}>"
26-
27-
def test_fields(self):
28-
"""Check the correct fields"""
29-
assert self.contributor1.email == "[email protected]"
30-
assert self.contributor2.email == "[email protected]"
31-
assert self.contributor3.email == "[email protected]"
20+
"""
21+
Parsing a contributor instance to a string returns its name and email.
22+
"""
23+
name = self.contributor.name
24+
email = self.contributor.email
25+
assert str(self.contributor) == f"{name} <{email}>"

api/models/repository.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@
1717

1818

1919
class Repository(models.Model):
20-
"""A repository to contribute to"""
20+
"""A repository that a contributor has contributed to."""
2121

2222
contributor_id: int
2323
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)
2424

25-
gh_id = models.IntegerField(_("GitHub ID"))
26-
points = models.IntegerField(_("points"), default=0)
25+
gh_id = models.IntegerField(
26+
_("GitHub ID"),
27+
help_text=_("Github ID of the repo a contributor has contributed to."),
28+
)
29+
points = models.IntegerField(
30+
_("points"),
31+
default=0,
32+
help_text=_("Story points the contributor closed for this repository."),
33+
)
2734

2835
class Meta(TypedModelMeta):
2936
unique_together = ["contributor", "gh_id"]
3037
verbose_name = _("repository")
3138
verbose_name_plural = _("repositories")
3239

3340
def __str__(self):
34-
return f"{self.contributor}: {self.gh_id}"
41+
return f"{self.contributor.pk}:{self.gh_id}"

api/models/repository_test.py

+6-38
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"""
55

66
from codeforlife.tests import ModelTestCase
7-
from django.db import IntegrityError
87

9-
from .contributor import Contributor
108
from .repository import Repository
119

1210

@@ -17,42 +15,12 @@ class TestRepository(ModelTestCase[Repository]):
1715

1816
def setUp(self):
1917
self.repository = Repository.objects.get(pk=1)
20-
self.contributor1 = Contributor.objects.get(pk=1)
21-
self.contributor2 = Contributor.objects.get(pk=2)
2218

2319
def test_str(self):
24-
"""Parsing a contributor object instance to returns its name."""
25-
expected = f"{self.repository.contributor}: {self.repository.gh_id}"
20+
"""
21+
Parsing a repository instance to a string
22+
returns the contributor's primary key and
23+
the repository's GitHub ID.
24+
"""
25+
expected = f"{self.repository.contributor.pk}:{self.repository.gh_id}"
2626
assert str(self.repository) == expected
27-
28-
def test_default_value(self):
29-
"""check default value of points if not assigned"""
30-
new_contributor = Contributor.objects.create(
31-
id=425525,
32-
33-
name="new contributor",
34-
location="london",
35-
html_url="https://github.com/newcontributor",
36-
avatar_url="https://contributornew.github.io/",
37-
)
38-
repository = Repository.objects.create(
39-
contributor=new_contributor, gh_id=432079567
40-
)
41-
assert repository.points == 0
42-
43-
def test_unique_fields(self):
44-
"""Test the unique fields functionality"""
45-
new_contributor = Contributor.objects.create(
46-
id=5134,
47-
48-
name="new contributor",
49-
location="london",
50-
html_url="https://github.com/newcontributor",
51-
avatar_url="https://contributornew.github.io/",
52-
)
53-
Repository.objects.create(contributor=new_contributor, gh_id=432079567)
54-
55-
with self.assertRaises(IntegrityError):
56-
Repository.objects.create(
57-
contributor=self.contributor1, gh_id=10274252
58-
)

0 commit comments

Comments
 (0)