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