Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api models #1

Merged
merged 36 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b267d6f
Start api models for contribution agreement (#82)
SalmanAsh Jul 5, 2024
84fd2a1
api models for contribution
SalmanAsh Jul 8, 2024
1db562a
change import sorting and format
SalmanAsh Jul 8, 2024
b70bda6
fixture data for testing
SalmanAsh Jul 9, 2024
bdb7581
change model fields
SalmanAsh Jul 9, 2024
24dc96a
test string parsing
SalmanAsh Jul 9, 2024
46c522f
Migrate models
SalmanAsh Jul 9, 2024
8878e9f
fixture data for testing
SalmanAsh Jul 9, 2024
a7681a4
api models and tests files
SalmanAsh Jul 9, 2024
47306f6
fix import statements
SalmanAsh Jul 9, 2024
0af1004
fix code format
SalmanAsh Jul 9, 2024
7e69d68
Fix static types
SalmanAsh Jul 9, 2024
ef5f20c
fix linting test file format
SalmanAsh Jul 9, 2024
72c5654
import fix
SalmanAsh Jul 9, 2024
44dfbb6
Check static code
SalmanAsh Jul 9, 2024
cc05cc2
import sort
SalmanAsh Jul 9, 2024
77e5a80
update DateTime Field
SalmanAsh Jul 9, 2024
9a8f976
Tests for models
SalmanAsh Jul 9, 2024
269ace9
Repository testing
SalmanAsh Jul 9, 2024
6249929
fix class name
SalmanAsh Jul 10, 2024
20a9537
tests for models
SalmanAsh Jul 10, 2024
9f55c76
correct formatting and comments
SalmanAsh Jul 10, 2024
def8ff7
Change meta classes
SalmanAsh Jul 10, 2024
0a22567
Fix code format and imports
SalmanAsh Jul 10, 2024
b5ec844
Delete all fruit files
SalmanAsh Jul 10, 2024
93f7398
Delete last fruit migration
SalmanAsh Jul 10, 2024
9fba816
Fix migration issue
SalmanAsh Jul 10, 2024
5dab9d0
change data fields
SalmanAsh Jul 10, 2024
8b23360
Apply changes after review
SalmanAsh Jul 10, 2024
9fe496d
apply initial migrations
SalmanAsh Jul 10, 2024
7f3efa4
Fix contributor type error
SalmanAsh Jul 10, 2024
bf18e02
Add verbose names
SalmanAsh Jul 11, 2024
bf17776
Fix import error
SalmanAsh Jul 11, 2024
6588722
Apply changes from second review
SalmanAsh Jul 12, 2024
519dfdd
Migrate models
SalmanAsh Jul 12, 2024
541c631
Merge branch 'development' into api-models
SKairinos Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions api/fixtures/agreement_signatures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"model": "api.agreementsignature",
"pk": 1,
"fields": {
"contributor": 1,
"agreement_id": "g3d3d3s8dgd3vc37232fef32232df3f3f31fgawf",
"signed_at": "2024-01-02T12:00:00Z"
}
},
{
"model": "api.agreementsignature",
"pk": 2,
"fields": {
"contributor": 2,
"agreement_id": "g3d3d3s8dgd43vc37232fef0898df3f3f31fgawf",
"signed_at": "2024-01-02T12:00:00Z"
}
},
{
"model": "api.agreementsignature",
"pk": 3,
"fields": {
"contributor": 3,
"agreement_id": "g379tuehr8dgd43vc37232fef0898df3f3f31fga",
"signed_at": "2024-01-02T12:00:00Z"
}
}
]
35 changes: 35 additions & 0 deletions api/fixtures/contributors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"model": "api.contributor",
"pk": 1,
"fields": {
"email": "[email protected]",
"name": "contributor1",
"location": "Hatfield",
"html_url": "https://github.com/contributor1",
"avatar_url": "https://contributor1.github.io/gravatar-url-generator/#/"
}
},
{
"model": "api.contributor",
"pk": 2,
"fields": {
"email": "[email protected]",
"name": "contributor2",
"location": "Hatfield",
"html_url": "https://github.com/contributor2",
"avatar_url": "https://contributor2.github.io/gravatar-url-generator/#/"
}
},
{
"model": "api.contributor",
"pk": 3,
"fields": {
"email": "[email protected]",
"name": "contributor3",
"location": "Hatfield",
"html_url": "https://github.com/contributor3",
"avatar_url": "https://contributor3.github.io/gravatar-url-generator/#/"
}
}
]
29 changes: 0 additions & 29 deletions api/fixtures/fruits.json

This file was deleted.

30 changes: 30 additions & 0 deletions api/fixtures/repositories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"model": "api.repository",
"pk": 1,
"fields": {
"contributor": 1,
"points": 10,
"gh_id": "10274252"
}
},
{
"model": "api.repository",
"pk": 2,
"fields": {
"contributor": 2,
"points": 20,
"gh_id": "102097552"

}
},
{
"model": "api.repository",
"pk": 3,
"fields": {
"contributor": 3,
"points": 30,
"gh_id": "890732552"
}
}
]
45 changes: 38 additions & 7 deletions api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 3.2.25 on 2024-07-02 15:57
# Generated by Django 3.2.25 on 2024-07-12 15:33

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -12,16 +13,46 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Fruit',
name='Contributor',
fields=[
('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')),
('html_url', models.TextField(verbose_name='html url')),
('avatar_url', models.TextField(verbose_name='avatar url')),
],
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(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={
'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')),
('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')),
('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')),
],
options={
'verbose_name': 'fruit',
'verbose_name_plural': 'fruits',
'verbose_name': 'agreement signature',
'verbose_name_plural': 'agreement signatures',
'unique_together': {('contributor', 'agreement_id')},
},
),
]
4 changes: 3 additions & 1 deletion api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
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 .repository import Repository
40 changes: 40 additions & 0 deletions api/models/agreement_signature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
© Ocado Group
Created on 08/07/2024 at 10:48:44(+01:00).
"""

import typing as t

from django.db import models
from django.utils.translation import gettext_lazy as _

from .contributor import Contributor

if t.TYPE_CHECKING:
from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover
else:
TypedModelMeta = object


class AgreementSignature(models.Model):
"""Signature of a contributor signing the agreement"""

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

agreement_id = models.CharField(
_("agreement id"),
max_length=40,
help_text=_("Commit ID of the contribution agreement in workspace."),
)
signed_at = models.DateTimeField(_("signed at"))

class Meta(TypedModelMeta):
unique_together = ["contributor", "agreement_id"]
verbose_name = _("agreement signature")
verbose_name_plural = _("agreement signatures")

def __str__(self):
cont = f"Contributor {self.contributor.pk} signed"
repo = f"{self.agreement_id[:7]} at {self.signed_at}"
return f"{cont} {repo}"
31 changes: 31 additions & 0 deletions api/models/agreement_signature_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
© Ocado Group
Created on 09/07/2024 at 11:43:42(+01:00).
"""

from codeforlife.tests import ModelTestCase

from .agreement_signature import AgreementSignature


class TestAgreementSignature(ModelTestCase[AgreementSignature]):
"""Test the AgreementSignature Model"""

fixtures = ["contributors", "agreement_signatures"]

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

def test_str(self):
"""
Parsing an agreement-signature instance to a string
that returns the contributor's primary key,
the first 7 characters of the agreement's commit ID
and the timestamp of when the agreement was signed.
"""
commit_id = self.agreement_signature.agreement_id[:7]
time = self.agreement_signature.signed_at
cont = f"Contributor {self.agreement_signature.contributor.pk} signed"
repo = f"{commit_id} at {time}"
expected_str = f"{cont} {repo}"
assert str(self.agreement_signature) == expected_str
34 changes: 34 additions & 0 deletions api/models/contributor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
© Ocado Group
Created on 05/07/2024 at 16:18:48(+01:00).
"""

import typing as t

from django.db import models
from django.utils.translation import gettext_lazy as _

if t.TYPE_CHECKING:
from django_stubs_ext.db.models import TypedModelMeta # pragma: no cover
else:
TypedModelMeta = object


class Contributor(models.Model):
"""A contributor that contributes to a repo"""

id = models.IntegerField(
primary_key=True, help_text=_("The contributor's GitHub user-ID.")
)
email = models.EmailField(_("email"))
name = models.TextField(_("name"))
location = models.TextField(_("location"))
html_url = models.TextField(_("html url"))
avatar_url = models.TextField(_("avatar url"))

class Meta(TypedModelMeta):
verbose_name = _("contributor")
verbose_name_plural = _("contributors")

def __str__(self):
return f"{self.name} <{self.email}>"
25 changes: 25 additions & 0 deletions api/models/contributor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
© Ocado Group
Created on 09/07/2024 at 09:39:50(+01:00).
"""

from codeforlife.tests import ModelTestCase

from .contributor import Contributor


class TestContributor(ModelTestCase[Contributor]):
"""Test the Contributor Model"""

fixtures = ["contributors"]

def setUp(self):
self.contributor = Contributor.objects.get(pk=1)

def test_str(self):
"""
Parsing a contributor instance to a string returns its name and email.
"""
name = self.contributor.name
email = self.contributor.email
assert str(self.contributor) == f"{name} <{email}>"
32 changes: 0 additions & 32 deletions api/models/fruit.py

This file was deleted.

28 changes: 0 additions & 28 deletions api/models/fruit_test.py

This file was deleted.

Loading
Loading