diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py index 4c2007c..b2d21ab 100644 --- a/api/migrations/0001_initial.py +++ b/api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.25 on 2024-07-11 10:16 +# Generated by Django 3.2.25 on 2024-07-12 15:33 from django.db import migrations, models import django.db.models.deletion @@ -15,7 +15,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Contributor', fields=[ - ('id', models.IntegerField(primary_key=True, serialize=False)), + ('id', models.IntegerField(help_text="The contributor's GitHub user-ID.", primary_key=True, serialize=False)), ('email', models.EmailField(max_length=254, verbose_name='email')), ('name', models.TextField(verbose_name='name')), ('location', models.TextField(verbose_name='location')), @@ -31,8 +31,8 @@ class Migration(migrations.Migration): name='Repository', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('gh_id', models.IntegerField(verbose_name='GitHub ID')), - ('points', models.IntegerField(default=0, verbose_name='points')), + ('gh_id', models.IntegerField(help_text='Github ID of the repo a contributor has contributed to.', verbose_name='GitHub ID')), + ('points', models.IntegerField(default=0, help_text='Story points the contributor closed for this repository.', verbose_name='points')), ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), ], options={ @@ -45,7 +45,7 @@ class Migration(migrations.Migration): name='AgreementSignature', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('agreement_id', models.CharField(max_length=40, verbose_name='agreement id')), + ('agreement_id', models.CharField(help_text='Commit ID of the contribution agreement in workspace.', max_length=40, verbose_name='agreement id')), ('signed_at', models.DateTimeField(verbose_name='signed at')), ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), ], diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 27b59fe..a8f1815 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -22,7 +22,11 @@ class AgreementSignature(models.Model): contributor_id: int contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - agreement_id = models.CharField(_("agreement id"), max_length=40) + agreement_id = models.CharField( + _("agreement id"), + max_length=40, + help_text=_("Commit ID of the contribution agreement in workspace."), + ) signed_at = models.DateTimeField(_("signed at")) class Meta(TypedModelMeta): @@ -31,6 +35,6 @@ class Meta(TypedModelMeta): verbose_name_plural = _("agreement signatures") def __str__(self): - cont = f"Contributor {self.contributor} signed" + cont = f"Contributor {self.contributor.pk} signed" repo = f"{self.agreement_id[:7]} at {self.signed_at}" return f"{cont} {repo}" diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 7554d5a..22c50b8 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -4,10 +4,8 @@ """ from codeforlife.tests import ModelTestCase -from django.db import IntegrityError from .agreement_signature import AgreementSignature -from .contributor import Contributor class TestAgreementSignature(ModelTestCase[AgreementSignature]): @@ -17,36 +15,17 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]): def setUp(self): self.agreement_signature = AgreementSignature.objects.get(pk=1) - self.contributor1 = Contributor.objects.get(pk=1) def test_str(self): - """Parsing a contributor object instance to returns its name.""" + """ + Parsing an agreement-signature instance to a string + that returns the contributor's primary key, + the first 7 characters of the agreement's commit ID + and the timestamp of when the agreement was signed. + """ commit_id = self.agreement_signature.agreement_id[:7] time = self.agreement_signature.signed_at - cont = f"Contributor {self.agreement_signature.contributor} signed" + cont = f"Contributor {self.agreement_signature.contributor.pk} signed" repo = f"{commit_id} at {time}" expected_str = f"{cont} {repo}" assert str(self.agreement_signature) == expected_str - - def test_unique_fields(self): - """Test the unique fields functionality""" - new_contributor = Contributor.objects.create( - id=738237, - email="newcontributor@gmail.com", - name="new contributor", - location="london", - html_url="https://github.com/newcontributor", - avatar_url="https://contributornew.github.io/", - ) - AgreementSignature.objects.create( - contributor=new_contributor, - agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga", - signed_at="2024-01-02T12:00:00Z", - ) - - with self.assertRaises(IntegrityError): - AgreementSignature.objects.create( - contributor=new_contributor, - agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga", - signed_at="2024-01-02T12:00:00Z", - ) diff --git a/api/models/contributor.py b/api/models/contributor.py index ffc83c8..124ac8d 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -17,7 +17,9 @@ class Contributor(models.Model): """A contributor that contributes to a repo""" - id = models.IntegerField(primary_key=True) + id = models.IntegerField( + primary_key=True, help_text=_("The contributor's GitHub user-ID.") + ) email = models.EmailField(_("email")) name = models.TextField(_("name")) location = models.TextField(_("location")) diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index a5858d8..909eda1 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -14,18 +14,12 @@ class TestContributor(ModelTestCase[Contributor]): fixtures = ["contributors"] def setUp(self): - self.contributor1 = Contributor.objects.get(pk=1) - self.contributor2 = Contributor.objects.get(pk=2) - self.contributor3 = Contributor.objects.get(pk=3) + self.contributor = Contributor.objects.get(pk=1) def test_str(self): - """Parsing a contributor object instance to returns its name.""" - name = self.contributor1.name - email = self.contributor1.email - assert str(self.contributor1) == f"{name} <{email}>" - - def test_fields(self): - """Check the correct fields""" - assert self.contributor1.email == "contributor1@gmail.com" - assert self.contributor2.email == "contributor2@gmail.com" - assert self.contributor3.email == "contributor3@gmail.com" + """ + Parsing a contributor instance to a string returns its name and email. + """ + name = self.contributor.name + email = self.contributor.email + assert str(self.contributor) == f"{name} <{email}>" diff --git a/api/models/repository.py b/api/models/repository.py index 127024c..80b2e87 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -17,13 +17,20 @@ class Repository(models.Model): - """A repository to contribute to""" + """A repository that a contributor has contributed to.""" contributor_id: int contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - gh_id = models.IntegerField(_("GitHub ID")) - points = models.IntegerField(_("points"), default=0) + gh_id = models.IntegerField( + _("GitHub ID"), + help_text=_("Github ID of the repo a contributor has contributed to."), + ) + points = models.IntegerField( + _("points"), + default=0, + help_text=_("Story points the contributor closed for this repository."), + ) class Meta(TypedModelMeta): unique_together = ["contributor", "gh_id"] @@ -31,4 +38,4 @@ class Meta(TypedModelMeta): verbose_name_plural = _("repositories") def __str__(self): - return f"{self.contributor}: {self.gh_id}" + return f"{self.contributor.pk}:{self.gh_id}" diff --git a/api/models/repository_test.py b/api/models/repository_test.py index 8e464fe..145add2 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -4,9 +4,7 @@ """ from codeforlife.tests import ModelTestCase -from django.db import IntegrityError -from .contributor import Contributor from .repository import Repository @@ -17,42 +15,12 @@ class TestRepository(ModelTestCase[Repository]): def setUp(self): self.repository = Repository.objects.get(pk=1) - self.contributor1 = Contributor.objects.get(pk=1) - self.contributor2 = Contributor.objects.get(pk=2) def test_str(self): - """Parsing a contributor object instance to returns its name.""" - expected = f"{self.repository.contributor}: {self.repository.gh_id}" + """ + Parsing a repository instance to a string + returns the contributor's primary key and + the repository's GitHub ID. + """ + expected = f"{self.repository.contributor.pk}:{self.repository.gh_id}" assert str(self.repository) == expected - - def test_default_value(self): - """check default value of points if not assigned""" - new_contributor = Contributor.objects.create( - id=425525, - email="newcontributor@gmail.com", - name="new contributor", - location="london", - html_url="https://github.com/newcontributor", - avatar_url="https://contributornew.github.io/", - ) - repository = Repository.objects.create( - contributor=new_contributor, gh_id=432079567 - ) - assert repository.points == 0 - - def test_unique_fields(self): - """Test the unique fields functionality""" - new_contributor = Contributor.objects.create( - id=5134, - email="newcontributor@gmail.com", - name="new contributor", - location="london", - html_url="https://github.com/newcontributor", - avatar_url="https://contributornew.github.io/", - ) - Repository.objects.create(contributor=new_contributor, gh_id=432079567) - - with self.assertRaises(IntegrityError): - Repository.objects.create( - contributor=self.contributor1, gh_id=10274252 - )