Skip to content

Commit

Permalink
Apply changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmanAsh committed Jul 10, 2024
1 parent 5dab9d0 commit 8b23360
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 152 deletions.
27 changes: 0 additions & 27 deletions api/migrations/0001_initial.py

This file was deleted.

53 changes: 0 additions & 53 deletions api/migrations/0002_agreementsignature_contributor_repository.py

This file was deleted.

21 changes: 0 additions & 21 deletions api/migrations/0003_auto_20240709_1347.py

This file was deleted.

16 changes: 0 additions & 16 deletions api/migrations/0004_delete_fruit.py

This file was deleted.

2 changes: 2 additions & 0 deletions api/models/agreement_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class AgreementSignature(models.Model):
"""Signature of a contributor signing the agreement"""

contributor: int
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)

agreement_id = models.CharField(max_length=40)
signed_at = models.DateTimeField()

Expand Down
8 changes: 4 additions & 4 deletions api/models/agreement_signature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]):

def setUp(self):
self.agreement_signature = AgreementSignature.objects.get(pk=1)
self.contributor1 = Contributor.objects.get(pk=111111)
self.contributor1 = Contributor.objects.get(pk=1)

def test_str(self):
"""Parsing a contributor object instance to returns its name."""
Expand All @@ -40,13 +40,13 @@ def test_unique_fields(self):
)
AgreementSignature.objects.create(
contributor=new_contributor,
agreement_id="g3d3d3s8dg2342c37",
agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga",
signed_at="2024-01-02T12:00:00Z",
)

with self.assertRaises(IntegrityError):
AgreementSignature.objects.create(
contributor=self.contributor1,
agreement_id="g3d3d3s8dgd3vc37",
contributor=new_contributor,
agreement_id="pyu66uehr8dgd43vc37232fef0898df3f3f31fga",
signed_at="2024-01-02T12:00:00Z",
)
4 changes: 2 additions & 2 deletions api/models/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Contributor(models.Model):
"""A contributor that contributes to a repo"""

id = models.IntegerField(primary_key=True)
email = models.TextField()
email = models.EmailField()
name = models.TextField()
location = models.TextField()
html_url = models.TextField()
Expand All @@ -29,4 +29,4 @@ class Meta(TypedModelMeta):
verbose_name_plural = _("contributors")

def __str__(self):
return self.name
return f"{self.name} <{self.email}>"
12 changes: 6 additions & 6 deletions api/models/contributor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class TestContributor(ModelTestCase[Contributor]):
fixtures = ["contributors"]

def setUp(self):
self.contributor1 = Contributor.objects.get(pk=111111)
self.contributor2 = Contributor.objects.get(pk=222222)
self.contributor3 = Contributor.objects.get(pk=333333)
self.contributor1 = Contributor.objects.get(pk=1)
self.contributor2 = Contributor.objects.get(pk=2)
self.contributor3 = Contributor.objects.get(pk=3)

def test_str(self):
"""Parsing a contributor object instance to returns its name."""
assert str(self.contributor1) == self.contributor1.name
assert str(self.contributor2) == self.contributor2.name
assert str(self.contributor3) == self.contributor3.name
name = self.contributor1.name
email = self.contributor1.email
assert str(self.contributor1) == f"{name} <{email}>"

def test_fields(self):
"""Check the correct fields"""
Expand Down
10 changes: 5 additions & 5 deletions api/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
class Repository(models.Model):
"""A repository to contribute to"""

id = models.IntegerField(primary_key=True)
contributor_id: int
contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE)
NAME_CHOICES = [("portal", "portal"), ("rr", "rr")]
name = models.TextField(choices=NAME_CHOICES)

gh_id = models.IntegerField(_("GitHub ID"))
points = models.IntegerField(default=0)

class Meta(TypedModelMeta):
unique_together = ["contributor", "name"]
unique_together = ["contributor", "gh_id"]
verbose_name = _("repository")
verbose_name_plural = _("repositories")

def __str__(self):
return self.name
return f"{self.contributor}: {self.gh_id}"
20 changes: 9 additions & 11 deletions api/models/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from codeforlife.tests import ModelTestCase
from django.db import IntegrityError

# from .agreement_signature import AgreementSignature
from .contributor import Contributor
from .repository import Repository

Expand All @@ -17,13 +16,14 @@ class TestRepository(ModelTestCase[Repository]):
fixtures = ["contributors", "repositories"]

def setUp(self):
self.repository = Repository.objects.get(pk=111)
self.contributor1 = Contributor.objects.get(pk=111111)
self.contributor2 = Contributor.objects.get(pk=222222)
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."""
assert str(self.repository) == self.repository.name
expected = f"{self.repository.contributor}: {self.repository.gh_id}"
assert str(self.repository) == expected

def test_default_value(self):
"""check default value of points if not assigned"""
Expand All @@ -36,25 +36,23 @@ def test_default_value(self):
avatar_url="https://contributornew.github.io/",
)
repository = Repository.objects.create(
id=999, contributor=new_contributor, name="portal"
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=999999,
id=5134,
email="[email protected]",
name="new contributor",
location="london",
html_url="https://github.com/newcontributor",
avatar_url="https://contributornew.github.io/",
)
Repository.objects.create(
id=123, contributor=new_contributor, name="rr"
)
Repository.objects.create(contributor=new_contributor, gh_id=432079567)

with self.assertRaises(IntegrityError):
Repository.objects.create(
id=999, contributor=self.contributor1, name="rr"
contributor=self.contributor1, gh_id=10274252
)
7 changes: 0 additions & 7 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
from codeforlife.urls import get_urlpatterns
from rest_framework.routers import DefaultRouter

# from .views import FruitViewSet

router = DefaultRouter()
# router.register(
# "fruits",
# FruitViewSet,
# basename="fruit",
# )

urlpatterns = get_urlpatterns(router.urls)

0 comments on commit 8b23360

Please sign in to comment.