From 5eddda980316eacf31494921bb258a262bbfa487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Wed, 18 Feb 2015 13:02:45 +0100 Subject: [PATCH] US #55: Custom fields - Fix a problem with serializer classes and mixins --- taiga/export_import/serializers.py | 15 ++++++--------- taiga/projects/custom_attributes/serializers.py | 6 +++--- .../integration/test_custom_attributes_issues.py | 4 ++-- tests/integration/test_custom_attributes_tasks.py | 4 ++-- .../test_custom_attributes_user_stories.py | 4 ++-- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/taiga/export_import/serializers.py b/taiga/export_import/serializers.py index 4027556d..e3996e59 100644 --- a/taiga/export_import/serializers.py +++ b/taiga/export_import/serializers.py @@ -333,7 +333,7 @@ class IssueCustomAttributeExportSerializer(serializers.ModelSerializer): exclude = ('id', 'project') -class CustomAttributesValuesExportSerializerMixin: +class CustomAttributesValuesExportSerializerMixin(serializers.ModelSerializer): custom_attributes_values = serializers.SerializerMethodField("get_custom_attributes_values") def custom_attributes_queryset(self, project): @@ -351,14 +351,14 @@ class CustomAttributesValuesExportSerializerMixin: try: values = obj.custom_attributes_values.attributes_values - custom_attributes = self.custom_attribute_queryset(obj.project).values('id', 'name') + custom_attributes = self.custom_attributes_queryset(obj.project).values('id', 'name') return _use_name_instead_id_as_key_in_custom_attributes_values(custom_attributes, values) except ObjectDoesNotExist: return None -class BaseCustomAttributesValuesExportSerializer: +class BaseCustomAttributesValuesExportSerializer(serializers.ModelSerializer): attributes_values = JsonField(source="attributes_values",required=True) _custom_attribute_model = None _container_field = None @@ -389,8 +389,7 @@ class BaseCustomAttributesValuesExportSerializer: return attrs -class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer, - serializers.ModelSerializer): +class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer): _custom_attribute_model = custom_attributes_models.UserStoryCustomAttribute _container_model = "userstories.UserStory" _container_field = "user_story" @@ -400,8 +399,7 @@ class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValues exclude = ("id",) -class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer, - serializers.ModelSerializer): +class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer): _custom_attribute_model = custom_attributes_models.TaskCustomAttribute _container_field = "task" @@ -410,8 +408,7 @@ class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExpor exclude = ("id",) -class IssueCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer, - serializers.ModelSerializer): +class IssueCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer): _custom_attribute_model = custom_attributes_models.IssueCustomAttribute _container_field = "issue" diff --git a/taiga/projects/custom_attributes/serializers.py b/taiga/projects/custom_attributes/serializers.py index b295af16..06f46ec2 100644 --- a/taiga/projects/custom_attributes/serializers.py +++ b/taiga/projects/custom_attributes/serializers.py @@ -75,8 +75,8 @@ class IssueCustomAttributeSerializer(BaseCustomAttributeSerializer): ####################################################### -class BaseCustomAttributesValuesSerializer: - attributes_values = JsonField(source="attributes_values", label="attributes values", required=True) +class BaseCustomAttributesValuesSerializer(ModelSerializer): + attributes_values = JsonField(source="attributes_values", label="attributes values") _custom_attribute_model = None _container_field = None @@ -107,7 +107,7 @@ class BaseCustomAttributesValuesSerializer: return attrs -class UserStoryCustomAttributesValuesSerializer(BaseCustomAttributesValuesSerializer, ModelSerializer): +class UserStoryCustomAttributesValuesSerializer(BaseCustomAttributesValuesSerializer): _custom_attribute_model = models.UserStoryCustomAttribute _container_model = "userstories.UserStory" _container_field = "user_story" diff --git a/tests/integration/test_custom_attributes_issues.py b/tests/integration/test_custom_attributes_issues.py index 568f82c9..505fae5c 100644 --- a/tests/integration/test_custom_attributes_issues.py +++ b/tests/integration/test_custom_attributes_issues.py @@ -117,7 +117,7 @@ def test_issue_custom_attributes_values_create(client): client.login(member.user) response = client.json.post(url, json.dumps(data)) assert response.status_code == 201 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] issue = issue.__class__.objects.get(id=issue.id) assert issue.custom_attributes_values.attributes_values == data["attributes_values"] @@ -179,7 +179,7 @@ def test_issue_custom_attributes_values_update(client): client.login(member.user) response = client.json.patch(url, json.dumps(data)) assert response.status_code == 200 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] issue = issue.__class__.objects.get(id=issue.id) assert issue.custom_attributes_values.attributes_values == data["attributes_values"] diff --git a/tests/integration/test_custom_attributes_tasks.py b/tests/integration/test_custom_attributes_tasks.py index 33ebce5d..1a11bc17 100644 --- a/tests/integration/test_custom_attributes_tasks.py +++ b/tests/integration/test_custom_attributes_tasks.py @@ -116,7 +116,7 @@ def test_task_custom_attributes_values_create(client): client.login(member.user) response = client.json.post(url, json.dumps(data)) assert response.status_code == 201 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] task = task.__class__.objects.get(id=task.id) assert task.custom_attributes_values.attributes_values == data["attributes_values"] @@ -176,7 +176,7 @@ def test_task_custom_attributes_values_update(client): client.login(member.user) response = client.json.patch(url, json.dumps(data)) assert response.status_code == 200 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] task = task.__class__.objects.get(id=task.id) assert task.custom_attributes_values.attributes_values == data["attributes_values"] diff --git a/tests/integration/test_custom_attributes_user_stories.py b/tests/integration/test_custom_attributes_user_stories.py index f6f355ff..ab1fb5a3 100644 --- a/tests/integration/test_custom_attributes_user_stories.py +++ b/tests/integration/test_custom_attributes_user_stories.py @@ -116,7 +116,7 @@ def test_userstory_custom_attributes_values_create(client): client.login(member.user) response = client.json.post(url, json.dumps(data)) assert response.status_code == 201 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] user_story = user_story.__class__.objects.get(id=user_story.id) assert user_story.custom_attributes_values.attributes_values == data["attributes_values"] @@ -176,7 +176,7 @@ def test_userstory_custom_attributes_values_update(client): client.login(member.user) response = client.json.patch(url, json.dumps(data)) assert response.status_code == 200 - assert json.loads(response.data["attributes_values"]) == data["attributes_values"] + assert response.data["attributes_values"] == data["attributes_values"] user_story = user_story.__class__.objects.get(id=user_story.id) assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]