US #55: Custom fields - Fix a problem with serializer classes and mixins

remotes/origin/enhancement/email-actions
David Barragán Merino 2015-02-18 13:02:45 +01:00
parent 22e62b4f65
commit 5eddda9803
5 changed files with 15 additions and 18 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]