From 18decc5fa22b6dd2ab2f4c195cd9124596ad3d25 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Fri, 12 Jul 2024 16:32:13 +0000 Subject: [PATCH] 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 - )