From b267d6fe91246b518cfbb67fb831b031e631a46f Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Fri, 5 Jul 2024 15:50:02 +0000 Subject: [PATCH 01/42] Start api models for contribution agreement (#82) --- api/models/contributor.py | 20 ++++++++++++++++++++ api/models/repository.py | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 api/models/contributor.py create mode 100644 api/models/repository.py diff --git a/api/models/contributor.py b/api/models/contributor.py new file mode 100644 index 0000000..3d46f57 --- /dev/null +++ b/api/models/contributor.py @@ -0,0 +1,20 @@ +""" +© Ocado Group +Created on 05/07/2024 at 16:18:48(+01:00). + +""" + +from django.db import models + +class Contributor(models.Model): + """ A contributor """ + id = models.IntegerField(primary_key=True) + email = models.TextField() + name = models.TextField() + location = models.TextField() + html_url = models.TextField() + avatar_url = models.TextField() + + def __str__(self): + return super().name + \ No newline at end of file diff --git a/api/models/repository.py b/api/models/repository.py new file mode 100644 index 0000000..db25d00 --- /dev/null +++ b/api/models/repository.py @@ -0,0 +1,6 @@ +""" +© Ocado Group +Created on 05/07/2024 at 16:39:14(+01:00). + +""" +from django.db import models From 84fd2a1c94b310618aff7dcf0038949ef1784790 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Mon, 8 Jul 2024 10:37:36 +0000 Subject: [PATCH 02/42] api models for contribution --- api/models/agreement_signature.py | 23 +++++++++++++++++++++++ api/models/contributor.py | 4 ++-- api/models/repository.py | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 api/models/agreement_signature.py diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py new file mode 100644 index 0000000..0d89b6f --- /dev/null +++ b/api/models/agreement_signature.py @@ -0,0 +1,23 @@ +""" +© Ocado Group +Created on 08/07/2024 at 10:48:44(+01:00). + +""" + +from django.db import models +from .contributor import Contributor + +class AgreementSignature(models.Model): + """ Signature of a contributor signing the agreement """ + id = models.AutoField(primary_key=True) + contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) + agreement_id = models.CharField(max_length=40) + signed_at = models.DateTimeField() + + def __str__(self): + return self.id + + class Meta: + constraints = [ + models.UniqueConstraint(fields=["contributor", "agreement_id"], name='unique_contributor_agreement') + ] \ No newline at end of file diff --git a/api/models/contributor.py b/api/models/contributor.py index 3d46f57..07c5cb7 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -7,7 +7,7 @@ from django.db import models class Contributor(models.Model): - """ A contributor """ + """ A contributor that contributes to a repo""" id = models.IntegerField(primary_key=True) email = models.TextField() name = models.TextField() @@ -16,5 +16,5 @@ class Contributor(models.Model): avatar_url = models.TextField() def __str__(self): - return super().name + return self.name \ No newline at end of file diff --git a/api/models/repository.py b/api/models/repository.py index db25d00..09e4f84 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -4,3 +4,23 @@ """ from django.db import models +from .contributor import Contributor + +class Repository(models.Model): + """ A repository to contribute to""" + id = models.IntegerField(primary_key=True) + contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) + name_choices = [ + ("portal", "portal"), + ("rr", "rr") + ] + name = models.TextField(choices=name_choices) + points = models.IntegerField(default=0) + + def __str__(self): + return self.name + + class Meta: + constraints = [ + models.UniqueConstraint(fields=["contributor", "name"], name='unique_contributor_repo') + ] \ No newline at end of file From 1db562a5db08912b19e34aaf59b2da5168fe7497 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Mon, 8 Jul 2024 10:43:57 +0000 Subject: [PATCH 03/42] change import sorting and format --- api/models/agreement_signature.py | 9 +++++++++ api/models/contributor.py | 8 ++++++++ api/models/repository.py | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 0d89b6f..94554d9 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -3,10 +3,19 @@ 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 +else: + TypedModelMeta = object + + + class AgreementSignature(models.Model): """ Signature of a contributor signing the agreement """ id = models.AutoField(primary_key=True) diff --git a/api/models/contributor.py b/api/models/contributor.py index 07c5cb7..5d7f119 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -4,7 +4,15 @@ """ +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 +else: + TypedModelMeta = object class Contributor(models.Model): """ A contributor that contributes to a repo""" diff --git a/api/models/repository.py b/api/models/repository.py index 09e4f84..8a55448 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -3,9 +3,18 @@ Created on 05/07/2024 at 16:39:14(+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 +else: + TypedModelMeta = object + class Repository(models.Model): """ A repository to contribute to""" id = models.IntegerField(primary_key=True) From b70bda67b0e139b7ce202e3a581ce2d68627711d Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 08:37:00 +0000 Subject: [PATCH 04/42] fixture data for testing --- api/fixtures/agreement_signature.json | 29 ++++++++++++++++++++++ api/fixtures/contributor.json | 35 +++++++++++++++++++++++++++ api/fixtures/repository.json | 29 ++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 api/fixtures/agreement_signature.json create mode 100644 api/fixtures/contributor.json create mode 100644 api/fixtures/repository.json diff --git a/api/fixtures/agreement_signature.json b/api/fixtures/agreement_signature.json new file mode 100644 index 0000000..cf861a6 --- /dev/null +++ b/api/fixtures/agreement_signature.json @@ -0,0 +1,29 @@ +[ + { + "model": "api.agreement_signature", + "pk": 1, + "fields": { + "contributor": 111111, + "agreement_id": "g3d3d3s8dgd3vc37", + "signed_at": "2023-01-01" + } + }, + { + "model": "api.agreement_signature", + "pk": 2, + "fields": { + "contributor": 222222, + "agreement_id": "g3d3d3s8dgd3vc37", + "signed_at": "2023-01-01" + } + }, + { + "model": "api.agreement_signature", + "pk": 3, + "fields": { + "contributor": 333333, + "agreement_id": "g3d3d3s8dgd3vc37", + "signed_at": "2023-01-01" + } + } +] diff --git a/api/fixtures/contributor.json b/api/fixtures/contributor.json new file mode 100644 index 0000000..2a2b11f --- /dev/null +++ b/api/fixtures/contributor.json @@ -0,0 +1,35 @@ +[ + { + "model": "api.contributor", + "pk": 111111, + "fields": { + "email": "contributor1@gmail.com", + "name": "contributor1", + "location": "Hatfield", + "html_url": "https://github.com/contributor1", + "avatar_url": "https://contributor1.github.io/gravatar-url-generator/#/" + } + }, + { + "model": "api.contributor", + "pk": 222222, + "fields": { + "email": "contributor2@gmail.com", + "name": "contributor2", + "location": "Hatfield", + "html_url": "https://github.com/contributor2", + "avatar_url": "https://contributor2.github.io/gravatar-url-generator/#/" + } + }, + { + "model": "api.contributor", + "pk": 333333, + "fields": { + "email": "contributor3@gmail.com", + "name": "contributor3", + "location": "Hatfield", + "html_url": "https://github.com/contributor3", + "avatar_url": "https://contributor3.github.io/gravatar-url-generator/#/" + } + } +] diff --git a/api/fixtures/repository.json b/api/fixtures/repository.json new file mode 100644 index 0000000..fa7de61 --- /dev/null +++ b/api/fixtures/repository.json @@ -0,0 +1,29 @@ +[ + { + "model": "api.repository", + "pk": 111, + "fields": { + "contributor": 111111, + "name": "rr", + "points": 10 + } + }, + { + "model": "api.repository", + "pk": 222, + "fields": { + "contributor": 222222, + "name": "rr", + "points": 20 + } + }, + { + "model": "api.repository", + "pk": 333, + "fields": { + "contributor": 333333, + "name": "rr", + "points": 30 + } + } +] From bdb75818bcd29ddbac24bc6e16ea3ecca1d34d0e Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 08:38:07 +0000 Subject: [PATCH 05/42] change model fields --- api/models/agreement_signature.py | 17 ++++++++--------- api/models/agreement_signature_test.py | 0 api/models/contributor_test.py | 0 api/models/repository.py | 17 ++++++++--------- api/models/repository_test.py | 0 5 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 api/models/agreement_signature_test.py create mode 100644 api/models/contributor_test.py create mode 100644 api/models/repository_test.py diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 94554d9..c44e1ac 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -3,30 +3,29 @@ 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 + + from .contributor import Contributor else: TypedModelMeta = object - class AgreementSignature(models.Model): """ Signature of a contributor signing the agreement """ - id = models.AutoField(primary_key=True) contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - - def __str__(self): - return self.id class Meta: - constraints = [ - models.UniqueConstraint(fields=["contributor", "agreement_id"], name='unique_contributor_agreement') - ] \ No newline at end of file + unique_together = ["contributor", "agreement_id"] + + def __str__(self): + return f"Contributor {self.contributor} signed + {self.agreement_id[:7]} at {self.signed_at}" \ No newline at end of file diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models/repository.py b/api/models/repository.py index 8a55448..d112df6 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -8,10 +8,11 @@ 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 + + from .contributor import Contributor else: TypedModelMeta = object @@ -19,17 +20,15 @@ class Repository(models.Model): """ A repository to contribute to""" id = models.IntegerField(primary_key=True) contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - name_choices = [ + NAME_CHOICES = [ ("portal", "portal"), ("rr", "rr") ] - name = models.TextField(choices=name_choices) + name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) - - def __str__(self): - return self.name class Meta: - constraints = [ - models.UniqueConstraint(fields=["contributor", "name"], name='unique_contributor_repo') - ] \ No newline at end of file + unique_together = ["contributor", "name"] + + def __str__(self): + return self.name \ No newline at end of file diff --git a/api/models/repository_test.py b/api/models/repository_test.py new file mode 100644 index 0000000..e69de29 From 24dc96a1c28e890f9bf458fc3f8b7a0cd81b6d04 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 10:08:55 +0000 Subject: [PATCH 06/42] test string parsing --- .../{contributor.json => contributors.json} | 0 api/migrations/0002_contributor.py | 28 +++++++++++++++++++ api/models/__init__.py | 1 + api/models/agreement_signature.py | 5 ++-- api/models/contributor.py | 4 +++ api/models/contributor_test.py | 21 ++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) rename api/fixtures/{contributor.json => contributors.json} (100%) create mode 100644 api/migrations/0002_contributor.py diff --git a/api/fixtures/contributor.json b/api/fixtures/contributors.json similarity index 100% rename from api/fixtures/contributor.json rename to api/fixtures/contributors.json diff --git a/api/migrations/0002_contributor.py b/api/migrations/0002_contributor.py new file mode 100644 index 0000000..bfc61bb --- /dev/null +++ b/api/migrations/0002_contributor.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.25 on 2024-07-09 09:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Contributor', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('email', models.TextField()), + ('name', models.TextField()), + ('location', models.TextField()), + ('html_url', models.TextField()), + ('avatar_url', models.TextField()), + ], + options={ + 'verbose_name': 'contributor', + 'verbose_name_plural': 'contributors', + }, + ), + ] diff --git a/api/models/__init__.py b/api/models/__init__.py index e1098b7..1bdf013 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -4,3 +4,4 @@ """ from .fruit import Fruit +from .contributor import Contributor diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index c44e1ac..9bf6c22 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -27,5 +27,6 @@ class Meta: unique_together = ["contributor", "agreement_id"] def __str__(self): - return f"Contributor {self.contributor} signed - {self.agreement_id[:7]} at {self.signed_at}" \ No newline at end of file + cont = f"Contributor {self.contributor} signed" + repo = f"{self.agreement_id[:7]} at {self.signed_at}" + return f"{cont} {repo}" \ No newline at end of file diff --git a/api/models/contributor.py b/api/models/contributor.py index 5d7f119..b01a6f8 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -23,6 +23,10 @@ class Contributor(models.Model): html_url = models.TextField() avatar_url = models.TextField() + class Meta(TypedModelMeta): + verbose_name = _("contributor") + verbose_name_plural = _("contributors") + def __str__(self): return self.name \ No newline at end of file diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index e69de29..95181c6 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -0,0 +1,21 @@ +""" +© 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]): + fixtures = ["contributors"] + + def setUp(self): + self.contributor = Contributor.objects.get(pk=111111) + + def test_str(self): + """Parsing a contributor object instance to string returns its name.""" + assert str(self.contributor) == self.contributor.name + + \ No newline at end of file From 46c522f1f5d0b8545732de7f82e09b1b48191afc Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:18:11 +0000 Subject: [PATCH 07/42] Migrate models --- ...reementsignature_contributor_repository.py | 53 +++++++++++++++++++ api/migrations/0002_contributor.py | 28 ---------- 2 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 api/migrations/0002_agreementsignature_contributor_repository.py delete mode 100644 api/migrations/0002_contributor.py diff --git a/api/migrations/0002_agreementsignature_contributor_repository.py b/api/migrations/0002_agreementsignature_contributor_repository.py new file mode 100644 index 0000000..e7ad68f --- /dev/null +++ b/api/migrations/0002_agreementsignature_contributor_repository.py @@ -0,0 +1,53 @@ +# Generated by Django 3.2.25 on 2024-07-09 10:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Contributor', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('email', models.TextField()), + ('name', models.TextField()), + ('location', models.TextField()), + ('html_url', models.TextField()), + ('avatar_url', models.TextField()), + ], + options={ + 'verbose_name': 'contributor', + 'verbose_name_plural': 'contributors', + }, + ), + migrations.CreateModel( + name='Repository', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('name', models.TextField(choices=[('portal', 'portal'), ('rr', 'rr')])), + ('points', models.IntegerField(default=0)), + ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), + ], + options={ + 'unique_together': {('contributor', 'name')}, + }, + ), + migrations.CreateModel( + name='AgreementSignature', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('agreement_id', models.CharField(max_length=40)), + ('signed_at', models.DateTimeField()), + ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), + ], + options={ + 'unique_together': {('contributor', 'agreement_id')}, + }, + ), + ] diff --git a/api/migrations/0002_contributor.py b/api/migrations/0002_contributor.py deleted file mode 100644 index bfc61bb..0000000 --- a/api/migrations/0002_contributor.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-09 09:52 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Contributor', - fields=[ - ('id', models.IntegerField(primary_key=True, serialize=False)), - ('email', models.TextField()), - ('name', models.TextField()), - ('location', models.TextField()), - ('html_url', models.TextField()), - ('avatar_url', models.TextField()), - ], - options={ - 'verbose_name': 'contributor', - 'verbose_name_plural': 'contributors', - }, - ), - ] From 8878e9f3d4e2d71191f7c5ee3809a37a04090d5e Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:18:43 +0000 Subject: [PATCH 08/42] fixture data for testing --- .../{agreement_signature.json => agreement_signatures.json} | 0 api/fixtures/{repository.json => repositories.json} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename api/fixtures/{agreement_signature.json => agreement_signatures.json} (100%) rename api/fixtures/{repository.json => repositories.json} (100%) diff --git a/api/fixtures/agreement_signature.json b/api/fixtures/agreement_signatures.json similarity index 100% rename from api/fixtures/agreement_signature.json rename to api/fixtures/agreement_signatures.json diff --git a/api/fixtures/repository.json b/api/fixtures/repositories.json similarity index 100% rename from api/fixtures/repository.json rename to api/fixtures/repositories.json From a7681a49d3e3c00f821ca9773c8db0781a7038c7 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:19:00 +0000 Subject: [PATCH 09/42] api models and tests files --- api/models/__init__.py | 5 +++++ api/models/agreement_signature.py | 9 +++++---- api/models/agreement_signature_test.py | 23 +++++++++++++++++++++++ api/models/contributor.py | 2 +- api/models/contributor_test.py | 5 +++-- api/models/repository.py | 9 ++++++--- api/models/repository_test.py | 23 +++++++++++++++++++++++ 7 files changed, 66 insertions(+), 10 deletions(-) diff --git a/api/models/__init__.py b/api/models/__init__.py index 1bdf013..b8905af 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -4,4 +4,9 @@ """ from .fruit import Fruit + from .contributor import Contributor + +from .repository import Repository + +from .agreement_signature import AgreementSignature diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 9bf6c22..fdeeb93 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -1,22 +1,19 @@ """ © Ocado Group Created on 08/07/2024 at 10:48:44(+01:00). - """ import typing as t from django.db import models +from .contributor import Contributor from django.utils.translation import gettext_lazy as _ if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta - - from .contributor import Contributor else: TypedModelMeta = object - class AgreementSignature(models.Model): """ Signature of a contributor signing the agreement """ contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) @@ -26,6 +23,10 @@ class AgreementSignature(models.Model): class Meta: unique_together = ["contributor", "agreement_id"] + class Meta(TypedModelMeta): + verbose_name = _("agreement_signature") + verbose_name_plural = _("agreement_signatures") + def __str__(self): cont = f"Contributor {self.contributor} signed" repo = f"{self.agreement_id[:7]} at {self.signed_at}" diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index e69de29..ca264f9 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -0,0 +1,23 @@ +""" +© Ocado Group +Created on 09/07/2024 at 11:43:42(+01:00). +""" + +from codeforlife.tests import ModelTestCase +from .contributor import Contributor +from .repository import Repository +from .agreement_signature import AgreementSignature + +class TestAgreementSignature(ModelTestCase[AgreementSignature]): + fixtures = ["agreement_signatures"] + + def setUp(self): + pass + + def test_str(self): + """Parsing a contributor object instance to string returns its name.""" + pass + + def test_fields(self): + """ Check if """ + pass \ No newline at end of file diff --git a/api/models/contributor.py b/api/models/contributor.py index b01a6f8..73e1a9f 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -1,7 +1,6 @@ """ © Ocado Group Created on 05/07/2024 at 16:18:48(+01:00). - """ import typing as t @@ -14,6 +13,7 @@ else: TypedModelMeta = object + class Contributor(models.Model): """ A contributor that contributes to a repo""" id = models.IntegerField(primary_key=True) diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 95181c6..7ca08d8 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -1,7 +1,6 @@ """ © Ocado Group Created on 09/07/2024 at 09:39:50(+01:00). - """ from codeforlife.tests import ModelTestCase @@ -18,4 +17,6 @@ def test_str(self): """Parsing a contributor object instance to string returns its name.""" assert str(self.contributor) == self.contributor.name - \ No newline at end of file + def test_fields(self): + """ Check if """ + assert self.contributor.email == "contributor1@gmail.com" diff --git a/api/models/repository.py b/api/models/repository.py index d112df6..5027e6c 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -1,21 +1,20 @@ """ © Ocado Group Created on 05/07/2024 at 16:39:14(+01:00). - """ import typing as t from django.db import models +from .contributor import Contributor from django.utils.translation import gettext_lazy as _ if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta - - from .contributor import Contributor else: TypedModelMeta = object + class Repository(models.Model): """ A repository to contribute to""" id = models.IntegerField(primary_key=True) @@ -26,6 +25,10 @@ class Repository(models.Model): ] name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) + + class Meta(TypedModelMeta): + verbose_name = _("repository") + verbose_name_plural = _("repositories") class Meta: unique_together = ["contributor", "name"] diff --git a/api/models/repository_test.py b/api/models/repository_test.py index e69de29..005bf15 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -0,0 +1,23 @@ +""" +© Ocado Group +Created on 09/07/2024 at 11:43:31(+01:00). +""" + +from codeforlife.tests import ModelTestCase +from .contributor import Contributor +from .repository import Repository +from .agreement_signature import AgreementSignature + +class TestRepository(ModelTestCase[Repository]): + fixtures = ["repositories"] + + def setUp(self): + pass + + def test_str(self): + """Parsing a contributor object instance to string returns its name.""" + pass + + def test_fields(self): + """ Check if """ + pass \ No newline at end of file From 47306f602a3e63188009c4a25e44f13448a35d07 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:25:09 +0000 Subject: [PATCH 10/42] fix import statements --- api/models/__init__.py | 7 ++----- api/models/agreement_signature.py | 3 ++- api/models/agreement_signature_test.py | 4 +++- api/models/contributor_test.py | 1 + api/models/repository.py | 3 ++- api/models/repository_test.py | 4 +++- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/models/__init__.py b/api/models/__init__.py index b8905af..4fcfd3f 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -3,10 +3,7 @@ Created on 02/07/2024 at 11:57:31(+01:00). """ -from .fruit import Fruit - +from .agreement_signature import AgreementSignature from .contributor import Contributor - +from .fruit import Fruit from .repository import Repository - -from .agreement_signature import AgreementSignature diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index fdeeb93..82d40aa 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -6,9 +6,10 @@ import typing as t from django.db import models -from .contributor import Contributor from django.utils.translation import gettext_lazy as _ +from .contributor import Contributor + if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta else: diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index ca264f9..c3bc322 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -4,9 +4,11 @@ """ from codeforlife.tests import ModelTestCase + +from .agreement_signature import AgreementSignature from .contributor import Contributor from .repository import Repository -from .agreement_signature import AgreementSignature + class TestAgreementSignature(ModelTestCase[AgreementSignature]): fixtures = ["agreement_signatures"] diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 7ca08d8..0c3aee5 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -7,6 +7,7 @@ from .contributor import Contributor + class TestContributor(ModelTestCase[Contributor]): fixtures = ["contributors"] diff --git a/api/models/repository.py b/api/models/repository.py index 5027e6c..8dc8681 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -6,9 +6,10 @@ import typing as t from django.db import models -from .contributor import Contributor from django.utils.translation import gettext_lazy as _ +from .contributor import Contributor + if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta else: diff --git a/api/models/repository_test.py b/api/models/repository_test.py index 005bf15..4c6a056 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -4,9 +4,11 @@ """ from codeforlife.tests import ModelTestCase + +from .agreement_signature import AgreementSignature from .contributor import Contributor from .repository import Repository -from .agreement_signature import AgreementSignature + class TestRepository(ModelTestCase[Repository]): fixtures = ["repositories"] From 0af10047a3233b8d065b349f17a31b45c12cdce7 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:32:58 +0000 Subject: [PATCH 11/42] fix code format --- api/models/agreement_signature.py | 12 +++++++----- api/models/agreement_signature_test.py | 8 ++++---- api/models/contributor.py | 4 ++-- api/models/contributor_test.py | 6 +++--- api/models/repository.py | 12 +++++------- api/models/repository_test.py | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 82d40aa..1be25fb 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -15,20 +15,22 @@ else: TypedModelMeta = object + class AgreementSignature(models.Model): - """ Signature of a contributor signing the agreement """ + """Signature of a contributor signing the agreement""" + contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - + class Meta: unique_together = ["contributor", "agreement_id"] - + class Meta(TypedModelMeta): verbose_name = _("agreement_signature") verbose_name_plural = _("agreement_signatures") - + def __str__(self): cont = f"Contributor {self.contributor} signed" repo = f"{self.agreement_id[:7]} at {self.signed_at}" - return f"{cont} {repo}" \ No newline at end of file + return f"{cont} {repo}" diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index c3bc322..3c967ae 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -15,11 +15,11 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]): def setUp(self): pass - + def test_str(self): """Parsing a contributor object instance to string returns its name.""" pass - + def test_fields(self): - """ Check if """ - pass \ No newline at end of file + """Check if""" + pass diff --git a/api/models/contributor.py b/api/models/contributor.py index 73e1a9f..409c2d3 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -15,7 +15,8 @@ class Contributor(models.Model): - """ A contributor that contributes to a repo""" + """A contributor that contributes to a repo""" + id = models.IntegerField(primary_key=True) email = models.TextField() name = models.TextField() @@ -29,4 +30,3 @@ class Meta(TypedModelMeta): def __str__(self): return self.name - \ No newline at end of file diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 0c3aee5..f831528 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -13,11 +13,11 @@ class TestContributor(ModelTestCase[Contributor]): def setUp(self): self.contributor = Contributor.objects.get(pk=111111) - + def test_str(self): """Parsing a contributor object instance to string returns its name.""" assert str(self.contributor) == self.contributor.name - + def test_fields(self): - """ Check if """ + """Check if""" assert self.contributor.email == "contributor1@gmail.com" diff --git a/api/models/repository.py b/api/models/repository.py index 8dc8681..d2c61e9 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -17,22 +17,20 @@ class Repository(models.Model): - """ A repository to contribute to""" + """A repository to contribute to""" + id = models.IntegerField(primary_key=True) contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - NAME_CHOICES = [ - ("portal", "portal"), - ("rr", "rr") - ] + NAME_CHOICES = [("portal", "portal"), ("rr", "rr")] name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) class Meta(TypedModelMeta): verbose_name = _("repository") verbose_name_plural = _("repositories") - + class Meta: unique_together = ["contributor", "name"] def __str__(self): - return self.name \ No newline at end of file + return self.name diff --git a/api/models/repository_test.py b/api/models/repository_test.py index 4c6a056..a5a42b4 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -15,11 +15,11 @@ class TestRepository(ModelTestCase[Repository]): def setUp(self): pass - + def test_str(self): """Parsing a contributor object instance to string returns its name.""" pass - + def test_fields(self): - """ Check if """ - pass \ No newline at end of file + """Check if""" + pass From 7e69d686e4652d60834fc08f8141ac2c360c665f Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:37:19 +0000 Subject: [PATCH 12/42] Fix static types --- api/models/agreement_signature.py | 4 +--- api/models/repository.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 1be25fb..e9ca1ca 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -23,10 +23,8 @@ class AgreementSignature(models.Model): agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - class Meta: - unique_together = ["contributor", "agreement_id"] - class Meta(TypedModelMeta): + unique_together = ["contributor", "agreement_id"] verbose_name = _("agreement_signature") verbose_name_plural = _("agreement_signatures") diff --git a/api/models/repository.py b/api/models/repository.py index d2c61e9..46238a2 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -26,11 +26,9 @@ class Repository(models.Model): points = models.IntegerField(default=0) class Meta(TypedModelMeta): + unique_together = ["contributor", "name"] verbose_name = _("repository") verbose_name_plural = _("repositories") - class Meta: - unique_together = ["contributor", "name"] - def __str__(self): return self.name From ef5f20c5af6081dbef0a824a5cf306b5461df024 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:51:19 +0000 Subject: [PATCH 13/42] fix linting test file format --- api/migrations/0003_auto_20240709_1347.py | 21 +++++++++++++++++++++ api/models/agreement_signature_test.py | 15 ++++++++------- api/models/contributor_test.py | 1 + api/models/repository_test.py | 15 ++++++++------- 4 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 api/migrations/0003_auto_20240709_1347.py diff --git a/api/migrations/0003_auto_20240709_1347.py b/api/migrations/0003_auto_20240709_1347.py new file mode 100644 index 0000000..e7c4eae --- /dev/null +++ b/api/migrations/0003_auto_20240709_1347.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.25 on 2024-07-09 12:47 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_agreementsignature_contributor_repository'), + ] + + operations = [ + migrations.AlterModelOptions( + name='agreementsignature', + options={'verbose_name': 'agreement_signature', 'verbose_name_plural': 'agreement_signatures'}, + ), + migrations.AlterModelOptions( + name='repository', + options={'verbose_name': 'repository', 'verbose_name_plural': 'repositories'}, + ), + ] diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 3c967ae..84d4c27 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -11,15 +11,16 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]): + """ Test the AgreementSignature Model""" fixtures = ["agreement_signatures"] def setUp(self): - pass + self.agreement_signature = Contributor.objects.get(pk=1) - def test_str(self): - """Parsing a contributor object instance to string returns its name.""" - pass + # def test_str(self): + # """Parsing a contributor object instance to string returns its name.""" + # pass - def test_fields(self): - """Check if""" - pass + # def test_fields(self): + # """Check if""" + # pass diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index f831528..902b961 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -9,6 +9,7 @@ class TestContributor(ModelTestCase[Contributor]): + """ Test the Contributor Model """ fixtures = ["contributors"] def setUp(self): diff --git a/api/models/repository_test.py b/api/models/repository_test.py index a5a42b4..b7aa9eb 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -11,15 +11,16 @@ class TestRepository(ModelTestCase[Repository]): + """ Test the Repository Model""" fixtures = ["repositories"] def setUp(self): - pass + self.repository = Repository.objects.get(pk=111) - def test_str(self): - """Parsing a contributor object instance to string returns its name.""" - pass + # def test_str(self): + # """Parsing a contributor object instance to string returns its name.""" + # assert str(self.repository) == self.repository.name - def test_fields(self): - """Check if""" - pass + # def test_fields(self): + # """Check if""" + # pass From 72c56540c218b8d02094d7dd55e7e813871db198 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:53:46 +0000 Subject: [PATCH 14/42] import fix --- api/models/agreement_signature_test.py | 3 ++- api/models/contributor_test.py | 3 ++- api/models/repository_test.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 84d4c27..324a7bb 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -11,7 +11,8 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]): - """ Test the AgreementSignature Model""" + """Test the AgreementSignature Model""" + fixtures = ["agreement_signatures"] def setUp(self): diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 902b961..4808da6 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -9,7 +9,8 @@ class TestContributor(ModelTestCase[Contributor]): - """ Test the Contributor Model """ + """Test the Contributor Model""" + fixtures = ["contributors"] def setUp(self): diff --git a/api/models/repository_test.py b/api/models/repository_test.py index b7aa9eb..ab3361b 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -11,7 +11,8 @@ class TestRepository(ModelTestCase[Repository]): - """ Test the Repository Model""" + """Test the Repository Model""" + fixtures = ["repositories"] def setUp(self): From 44dfbb6691ac97d49107245512d9541230115e21 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 12:57:27 +0000 Subject: [PATCH 15/42] Check static code --- api/models/agreement_signature_test.py | 4 ++-- api/models/repository_test.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 324a7bb..5998789 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -7,7 +7,7 @@ from .agreement_signature import AgreementSignature from .contributor import Contributor -from .repository import Repository +# from .repository import Repository class TestAgreementSignature(ModelTestCase[AgreementSignature]): @@ -19,7 +19,7 @@ def setUp(self): self.agreement_signature = Contributor.objects.get(pk=1) # def test_str(self): - # """Parsing a contributor object instance to string returns its name.""" + # """Parsing a contributor object instance to returns its name.""" # pass # def test_fields(self): diff --git a/api/models/repository_test.py b/api/models/repository_test.py index ab3361b..88da585 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -5,8 +5,8 @@ from codeforlife.tests import ModelTestCase -from .agreement_signature import AgreementSignature -from .contributor import Contributor +# from .agreement_signature import AgreementSignature +# from .contributor import Contributor from .repository import Repository @@ -19,7 +19,7 @@ def setUp(self): self.repository = Repository.objects.get(pk=111) # def test_str(self): - # """Parsing a contributor object instance to string returns its name.""" + # """Parsing a contributor object instance to returns its name.""" # assert str(self.repository) == self.repository.name # def test_fields(self): From cc05cc2354b2c5c94ccb3ec0069bdefdee422712 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 13:04:40 +0000 Subject: [PATCH 16/42] import sort --- api/models/agreement_signature_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 5998789..4e65cbb 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -7,6 +7,7 @@ from .agreement_signature import AgreementSignature from .contributor import Contributor + # from .repository import Repository From 77e5a8065d97a04b963c9971b70d1b573665f155 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 14:41:03 +0000 Subject: [PATCH 17/42] update DateTime Field --- api/fixtures/agreement_signatures.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/fixtures/agreement_signatures.json b/api/fixtures/agreement_signatures.json index cf861a6..a8b36ed 100644 --- a/api/fixtures/agreement_signatures.json +++ b/api/fixtures/agreement_signatures.json @@ -5,7 +5,7 @@ "fields": { "contributor": 111111, "agreement_id": "g3d3d3s8dgd3vc37", - "signed_at": "2023-01-01" + "signed_at": "2024-01-02T12:00:00Z" } }, { @@ -14,7 +14,7 @@ "fields": { "contributor": 222222, "agreement_id": "g3d3d3s8dgd3vc37", - "signed_at": "2023-01-01" + "signed_at": "2024-01-02T12:00:00Z" } }, { @@ -23,7 +23,7 @@ "fields": { "contributor": 333333, "agreement_id": "g3d3d3s8dgd3vc37", - "signed_at": "2023-01-01" + "signed_at": "2024-01-02T12:00:00Z" } } ] From 9a8f9767a8b914db5430b2686a8d4530ba860f7b Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 14:41:21 +0000 Subject: [PATCH 18/42] Tests for models --- api/models/__init__.py | 4 ++-- api/models/agreement_signature.py | 9 ++++++--- api/models/agreement_signature_test.py | 16 ++++++++++------ api/models/contributor_test.py | 16 +++++++++++----- api/models/repository.py | 6 +++--- api/models/repository_test.py | 12 ++++-------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/api/models/__init__.py b/api/models/__init__.py index 4fcfd3f..9d79b48 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -2,8 +2,8 @@ © Ocado Group Created on 02/07/2024 at 11:57:31(+01:00). """ - +from .repository import Repository from .agreement_signature import AgreementSignature from .contributor import Contributor from .fruit import Fruit -from .repository import Repository + diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index e9ca1ca..9e81a98 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -23,12 +23,15 @@ class AgreementSignature(models.Model): agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - class Meta(TypedModelMeta): + class Meta: unique_together = ["contributor", "agreement_id"] - verbose_name = _("agreement_signature") - verbose_name_plural = _("agreement_signatures") + verbose_name = "agreement_signature" + verbose_name_plural = "agreement_signatures" def __str__(self): cont = f"Contributor {self.contributor} signed" repo = f"{self.agreement_id[:7]} at {self.signed_at}" return f"{cont} {repo}" + + # def __str__(self): + # return self.agreement_id diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 4e65cbb..9c2b6e8 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -14,15 +14,19 @@ class TestAgreementSignature(ModelTestCase[AgreementSignature]): """Test the AgreementSignature Model""" - fixtures = ["agreement_signatures"] + fixtures = ["agreement_signatures", "contributors"] def setUp(self): - self.agreement_signature = Contributor.objects.get(pk=1) + self.agreement_signature = AgreementSignature.objects.get(pk=1) # def test_str(self): # """Parsing a contributor object instance to returns its name.""" - # pass + # commit_id = self.agreement_signature.agreement_id[:7] + # # time = self.agreement_signature.signed_at + # # contributor = self.agreement_signature.contributor.name + # # cont = f"Contributor {contributor} signed" + # # repo = f"{commit_id} at {time}" + # assert commit_id in str(self.agreement_signature) - # def test_fields(self): - # """Check if""" - # pass + # def test_str(self): + # assert str(self.agreement_signature) == self.agreement_signature.agreement_id diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 4808da6..37b9c78 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -14,12 +14,18 @@ class TestContributor(ModelTestCase[Contributor]): fixtures = ["contributors"] def setUp(self): - self.contributor = Contributor.objects.get(pk=111111) + self.contributor1 = Contributor.objects.get(pk=111111) + self.contributor2 = Contributor.objects.get(pk=222222) + self.contributor3 = Contributor.objects.get(pk=333333) def test_str(self): - """Parsing a contributor object instance to string returns its name.""" - assert str(self.contributor) == self.contributor.name + """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 def test_fields(self): - """Check if""" - assert self.contributor.email == "contributor1@gmail.com" + """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" diff --git a/api/models/repository.py b/api/models/repository.py index 46238a2..151215b 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -25,10 +25,10 @@ class Repository(models.Model): name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) - class Meta(TypedModelMeta): + class Meta: unique_together = ["contributor", "name"] - verbose_name = _("repository") - verbose_name_plural = _("repositories") + verbose_name = "repository" + verbose_name_plural = "repositories" def __str__(self): return self.name diff --git a/api/models/repository_test.py b/api/models/repository_test.py index 88da585..385bc81 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -13,15 +13,11 @@ class TestRepository(ModelTestCase[Repository]): """Test the Repository Model""" - fixtures = ["repositories"] + fixtures = ["contributors", "repositories"] def setUp(self): self.repository = Repository.objects.get(pk=111) - # def test_str(self): - # """Parsing a contributor object instance to returns its name.""" - # assert str(self.repository) == self.repository.name - - # def test_fields(self): - # """Check if""" - # pass + def test_str(self): + """Parsing a contributor object instance to returns its name.""" + assert str(self.repository) == self.repository.name From 269ace90afd46189e911c352e1b180dbee670e41 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 15:19:26 +0000 Subject: [PATCH 19/42] Repository testing --- api/models/__init__.py | 3 +- api/models/agreement_signature_test.py | 6 ++-- api/models/repository_test.py | 39 +++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/api/models/__init__.py b/api/models/__init__.py index 9d79b48..d1d2cdc 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -2,8 +2,7 @@ © Ocado Group Created on 02/07/2024 at 11:57:31(+01:00). """ -from .repository import Repository from .agreement_signature import AgreementSignature from .contributor import Contributor from .fruit import Fruit - +from .repository import Repository diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 9c2b6e8..43fa3c9 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -6,7 +6,8 @@ from codeforlife.tests import ModelTestCase from .agreement_signature import AgreementSignature -from .contributor import Contributor + +# from .contributor import Contributor # from .repository import Repository @@ -29,4 +30,5 @@ def setUp(self): # assert commit_id in str(self.agreement_signature) # def test_str(self): - # assert str(self.agreement_signature) == self.agreement_signature.agreement_id + # assert str(self.agreement_signature) == + # self.agreement_signature.agreement_id diff --git a/api/models/repository_test.py b/api/models/repository_test.py index 385bc81..f4c43d6 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -4,9 +4,10 @@ """ from codeforlife.tests import ModelTestCase +from django.db import IntegrityError # from .agreement_signature import AgreementSignature -# from .contributor import Contributor +from .contributor import Contributor from .repository import Repository @@ -17,7 +18,43 @@ class TestRepository(ModelTestCase[Repository]): def setUp(self): self.repository = Repository.objects.get(pk=111) + self.contributor1 = Contributor.objects.get(pk=111111) + self.contributor2 = Contributor.objects.get(pk=222222) def test_str(self): """Parsing a contributor object instance to returns its name.""" assert str(self.repository) == self.repository.name + + 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( + id=999, contributor=new_contributor, name="portal" + ) + assert repository.points == 0 + + def test_unique_fields(self): + """Test the unique fields functionality""" + new_contributor = Contributor.objects.create( + id=999999, + email="newcontributor@gmail.com", + 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" + ) + + with self.assertRaises(IntegrityError): + Repository.objects.create( + id=999, contributor=self.contributor1, name="rr" + ) From 6249929761c1a03803ad3c3e4b3b776a7ae478ca Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:18:15 +0000 Subject: [PATCH 20/42] fix class name --- api/fixtures/agreement_signatures.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/fixtures/agreement_signatures.json b/api/fixtures/agreement_signatures.json index a8b36ed..cec6266 100644 --- a/api/fixtures/agreement_signatures.json +++ b/api/fixtures/agreement_signatures.json @@ -1,6 +1,6 @@ [ { - "model": "api.agreement_signature", + "model": "api.agreementsignature", "pk": 1, "fields": { "contributor": 111111, @@ -9,7 +9,7 @@ } }, { - "model": "api.agreement_signature", + "model": "api.agreementsignature", "pk": 2, "fields": { "contributor": 222222, @@ -18,7 +18,7 @@ } }, { - "model": "api.agreement_signature", + "model": "api.agreementsignature", "pk": 3, "fields": { "contributor": 333333, From 20a953733c583ce28dc4864b48938e58b6aa90dd Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:18:30 +0000 Subject: [PATCH 21/42] tests for models --- api/models/__init__.py | 1 + api/models/agreement_signature.py | 8 ---- api/models/agreement_signature_test.py | 54 +++++++++++++++++--------- api/models/repository.py | 8 ---- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/api/models/__init__.py b/api/models/__init__.py index d1d2cdc..4fcfd3f 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -2,6 +2,7 @@ © Ocado Group Created on 02/07/2024 at 11:57:31(+01:00). """ + from .agreement_signature import AgreementSignature from .contributor import Contributor from .fruit import Fruit diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 9e81a98..9fb9e6b 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -3,18 +3,10 @@ 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 -else: - TypedModelMeta = object - class AgreementSignature(models.Model): """Signature of a contributor signing the agreement""" diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index 43fa3c9..b634564 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -4,31 +4,49 @@ """ from codeforlife.tests import ModelTestCase +from django.db import IntegrityError from .agreement_signature import AgreementSignature - -# from .contributor import Contributor - -# from .repository import Repository +from .contributor import Contributor class TestAgreementSignature(ModelTestCase[AgreementSignature]): """Test the AgreementSignature Model""" - fixtures = ["agreement_signatures", "contributors"] + fixtures = ["contributors", "agreement_signatures"] def setUp(self): self.agreement_signature = AgreementSignature.objects.get(pk=1) - - # def test_str(self): - # """Parsing a contributor object instance to returns its name.""" - # commit_id = self.agreement_signature.agreement_id[:7] - # # time = self.agreement_signature.signed_at - # # contributor = self.agreement_signature.contributor.name - # # cont = f"Contributor {contributor} signed" - # # repo = f"{commit_id} at {time}" - # assert commit_id in str(self.agreement_signature) - - # def test_str(self): - # assert str(self.agreement_signature) == - # self.agreement_signature.agreement_id + self.contributor1 = Contributor.objects.get(pk=111111) + + def test_str(self): + """Parsing a contributor object instance to returns its name.""" + commit_id = self.agreement_signature.agreement_id[:7] + time = self.agreement_signature.signed_at + cont = f"Contributor {self.agreement_signature.contributor} 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="g3d3d3s8dg2342c37", + signed_at="2024-01-02T12:00:00Z", + ) + + with self.assertRaises(IntegrityError): + AgreementSignature.objects.create( + contributor=self.contributor1, + agreement_id="g3d3d3s8dgd3vc37", + signed_at="2024-01-02T12:00:00Z", + ) diff --git a/api/models/repository.py b/api/models/repository.py index 151215b..dc481ac 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -3,18 +3,10 @@ Created on 05/07/2024 at 16:39:14(+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 -else: - TypedModelMeta = object - class Repository(models.Model): """A repository to contribute to""" From 9f55c76108c5e9257a17844f96c5261760736164 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:26:52 +0000 Subject: [PATCH 22/42] correct formatting and comments --- api/models/agreement_signature.py | 3 --- api/models/contributor.py | 14 +++----------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 9fb9e6b..55e3527 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -24,6 +24,3 @@ def __str__(self): cont = f"Contributor {self.contributor} signed" repo = f"{self.agreement_id[:7]} at {self.signed_at}" return f"{cont} {repo}" - - # def __str__(self): - # return self.agreement_id diff --git a/api/models/contributor.py b/api/models/contributor.py index 409c2d3..58ee673 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -3,15 +3,7 @@ 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 -else: - TypedModelMeta = object class Contributor(models.Model): @@ -24,9 +16,9 @@ class Contributor(models.Model): html_url = models.TextField() avatar_url = models.TextField() - class Meta(TypedModelMeta): - verbose_name = _("contributor") - verbose_name_plural = _("contributors") + class Meta: + verbose_name = "contributor" + verbose_name_plural = "contributors" def __str__(self): return self.name From def8ff7a518e6113650a675a842b49bb902297c3 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:33:36 +0000 Subject: [PATCH 23/42] Change meta classes --- api/models/agreement_signature.py | 16 ++++++++++++---- api/models/contributor.py | 14 +++++++++++--- api/models/fruit.py | 2 +- api/models/repository.py | 16 ++++++++++++---- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 55e3527..f471144 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -3,9 +3,17 @@ Created on 08/07/2024 at 10:48:44(+01:00). """ -from django.db import models +import typing as t +from django.db import models from .contributor import Contributor +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 AgreementSignature(models.Model): @@ -15,10 +23,10 @@ class AgreementSignature(models.Model): agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - class Meta: + class Meta(TypedModelMeta): unique_together = ["contributor", "agreement_id"] - verbose_name = "agreement_signature" - verbose_name_plural = "agreement_signatures" + verbose_name = _("agreement_signature") + verbose_name_plural = _("agreement_signatures") def __str__(self): cont = f"Contributor {self.contributor} signed" diff --git a/api/models/contributor.py b/api/models/contributor.py index 58ee673..9fe9ab3 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -3,7 +3,15 @@ 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): @@ -16,9 +24,9 @@ class Contributor(models.Model): html_url = models.TextField() avatar_url = models.TextField() - class Meta: - verbose_name = "contributor" - verbose_name_plural = "contributors" + class Meta(TypedModelMeta): + verbose_name = _("contributor") + verbose_name_plural = _("contributors") def __str__(self): return self.name diff --git a/api/models/fruit.py b/api/models/fruit.py index 0ab3db2..6957195 100644 --- a/api/models/fruit.py +++ b/api/models/fruit.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ if t.TYPE_CHECKING: - from django_stubs_ext.db.models import TypedModelMeta + from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover else: TypedModelMeta = object diff --git a/api/models/repository.py b/api/models/repository.py index dc481ac..8c93f6e 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -3,9 +3,17 @@ Created on 05/07/2024 at 16:39:14(+01:00). """ -from django.db import models +import typing as t +from django.db import models from .contributor import Contributor +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 Repository(models.Model): @@ -17,10 +25,10 @@ class Repository(models.Model): name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) - class Meta: + class Meta(TypedModelMeta): unique_together = ["contributor", "name"] - verbose_name = "repository" - verbose_name_plural = "repositories" + verbose_name = _("repository") + verbose_name_plural = _("repositories") def __str__(self): return self.name From 0a22567a3e3c54a8442c5d5c74034a7304119ef9 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:34:46 +0000 Subject: [PATCH 24/42] Fix code format and imports --- api/models/agreement_signature.py | 6 +++--- api/models/contributor.py | 2 +- api/models/fruit.py | 2 +- api/models/repository.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index f471144..445401c 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -6,16 +6,16 @@ import typing as t from django.db import models -from .contributor import Contributor 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 + 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""" diff --git a/api/models/contributor.py b/api/models/contributor.py index 9fe9ab3..e3e82e2 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ if t.TYPE_CHECKING: - from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover + from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover else: TypedModelMeta = object diff --git a/api/models/fruit.py b/api/models/fruit.py index 6957195..0292f20 100644 --- a/api/models/fruit.py +++ b/api/models/fruit.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ if t.TYPE_CHECKING: - from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover + from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover else: TypedModelMeta = object diff --git a/api/models/repository.py b/api/models/repository.py index 8c93f6e..334d1c3 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -6,16 +6,16 @@ import typing as t from django.db import models -from .contributor import Contributor 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 + from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover else: TypedModelMeta = object - class Repository(models.Model): """A repository to contribute to""" From b5ec844ea2ed95e4d5e813f0f48cd8660adb6b7a Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:46:24 +0000 Subject: [PATCH 25/42] Delete all fruit files --- api/fixtures/fruits.json | 29 ----------------------------- api/models/__init__.py | 1 - api/models/fruit.py | 32 -------------------------------- api/models/fruit_test.py | 28 ---------------------------- api/serializers/__init__.py | 2 -- api/serializers/fruit.py | 27 --------------------------- api/serializers/fruit_test.py | 28 ---------------------------- api/urls.py | 12 ++++++------ api/views/__init__.py | 2 -- api/views/fruit.py | 19 ------------------- api/views/fruit_test.py | 34 ---------------------------------- 11 files changed, 6 insertions(+), 208 deletions(-) delete mode 100644 api/fixtures/fruits.json delete mode 100644 api/models/fruit.py delete mode 100644 api/models/fruit_test.py delete mode 100644 api/serializers/fruit.py delete mode 100644 api/serializers/fruit_test.py delete mode 100644 api/views/fruit.py delete mode 100644 api/views/fruit_test.py diff --git a/api/fixtures/fruits.json b/api/fixtures/fruits.json deleted file mode 100644 index 01d1dd4..0000000 --- a/api/fixtures/fruits.json +++ /dev/null @@ -1,29 +0,0 @@ -[ - { - "model": "api.fruit", - "pk": 1, - "fields": { - "name": "apple", - "is_citrus": false, - "expires_on": "2023-01-01" - } - }, - { - "model": "api.fruit", - "pk": 2, - "fields": { - "name": "banana", - "is_citrus": false, - "expires_on": "2023-01-02" - } - }, - { - "model": "api.fruit", - "pk": 3, - "fields": { - "name": "orange", - "is_citrus": true, - "expires_on": "2023-01-03" - } - } -] diff --git a/api/models/__init__.py b/api/models/__init__.py index 4fcfd3f..55bea85 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -5,5 +5,4 @@ from .agreement_signature import AgreementSignature from .contributor import Contributor -from .fruit import Fruit from .repository import Repository diff --git a/api/models/fruit.py b/api/models/fruit.py deleted file mode 100644 index 0292f20..0000000 --- a/api/models/fruit.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 15:12:59(+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 Fruit(models.Model): - """A piece of fruit.""" - - name = models.CharField(_("name"), max_length=50) - is_citrus = models.BooleanField(_("is citrus")) - expires_on = models.DateField(_("expires on")) - - class Meta(TypedModelMeta): - verbose_name = _("fruit") - verbose_name_plural = _("fruits") - - def __str__(self): - return self.name - - def __lt__(self, other): - return isinstance(other, Fruit) and self.expires_on < other.expires_on diff --git a/api/models/fruit_test.py b/api/models/fruit_test.py deleted file mode 100644 index b2229be..0000000 --- a/api/models/fruit_test.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 16:17:04(+01:00). -""" - -from codeforlife.tests import ModelTestCase - -from .fruit import Fruit - - -# pylint: disable-next=missing-class-docstring -class TestFruit(ModelTestCase[Fruit]): - fixtures = ["fruits"] - - def setUp(self): - self.apple = Fruit.objects.get(name="apple") - self.banana = Fruit.objects.get(name="banana") - - def test_str(self): - """Parsing a fruit object instance to string returns its name.""" - assert str(self.apple) == self.apple.name - - def test_lt(self): - """ - Comparing if one fruit is less than another compares their expiry dates. - """ - assert self.apple < self.banana - assert not self.banana < self.apple diff --git a/api/serializers/__init__.py b/api/serializers/__init__.py index 49eb27f..7e05fbc 100644 --- a/api/serializers/__init__.py +++ b/api/serializers/__init__.py @@ -2,5 +2,3 @@ © Ocado Group Created on 02/07/2024 at 12:00:12(+01:00). """ - -from .fruit import FruitSerializer diff --git a/api/serializers/fruit.py b/api/serializers/fruit.py deleted file mode 100644 index 906d6ea..0000000 --- a/api/serializers/fruit.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 15:21:47(+01:00). -""" - -from datetime import timedelta - -from codeforlife.serializers import ModelSerializer -from codeforlife.user.models import User -from django.utils import timezone - -from ..models import Fruit - - -# pylint: disable-next=missing-class-docstring -class FruitSerializer(ModelSerializer[User, Fruit]): - class Meta: - model = Fruit - fields = ["id", "name", "is_citrus", "expires_on"] - extra_kwargs = { - "id": {"read_only": True}, - "expires_on": {"read_only": True}, - } - - def create(self, validated_data): - validated_data["expires_on"] = timezone.now().date() + timedelta(days=3) - return super().create(validated_data) diff --git a/api/serializers/fruit_test.py b/api/serializers/fruit_test.py deleted file mode 100644 index cf84019..0000000 --- a/api/serializers/fruit_test.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 16:27:55(+01:00). -""" - -from datetime import timedelta -from unittest.mock import patch - -from codeforlife.tests import ModelSerializerTestCase -from codeforlife.user.models import User -from django.utils import timezone - -from ..models import Fruit -from .fruit import FruitSerializer - - -# pylint: disable-next=missing-class-docstring -class TestFruitSerializer(ModelSerializerTestCase[User, Fruit]): - model_serializer_class = FruitSerializer - - def test_create(self): - """Creating a fruit instance sets the expiry date to 3 days from now.""" - now = timezone.now() - with patch.object(timezone, "now", return_value=now): - self.assert_create( - validated_data={"name": "kiwi", "is_citrus": False}, - new_data={"expires_on": now.date() + timedelta(days=3)}, - ) diff --git a/api/urls.py b/api/urls.py index 735d6b8..8506982 100644 --- a/api/urls.py +++ b/api/urls.py @@ -19,13 +19,13 @@ from codeforlife.urls import get_urlpatterns from rest_framework.routers import DefaultRouter -from .views import FruitViewSet +# from .views import FruitViewSet router = DefaultRouter() -router.register( - "fruits", - FruitViewSet, - basename="fruit", -) +# router.register( +# "fruits", +# FruitViewSet, +# basename="fruit", +# ) urlpatterns = get_urlpatterns(router.urls) diff --git a/api/views/__init__.py b/api/views/__init__.py index 435c50f..e7f7f62 100644 --- a/api/views/__init__.py +++ b/api/views/__init__.py @@ -2,5 +2,3 @@ © Ocado Group Created on 02/07/2024 at 11:59:45(+01:00). """ - -from .fruit import FruitViewSet diff --git a/api/views/fruit.py b/api/views/fruit.py deleted file mode 100644 index 092b1d5..0000000 --- a/api/views/fruit.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 15:24:20(+01:00). -""" - -from codeforlife.permissions import AllowAny -from codeforlife.user.models import User -from codeforlife.views import ModelViewSet - -from ..models import Fruit -from ..serializers import FruitSerializer - - -# pylint: disable-next=missing-class-docstring,too-many-ancestors -class FruitViewSet(ModelViewSet[User, Fruit]): - http_method_names = ["get", "post"] - permission_classes = [AllowAny] - serializer_class = FruitSerializer - queryset = Fruit.objects.all() diff --git a/api/views/fruit_test.py b/api/views/fruit_test.py deleted file mode 100644 index 4b4094b..0000000 --- a/api/views/fruit_test.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -© Ocado Group -Created on 02/07/2024 at 16:38:57(+01:00). -""" - -from codeforlife.tests import ModelViewSetTestCase -from codeforlife.user.models import User - -from ..models import Fruit -from .fruit import FruitViewSet - - -# pylint: disable-next=missing-class-docstring,too-many-ancestors -class TestFruitViewSet(ModelViewSetTestCase[User, Fruit]): - basename = "fruit" - model_view_set_class = FruitViewSet - fixtures = ["fruits"] - - def setUp(self): - self.apple = Fruit.objects.get(name="apple") - self.banana = Fruit.objects.get(name="banana") - self.orange = Fruit.objects.get(name="orange") - - def test_list(self): - """Can list all fruits.""" - self.client.list(models=[self.apple, self.banana, self.orange]) - - def test_retrieve(self): - """Can retrieve a single fruit.""" - self.client.retrieve(model=self.apple) - - def test_create(self): - """Can create a fruit.""" - self.client.create(data={"name": "kiwi", "is_citrus": False}) From 93f73989d353e969efcb5ee922670b2b4974071b Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:48:42 +0000 Subject: [PATCH 26/42] Delete last fruit migration --- api/migrations/0001_initial.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 api/migrations/0001_initial.py diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py deleted file mode 100644 index c169fca..0000000 --- a/api/migrations/0001_initial.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-02 15:57 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Fruit', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=50, verbose_name='name')), - ('is_citrus', models.BooleanField(verbose_name='is citrus')), - ('expires_on', models.DateField(verbose_name='expires on')), - ], - options={ - 'verbose_name': 'fruit', - 'verbose_name_plural': 'fruits', - }, - ), - ] From 9fba816c91061dbb6425303809b0b6b29ed297da Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 10:58:19 +0000 Subject: [PATCH 27/42] Fix migration issue --- api/migrations/0001_initial.py | 27 +++++++++++++++++++++++++++ api/migrations/0004_delete_fruit.py | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 api/migrations/0001_initial.py create mode 100644 api/migrations/0004_delete_fruit.py diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py new file mode 100644 index 0000000..c169fca --- /dev/null +++ b/api/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.25 on 2024-07-02 15:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Fruit', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='name')), + ('is_citrus', models.BooleanField(verbose_name='is citrus')), + ('expires_on', models.DateField(verbose_name='expires on')), + ], + options={ + 'verbose_name': 'fruit', + 'verbose_name_plural': 'fruits', + }, + ), + ] diff --git a/api/migrations/0004_delete_fruit.py b/api/migrations/0004_delete_fruit.py new file mode 100644 index 0000000..9fad9bd --- /dev/null +++ b/api/migrations/0004_delete_fruit.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.25 on 2024-07-10 10:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0003_auto_20240709_1347'), + ] + + operations = [ + migrations.DeleteModel( + name='Fruit', + ), + ] From 5dab9d0226b5f12f41401a751e5c5e087e87e501 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 14:56:56 +0000 Subject: [PATCH 28/42] change data fields --- api/fixtures/agreement_signatures.json | 12 ++++++------ api/fixtures/contributors.json | 6 +++--- api/fixtures/repositories.json | 25 +++++++++++++------------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/api/fixtures/agreement_signatures.json b/api/fixtures/agreement_signatures.json index cec6266..8a29b8b 100644 --- a/api/fixtures/agreement_signatures.json +++ b/api/fixtures/agreement_signatures.json @@ -3,8 +3,8 @@ "model": "api.agreementsignature", "pk": 1, "fields": { - "contributor": 111111, - "agreement_id": "g3d3d3s8dgd3vc37", + "contributor": 1, + "agreement_id": "g3d3d3s8dgd3vc37232fef32232df3f3f31fgawf", "signed_at": "2024-01-02T12:00:00Z" } }, @@ -12,8 +12,8 @@ "model": "api.agreementsignature", "pk": 2, "fields": { - "contributor": 222222, - "agreement_id": "g3d3d3s8dgd3vc37", + "contributor": 2, + "agreement_id": "g3d3d3s8dgd43vc37232fef0898df3f3f31fgawf", "signed_at": "2024-01-02T12:00:00Z" } }, @@ -21,8 +21,8 @@ "model": "api.agreementsignature", "pk": 3, "fields": { - "contributor": 333333, - "agreement_id": "g3d3d3s8dgd3vc37", + "contributor": 3, + "agreement_id": "g379tuehr8dgd43vc37232fef0898df3f3f31fga", "signed_at": "2024-01-02T12:00:00Z" } } diff --git a/api/fixtures/contributors.json b/api/fixtures/contributors.json index 2a2b11f..da3019f 100644 --- a/api/fixtures/contributors.json +++ b/api/fixtures/contributors.json @@ -1,7 +1,7 @@ [ { "model": "api.contributor", - "pk": 111111, + "pk": 1, "fields": { "email": "contributor1@gmail.com", "name": "contributor1", @@ -12,7 +12,7 @@ }, { "model": "api.contributor", - "pk": 222222, + "pk": 2, "fields": { "email": "contributor2@gmail.com", "name": "contributor2", @@ -23,7 +23,7 @@ }, { "model": "api.contributor", - "pk": 333333, + "pk": 3, "fields": { "email": "contributor3@gmail.com", "name": "contributor3", diff --git a/api/fixtures/repositories.json b/api/fixtures/repositories.json index fa7de61..07545f3 100644 --- a/api/fixtures/repositories.json +++ b/api/fixtures/repositories.json @@ -1,29 +1,30 @@ [ { "model": "api.repository", - "pk": 111, + "pk": 1, "fields": { - "contributor": 111111, - "name": "rr", - "points": 10 + "contributor": 1, + "points": 10, + "gh_id": "10274252" } }, { "model": "api.repository", - "pk": 222, + "pk": 2, "fields": { - "contributor": 222222, - "name": "rr", - "points": 20 + "contributor": 2, + "points": 20, + "gh_id": "102097552" + } }, { "model": "api.repository", - "pk": 333, + "pk": 3, "fields": { - "contributor": 333333, - "name": "rr", - "points": 30 + "contributor": 3, + "points": 30, + "gh_id": "890732552" } } ] From 8b233605128aa79ef6597e54bde3db95e901013e Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 14:57:55 +0000 Subject: [PATCH 29/42] Apply changes after review --- api/migrations/0001_initial.py | 27 ---------- ...reementsignature_contributor_repository.py | 53 ------------------- api/migrations/0003_auto_20240709_1347.py | 21 -------- api/migrations/0004_delete_fruit.py | 16 ------ api/models/agreement_signature.py | 2 + api/models/agreement_signature_test.py | 8 +-- api/models/contributor.py | 4 +- api/models/contributor_test.py | 12 ++--- api/models/repository.py | 10 ++-- api/models/repository_test.py | 20 ++++--- api/urls.py | 7 --- 11 files changed, 28 insertions(+), 152 deletions(-) delete mode 100644 api/migrations/0001_initial.py delete mode 100644 api/migrations/0002_agreementsignature_contributor_repository.py delete mode 100644 api/migrations/0003_auto_20240709_1347.py delete mode 100644 api/migrations/0004_delete_fruit.py diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py deleted file mode 100644 index c169fca..0000000 --- a/api/migrations/0001_initial.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-02 15:57 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Fruit', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=50, verbose_name='name')), - ('is_citrus', models.BooleanField(verbose_name='is citrus')), - ('expires_on', models.DateField(verbose_name='expires on')), - ], - options={ - 'verbose_name': 'fruit', - 'verbose_name_plural': 'fruits', - }, - ), - ] diff --git a/api/migrations/0002_agreementsignature_contributor_repository.py b/api/migrations/0002_agreementsignature_contributor_repository.py deleted file mode 100644 index e7ad68f..0000000 --- a/api/migrations/0002_agreementsignature_contributor_repository.py +++ /dev/null @@ -1,53 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-09 10:23 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Contributor', - fields=[ - ('id', models.IntegerField(primary_key=True, serialize=False)), - ('email', models.TextField()), - ('name', models.TextField()), - ('location', models.TextField()), - ('html_url', models.TextField()), - ('avatar_url', models.TextField()), - ], - options={ - 'verbose_name': 'contributor', - 'verbose_name_plural': 'contributors', - }, - ), - migrations.CreateModel( - name='Repository', - fields=[ - ('id', models.IntegerField(primary_key=True, serialize=False)), - ('name', models.TextField(choices=[('portal', 'portal'), ('rr', 'rr')])), - ('points', models.IntegerField(default=0)), - ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), - ], - options={ - 'unique_together': {('contributor', 'name')}, - }, - ), - migrations.CreateModel( - name='AgreementSignature', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('agreement_id', models.CharField(max_length=40)), - ('signed_at', models.DateTimeField()), - ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), - ], - options={ - 'unique_together': {('contributor', 'agreement_id')}, - }, - ), - ] diff --git a/api/migrations/0003_auto_20240709_1347.py b/api/migrations/0003_auto_20240709_1347.py deleted file mode 100644 index e7c4eae..0000000 --- a/api/migrations/0003_auto_20240709_1347.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-09 12:47 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0002_agreementsignature_contributor_repository'), - ] - - operations = [ - migrations.AlterModelOptions( - name='agreementsignature', - options={'verbose_name': 'agreement_signature', 'verbose_name_plural': 'agreement_signatures'}, - ), - migrations.AlterModelOptions( - name='repository', - options={'verbose_name': 'repository', 'verbose_name_plural': 'repositories'}, - ), - ] diff --git a/api/migrations/0004_delete_fruit.py b/api/migrations/0004_delete_fruit.py deleted file mode 100644 index 9fad9bd..0000000 --- a/api/migrations/0004_delete_fruit.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 3.2.25 on 2024-07-10 10:57 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0003_auto_20240709_1347'), - ] - - operations = [ - migrations.DeleteModel( - name='Fruit', - ), - ] diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 445401c..4576d7a 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -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() diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py index b634564..7554d5a 100644 --- a/api/models/agreement_signature_test.py +++ b/api/models/agreement_signature_test.py @@ -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.""" @@ -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", ) diff --git a/api/models/contributor.py b/api/models/contributor.py index e3e82e2..2647a69 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -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() @@ -29,4 +29,4 @@ class Meta(TypedModelMeta): verbose_name_plural = _("contributors") def __str__(self): - return self.name + return f"{self.name} <{self.email}>" diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py index 37b9c78..a5858d8 100644 --- a/api/models/contributor_test.py +++ b/api/models/contributor_test.py @@ -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""" diff --git a/api/models/repository.py b/api/models/repository.py index 334d1c3..bf304bd 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -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}" diff --git a/api/models/repository_test.py b/api/models/repository_test.py index f4c43d6..8e464fe 100644 --- a/api/models/repository_test.py +++ b/api/models/repository_test.py @@ -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 @@ -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""" @@ -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="newcontributor@gmail.com", 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 ) diff --git a/api/urls.py b/api/urls.py index 8506982..13b885f 100644 --- a/api/urls.py +++ b/api/urls.py @@ -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) From 9fe496d266d5223077dfb6cbe498dcfe4090a0ed Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 15:00:10 +0000 Subject: [PATCH 30/42] apply initial migrations --- api/migrations/0001_initial.py | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 api/migrations/0001_initial.py diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py new file mode 100644 index 0000000..d990b0e --- /dev/null +++ b/api/migrations/0001_initial.py @@ -0,0 +1,58 @@ +# Generated by Django 3.2.25 on 2024-07-10 14:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Contributor', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('email', models.EmailField(max_length=254)), + ('name', models.TextField()), + ('location', models.TextField()), + ('html_url', models.TextField()), + ('avatar_url', models.TextField()), + ], + options={ + 'verbose_name': 'contributor', + 'verbose_name_plural': 'contributors', + }, + ), + migrations.CreateModel( + 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)), + ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), + ], + options={ + 'verbose_name': 'repository', + 'verbose_name_plural': 'repositories', + 'unique_together': {('contributor', 'gh_id')}, + }, + ), + migrations.CreateModel( + name='AgreementSignature', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('agreement_id', models.CharField(max_length=40)), + ('signed_at', models.DateTimeField()), + ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), + ], + options={ + 'verbose_name': 'agreement_signature', + 'verbose_name_plural': 'agreement_signatures', + 'unique_together': {('contributor', 'agreement_id')}, + }, + ), + ] From 7f3efa4432b5374bf3cb42c76f79c8043fc0c2b0 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Wed, 10 Jul 2024 15:04:04 +0000 Subject: [PATCH 31/42] Fix contributor type error --- api/models/agreement_signature.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 4576d7a..ecd9e03 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -19,7 +19,7 @@ class AgreementSignature(models.Model): """Signature of a contributor signing the agreement""" - contributor: int + contributor_id: int contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) agreement_id = models.CharField(max_length=40) From bf18e02366cb9a512e23b8acf4e1f0d9f7a621a3 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Thu, 11 Jul 2024 10:02:19 +0000 Subject: [PATCH 32/42] Add verbose names --- api/models/agreement_signature.py | 8 ++++---- api/models/contributor.py | 10 +++++----- api/models/repository.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index ecd9e03..27b59fe 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -22,13 +22,13 @@ class AgreementSignature(models.Model): contributor_id: int contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - agreement_id = models.CharField(max_length=40) - signed_at = models.DateTimeField() + agreement_id = models.CharField(_("agreement id"), max_length=40) + signed_at = models.DateTimeField(_("signed at")) class Meta(TypedModelMeta): unique_together = ["contributor", "agreement_id"] - verbose_name = _("agreement_signature") - verbose_name_plural = _("agreement_signatures") + verbose_name = _("agreement signature") + verbose_name_plural = _("agreement signatures") def __str__(self): cont = f"Contributor {self.contributor} signed" diff --git a/api/models/contributor.py b/api/models/contributor.py index 2647a69..ffc83c8 100644 --- a/api/models/contributor.py +++ b/api/models/contributor.py @@ -18,11 +18,11 @@ class Contributor(models.Model): """A contributor that contributes to a repo""" id = models.IntegerField(primary_key=True) - email = models.EmailField() - name = models.TextField() - location = models.TextField() - html_url = models.TextField() - avatar_url = models.TextField() + 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") diff --git a/api/models/repository.py b/api/models/repository.py index bf304bd..127024c 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -23,7 +23,7 @@ class Repository(models.Model): contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) gh_id = models.IntegerField(_("GitHub ID")) - points = models.IntegerField(default=0) + points = models.IntegerField(_("points"), default=0) class Meta(TypedModelMeta): unique_together = ["contributor", "gh_id"] From bf17776836fc7ad77580043efebab29a68b9be3a Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Thu, 11 Jul 2024 10:16:56 +0000 Subject: [PATCH 33/42] Fix import error --- api/migrations/0001_initial.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py index d990b0e..4c2007c 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-10 14:59 +# Generated by Django 3.2.25 on 2024-07-11 10:16 from django.db import migrations, models import django.db.models.deletion @@ -16,11 +16,11 @@ class Migration(migrations.Migration): name='Contributor', fields=[ ('id', models.IntegerField(primary_key=True, serialize=False)), - ('email', models.EmailField(max_length=254)), - ('name', models.TextField()), - ('location', models.TextField()), - ('html_url', models.TextField()), - ('avatar_url', models.TextField()), + ('email', models.EmailField(max_length=254, verbose_name='email')), + ('name', models.TextField(verbose_name='name')), + ('location', models.TextField(verbose_name='location')), + ('html_url', models.TextField(verbose_name='html url')), + ('avatar_url', models.TextField(verbose_name='avatar url')), ], options={ 'verbose_name': 'contributor', @@ -32,7 +32,7 @@ class Migration(migrations.Migration): 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)), + ('points', models.IntegerField(default=0, verbose_name='points')), ('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.contributor')), ], options={ @@ -45,13 +45,13 @@ 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)), - ('signed_at', models.DateTimeField()), + ('agreement_id', models.CharField(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')), ], options={ - 'verbose_name': 'agreement_signature', - 'verbose_name_plural': 'agreement_signatures', + 'verbose_name': 'agreement signature', + 'verbose_name_plural': 'agreement signatures', 'unique_together': {('contributor', 'agreement_id')}, }, ), From 7fe08cd2c0ad8d5311fa31e9c43437e317c45032 Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Thu, 11 Jul 2024 10:52:36 +0000 Subject: [PATCH 34/42] Create api serializers --- api/serializers/agreement_signature.py | 9 +++++++++ api/serializers/contributor.py | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 api/serializers/agreement_signature.py create mode 100644 api/serializers/contributor.py diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py new file mode 100644 index 0000000..7182ddf --- /dev/null +++ b/api/serializers/agreement_signature.py @@ -0,0 +1,9 @@ +from codeforlife.serializers import ModelSerializer +from codeforlife.user.models import User + +from ..models import AgreementSignature + +class ContributorSerializer(ModelSerializer[User, AgreementSignature]): + class Meta: + model = AgreementSignature + fields = "__all__" \ No newline at end of file diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py new file mode 100644 index 0000000..e15544b --- /dev/null +++ b/api/serializers/contributor.py @@ -0,0 +1,9 @@ +from codeforlife.serializers import ModelSerializer +from codeforlife.user.models import User + +from ..models import Contributor + +class ContributorSerializer(ModelSerializer[User, Contributor]): + class Meta: + model = Contributor + fields = "__all__" \ No newline at end of file From f9029e336acec94d1b2e030e7847a28bd8be72c9 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 13:00:08 +0000 Subject: [PATCH 35/42] Test the serializer's functionality --- api/serializers/__init__.py | 3 ++ api/serializers/agreement_signature.py | 7 ++-- api/serializers/contributor.py | 5 ++- api/serializers/contributor_test.py | 45 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 api/serializers/contributor_test.py diff --git a/api/serializers/__init__.py b/api/serializers/__init__.py index 7e05fbc..f0bca6c 100644 --- a/api/serializers/__init__.py +++ b/api/serializers/__init__.py @@ -2,3 +2,6 @@ © Ocado Group Created on 02/07/2024 at 12:00:12(+01:00). """ + +from .agreement_signature import AgreementSignatureSerializer +from .contributor import ContributorSerializer diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py index 7182ddf..c86f851 100644 --- a/api/serializers/agreement_signature.py +++ b/api/serializers/agreement_signature.py @@ -3,7 +3,10 @@ from ..models import AgreementSignature -class ContributorSerializer(ModelSerializer[User, AgreementSignature]): + +class AgreementSignatureSerializer(ModelSerializer[User, AgreementSignature]): + """ """ + class Meta: model = AgreementSignature - fields = "__all__" \ No newline at end of file + fields = "__all__" diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py index e15544b..d696341 100644 --- a/api/serializers/contributor.py +++ b/api/serializers/contributor.py @@ -3,7 +3,10 @@ from ..models import Contributor + class ContributorSerializer(ModelSerializer[User, Contributor]): + """Contributor class""" + class Meta: model = Contributor - fields = "__all__" \ No newline at end of file + fields = "__all__" diff --git a/api/serializers/contributor_test.py b/api/serializers/contributor_test.py new file mode 100644 index 0000000..e31299d --- /dev/null +++ b/api/serializers/contributor_test.py @@ -0,0 +1,45 @@ +""" +© Ocado Group +Created on 12/07/2024 at 11:36:23(+01:00). +""" + +from codeforlife.tests import ModelSerializerTestCase +from codeforlife.user.models import User + +from ..models import Contributor +from .contributor import ContributorSerializer + + +class TestContributorSerializer(ModelSerializerTestCase[User, Contributor]): + """Test the functionality of the serializers""" + + model_serializer_class = ContributorSerializer + + def setUp(self): + self.data1 = { + "id": 1, + "email": "cont1@gmail.com", + "name": "Cont One", + "location": "London", + "html_url": "http://github.com/cont1", + "avatar_url": "https://testcont.github.io/gravatar-url-generator/", + } + + self.data2 = { + "id": 2, + "email": "cont2@gmail.com", + "name": "Cont Two", + "location": "London", + "html_url": "http://github.com/cont2", + "avatar_url": "https://cont2.github.io/gravatar-url-generator/", + } + + def test_create(self): + """Create a contributor""" + self.assert_create(validated_data=self.data1, new_data=self.data1) + + def test_create_list(self): + """List all contributor""" + # expected = [self.data1, self.data2] + self.assert_create(validated_data=self.data1, new_data=self.data1) + self.assert_create(validated_data=self.data2, new_data=self.data2) From b42133444138344d26315ee6d34f4727c1583e3f Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 13:05:11 +0000 Subject: [PATCH 36/42] Check static code --- api/serializers/agreement_signature.py | 4 +++- api/serializers/contributor.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py index c86f851..548dc24 100644 --- a/api/serializers/agreement_signature.py +++ b/api/serializers/agreement_signature.py @@ -5,8 +5,10 @@ class AgreementSignatureSerializer(ModelSerializer[User, AgreementSignature]): - """ """ + """Agreement serializer""" class Meta: + """Specify fields for the serializer""" + model = AgreementSignature fields = "__all__" diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py index d696341..8e80c92 100644 --- a/api/serializers/contributor.py +++ b/api/serializers/contributor.py @@ -8,5 +8,7 @@ class ContributorSerializer(ModelSerializer[User, Contributor]): """Contributor class""" class Meta: + """Specify fields for the serializer""" + model = Contributor fields = "__all__" From c040e515b7c0484e2bda040eb7ec80b6e072ec00 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 13:08:42 +0000 Subject: [PATCH 37/42] Add module doc strings --- api/serializers/agreement_signature.py | 5 +++++ api/serializers/contributor.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py index 548dc24..685c941 100644 --- a/api/serializers/agreement_signature.py +++ b/api/serializers/agreement_signature.py @@ -1,3 +1,8 @@ +""" +© Ocado Group +Created on 12/07/2024 at 14:07:45(+01:00). +""" + from codeforlife.serializers import ModelSerializer from codeforlife.user.models import User diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py index 8e80c92..ef67ea0 100644 --- a/api/serializers/contributor.py +++ b/api/serializers/contributor.py @@ -1,3 +1,7 @@ +""" +© Ocado Group +Created on 12/07/2024 at 14:07:59(+01:00). +""" from codeforlife.serializers import ModelSerializer from codeforlife.user.models import User From 276b70936c80ce302e4c626971cc669bff46ed7d Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 14:01:40 +0000 Subject: [PATCH 38/42] Contributor tests --- api/serializers/contributor_test.py | 55 ++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/api/serializers/contributor_test.py b/api/serializers/contributor_test.py index e31299d..4795bd4 100644 --- a/api/serializers/contributor_test.py +++ b/api/serializers/contributor_test.py @@ -16,6 +16,7 @@ class TestContributorSerializer(ModelSerializerTestCase[User, Contributor]): model_serializer_class = ContributorSerializer def setUp(self): + """Set up data to be used for testing""" self.data1 = { "id": 1, "email": "cont1@gmail.com", @@ -40,6 +41,58 @@ def test_create(self): def test_create_list(self): """List all contributor""" - # expected = [self.data1, self.data2] + # Create multiple Contributors self.assert_create(validated_data=self.data1, new_data=self.data1) self.assert_create(validated_data=self.data2, new_data=self.data2) + + # Compare results + queryset = Contributor.objects.all() + assert len(queryset) == 2 + + def test_get_first(self): + """Retrieve the first object""" + # Create multiple Contributors + self.assert_create(validated_data=self.data1, new_data=self.data1) + self.assert_create(validated_data=self.data2, new_data=self.data2) + + # Retrieve the first and compare + cont = Contributor.objects.first() + serializer = ContributorSerializer(cont) + assert serializer.data["id"] == self.data1["id"] + + def test_get_any(self): + """ " Retrieve any object using its id""" + # Create multiple Contributors + self.assert_create(validated_data=self.data1, new_data=self.data1) + self.assert_create(validated_data=self.data2, new_data=self.data2) + + # Retrieve by id and compare + cont = Contributor.objects.get(id=2) + serializer = ContributorSerializer(cont) + assert serializer.data["id"] == self.data2["id"] + + def test_update(self): + """Updating a single contributor""" + # Create a new contributor + cont = Contributor.objects.create( + id=1, + email="cont1@gmail.com", + name="Cont One", + location="London", + html_url="http://github.com/cont1", + avatar_url="https://testcont.github.io/gravatar-url-generator/", + ) + + # Expected Results + new_data = {"email": "new_email@gmail.com", "name": "New Name"} + expected = { + "id": 1, + "email": "new_email@gmail.com", + "name": "New Name", + "location": "London", + "html_url": "http://github.com/cont1", + "avatar_url": "https://testcont.github.io/gravatar-url-generator/", + } + self.assert_update( + instance=cont, validated_data=new_data, new_data=expected + ) From 6588722e23f8fb630c29311b2417d91d40d538de Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 15:30:27 +0000 Subject: [PATCH 39/42] Apply changes from second review --- api/models/agreement_signature.py | 8 +++-- api/models/agreement_signature_test.py | 35 ++++---------------- api/models/contributor.py | 4 ++- api/models/contributor_test.py | 20 ++++-------- api/models/repository.py | 15 ++++++--- api/models/repository_test.py | 44 ++++---------------------- 6 files changed, 40 insertions(+), 86 deletions(-) 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 - ) From 519dfddd2f911e7f40eadbb70ac26c56fceea61e Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 15:37:12 +0000 Subject: [PATCH 40/42] Migrate models --- api/migrations/0001_initial.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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')), ], From 18decc5fa22b6dd2ab2f4c195cd9124596ad3d25 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 16:32:13 +0000 Subject: [PATCH 41/42] Fix doc strings --- api/serializers/agreement_signature.py | 4 +- api/serializers/agreement_signature_test.py | 18 +++++ api/serializers/contributor.py | 4 +- api/serializers/contributor_test.py | 84 +-------------------- 4 files changed, 21 insertions(+), 89 deletions(-) create mode 100644 api/serializers/agreement_signature_test.py diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py index 685c941..e750812 100644 --- a/api/serializers/agreement_signature.py +++ b/api/serializers/agreement_signature.py @@ -10,10 +10,8 @@ class AgreementSignatureSerializer(ModelSerializer[User, AgreementSignature]): - """Agreement serializer""" + """Agreement serializer class""" class Meta: - """Specify fields for the serializer""" - model = AgreementSignature fields = "__all__" diff --git a/api/serializers/agreement_signature_test.py b/api/serializers/agreement_signature_test.py new file mode 100644 index 0000000..589c5e8 --- /dev/null +++ b/api/serializers/agreement_signature_test.py @@ -0,0 +1,18 @@ +""" +© Ocado Group +Created on 12/07/2024 at 17:16:58(+01:00). +""" + +from codeforlife.tests import ModelSerializerTestCase +from codeforlife.user.models import User + +from ..models import AgreementSignature +from .agreement_signature import AgreementSignatureSerializer + + +class TestAgreementSignatureSerializer( + ModelSerializerTestCase[User, AgreementSignature] +): + """Test the Agreement Signature serializers""" + + model_serializer_class = AgreementSignatureSerializer diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py index ef67ea0..4e2817c 100644 --- a/api/serializers/contributor.py +++ b/api/serializers/contributor.py @@ -9,10 +9,8 @@ class ContributorSerializer(ModelSerializer[User, Contributor]): - """Contributor class""" + """Contributor serializer class""" class Meta: - """Specify fields for the serializer""" - model = Contributor fields = "__all__" diff --git a/api/serializers/contributor_test.py b/api/serializers/contributor_test.py index 4795bd4..bf406b4 100644 --- a/api/serializers/contributor_test.py +++ b/api/serializers/contributor_test.py @@ -11,88 +11,6 @@ class TestContributorSerializer(ModelSerializerTestCase[User, Contributor]): - """Test the functionality of the serializers""" + """Test the Contributor serializers""" model_serializer_class = ContributorSerializer - - def setUp(self): - """Set up data to be used for testing""" - self.data1 = { - "id": 1, - "email": "cont1@gmail.com", - "name": "Cont One", - "location": "London", - "html_url": "http://github.com/cont1", - "avatar_url": "https://testcont.github.io/gravatar-url-generator/", - } - - self.data2 = { - "id": 2, - "email": "cont2@gmail.com", - "name": "Cont Two", - "location": "London", - "html_url": "http://github.com/cont2", - "avatar_url": "https://cont2.github.io/gravatar-url-generator/", - } - - def test_create(self): - """Create a contributor""" - self.assert_create(validated_data=self.data1, new_data=self.data1) - - def test_create_list(self): - """List all contributor""" - # Create multiple Contributors - self.assert_create(validated_data=self.data1, new_data=self.data1) - self.assert_create(validated_data=self.data2, new_data=self.data2) - - # Compare results - queryset = Contributor.objects.all() - assert len(queryset) == 2 - - def test_get_first(self): - """Retrieve the first object""" - # Create multiple Contributors - self.assert_create(validated_data=self.data1, new_data=self.data1) - self.assert_create(validated_data=self.data2, new_data=self.data2) - - # Retrieve the first and compare - cont = Contributor.objects.first() - serializer = ContributorSerializer(cont) - assert serializer.data["id"] == self.data1["id"] - - def test_get_any(self): - """ " Retrieve any object using its id""" - # Create multiple Contributors - self.assert_create(validated_data=self.data1, new_data=self.data1) - self.assert_create(validated_data=self.data2, new_data=self.data2) - - # Retrieve by id and compare - cont = Contributor.objects.get(id=2) - serializer = ContributorSerializer(cont) - assert serializer.data["id"] == self.data2["id"] - - def test_update(self): - """Updating a single contributor""" - # Create a new contributor - cont = Contributor.objects.create( - id=1, - email="cont1@gmail.com", - name="Cont One", - location="London", - html_url="http://github.com/cont1", - avatar_url="https://testcont.github.io/gravatar-url-generator/", - ) - - # Expected Results - new_data = {"email": "new_email@gmail.com", "name": "New Name"} - expected = { - "id": 1, - "email": "new_email@gmail.com", - "name": "New Name", - "location": "London", - "html_url": "http://github.com/cont1", - "avatar_url": "https://testcont.github.io/gravatar-url-generator/", - } - self.assert_update( - instance=cont, validated_data=new_data, new_data=expected - ) From 1f2dbfd5f306b289937508efb99ec6a3eb762bc7 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Tue, 16 Jul 2024 13:27:04 +0000 Subject: [PATCH 42/42] apply review changes --- api/serializers/agreement_signature.py | 2 +- api/serializers/contributor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/serializers/agreement_signature.py b/api/serializers/agreement_signature.py index e750812..9113139 100644 --- a/api/serializers/agreement_signature.py +++ b/api/serializers/agreement_signature.py @@ -14,4 +14,4 @@ class AgreementSignatureSerializer(ModelSerializer[User, AgreementSignature]): class Meta: model = AgreementSignature - fields = "__all__" + fields = ["id", "contributor", "agreement_id", "signed_at"] diff --git a/api/serializers/contributor.py b/api/serializers/contributor.py index 4e2817c..bd47679 100644 --- a/api/serializers/contributor.py +++ b/api/serializers/contributor.py @@ -13,4 +13,4 @@ class ContributorSerializer(ModelSerializer[User, Contributor]): class Meta: model = Contributor - fields = "__all__" + fields = ["id", "email", "name", "location", "html_url", "avatar_url"]