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.
- Loading branch information
Showing
7 changed files
with
45 additions
and
91 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
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 |
---|---|---|
|
@@ -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="[email protected]", | ||
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", | ||
) |
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 |
---|---|---|
|
@@ -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 == "[email protected]" | ||
assert self.contributor2.email == "[email protected]" | ||
assert self.contributor3.email == "[email protected]" | ||
""" | ||
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 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 |
---|---|---|
|
@@ -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="[email protected]", | ||
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="[email protected]", | ||
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 | ||
) |