generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start api models for contribution agreement (#82) * api models for contribution * change import sorting and format * fixture data for testing * change model fields * test string parsing * Migrate models * fixture data for testing * api models and tests files * fix import statements * fix code format * Fix static types * fix linting test file format * import fix * Check static code * import sort * update DateTime Field * Tests for models * Repository testing * fix class name * tests for models * correct formatting and comments * Change meta classes * Fix code format and imports * Delete all fruit files * Delete last fruit migration * Fix migration issue * change data fields * Apply changes after review * apply initial migrations * Fix contributor type error * Add verbose names * Fix import error * Apply changes from second review * Migrate models --------- Co-authored-by: Stefan Kairinos <[email protected]>
- Loading branch information
Showing
21 changed files
with
332 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[ | ||
{ | ||
"model": "api.agreementsignature", | ||
"pk": 1, | ||
"fields": { | ||
"contributor": 1, | ||
"agreement_id": "g3d3d3s8dgd3vc37232fef32232df3f3f31fgawf", | ||
"signed_at": "2024-01-02T12:00:00Z" | ||
} | ||
}, | ||
{ | ||
"model": "api.agreementsignature", | ||
"pk": 2, | ||
"fields": { | ||
"contributor": 2, | ||
"agreement_id": "g3d3d3s8dgd43vc37232fef0898df3f3f31fgawf", | ||
"signed_at": "2024-01-02T12:00:00Z" | ||
} | ||
}, | ||
{ | ||
"model": "api.agreementsignature", | ||
"pk": 3, | ||
"fields": { | ||
"contributor": 3, | ||
"agreement_id": "g379tuehr8dgd43vc37232fef0898df3f3f31fga", | ||
"signed_at": "2024-01-02T12:00:00Z" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[ | ||
{ | ||
"model": "api.contributor", | ||
"pk": 1, | ||
"fields": { | ||
"email": "[email protected]", | ||
"name": "contributor1", | ||
"location": "Hatfield", | ||
"html_url": "https://github.com/contributor1", | ||
"avatar_url": "https://contributor1.github.io/gravatar-url-generator/#/" | ||
} | ||
}, | ||
{ | ||
"model": "api.contributor", | ||
"pk": 2, | ||
"fields": { | ||
"email": "[email protected]", | ||
"name": "contributor2", | ||
"location": "Hatfield", | ||
"html_url": "https://github.com/contributor2", | ||
"avatar_url": "https://contributor2.github.io/gravatar-url-generator/#/" | ||
} | ||
}, | ||
{ | ||
"model": "api.contributor", | ||
"pk": 3, | ||
"fields": { | ||
"email": "[email protected]", | ||
"name": "contributor3", | ||
"location": "Hatfield", | ||
"html_url": "https://github.com/contributor3", | ||
"avatar_url": "https://contributor3.github.io/gravatar-url-generator/#/" | ||
} | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"model": "api.repository", | ||
"pk": 1, | ||
"fields": { | ||
"contributor": 1, | ||
"points": 10, | ||
"gh_id": "10274252" | ||
} | ||
}, | ||
{ | ||
"model": "api.repository", | ||
"pk": 2, | ||
"fields": { | ||
"contributor": 2, | ||
"points": 20, | ||
"gh_id": "102097552" | ||
|
||
} | ||
}, | ||
{ | ||
"model": "api.repository", | ||
"pk": 3, | ||
"fields": { | ||
"contributor": 3, | ||
"points": 30, | ||
"gh_id": "890732552" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
© Ocado Group | ||
Created on 08/07/2024 at 10:48:44(+01:00). | ||
""" | ||
|
||
import typing as t | ||
|
||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from .contributor import Contributor | ||
|
||
if t.TYPE_CHECKING: | ||
from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover | ||
else: | ||
TypedModelMeta = object | ||
|
||
|
||
class AgreementSignature(models.Model): | ||
"""Signature of a contributor signing the agreement""" | ||
|
||
contributor_id: int | ||
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) | ||
|
||
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): | ||
unique_together = ["contributor", "agreement_id"] | ||
verbose_name = _("agreement signature") | ||
verbose_name_plural = _("agreement signatures") | ||
|
||
def __str__(self): | ||
cont = f"Contributor {self.contributor.pk} signed" | ||
repo = f"{self.agreement_id[:7]} at {self.signed_at}" | ||
return f"{cont} {repo}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
© Ocado Group | ||
Created on 09/07/2024 at 11:43:42(+01:00). | ||
""" | ||
|
||
from codeforlife.tests import ModelTestCase | ||
|
||
from .agreement_signature import AgreementSignature | ||
|
||
|
||
class TestAgreementSignature(ModelTestCase[AgreementSignature]): | ||
"""Test the AgreementSignature Model""" | ||
|
||
fixtures = ["contributors", "agreement_signatures"] | ||
|
||
def setUp(self): | ||
self.agreement_signature = AgreementSignature.objects.get(pk=1) | ||
|
||
def test_str(self): | ||
""" | ||
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.pk} signed" | ||
repo = f"{commit_id} at {time}" | ||
expected_str = f"{cont} {repo}" | ||
assert str(self.agreement_signature) == expected_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/07/2024 at 16:18:48(+01:00). | ||
""" | ||
|
||
import typing as t | ||
|
||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
if t.TYPE_CHECKING: | ||
from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover | ||
else: | ||
TypedModelMeta = object | ||
|
||
|
||
class Contributor(models.Model): | ||
"""A contributor that contributes to a repo""" | ||
|
||
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")) | ||
html_url = models.TextField(_("html url")) | ||
avatar_url = models.TextField(_("avatar url")) | ||
|
||
class Meta(TypedModelMeta): | ||
verbose_name = _("contributor") | ||
verbose_name_plural = _("contributors") | ||
|
||
def __str__(self): | ||
return f"{self.name} <{self.email}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
© Ocado Group | ||
Created on 09/07/2024 at 09:39:50(+01:00). | ||
""" | ||
|
||
from codeforlife.tests import ModelTestCase | ||
|
||
from .contributor import Contributor | ||
|
||
|
||
class TestContributor(ModelTestCase[Contributor]): | ||
"""Test the Contributor Model""" | ||
|
||
fixtures = ["contributors"] | ||
|
||
def setUp(self): | ||
self.contributor = Contributor.objects.get(pk=1) | ||
|
||
def test_str(self): | ||
""" | ||
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}>" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.