US #55: Custom fields - Fix a problem with serializer classes and mixins
parent
22e62b4f65
commit
5eddda9803
|
@ -333,7 +333,7 @@ class IssueCustomAttributeExportSerializer(serializers.ModelSerializer):
|
||||||
exclude = ('id', 'project')
|
exclude = ('id', 'project')
|
||||||
|
|
||||||
|
|
||||||
class CustomAttributesValuesExportSerializerMixin:
|
class CustomAttributesValuesExportSerializerMixin(serializers.ModelSerializer):
|
||||||
custom_attributes_values = serializers.SerializerMethodField("get_custom_attributes_values")
|
custom_attributes_values = serializers.SerializerMethodField("get_custom_attributes_values")
|
||||||
|
|
||||||
def custom_attributes_queryset(self, project):
|
def custom_attributes_queryset(self, project):
|
||||||
|
@ -351,14 +351,14 @@ class CustomAttributesValuesExportSerializerMixin:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
values = obj.custom_attributes_values.attributes_values
|
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)
|
return _use_name_instead_id_as_key_in_custom_attributes_values(custom_attributes, values)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class BaseCustomAttributesValuesExportSerializer:
|
class BaseCustomAttributesValuesExportSerializer(serializers.ModelSerializer):
|
||||||
attributes_values = JsonField(source="attributes_values",required=True)
|
attributes_values = JsonField(source="attributes_values",required=True)
|
||||||
_custom_attribute_model = None
|
_custom_attribute_model = None
|
||||||
_container_field = None
|
_container_field = None
|
||||||
|
@ -389,8 +389,7 @@ class BaseCustomAttributesValuesExportSerializer:
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer,
|
class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer):
|
||||||
serializers.ModelSerializer):
|
|
||||||
_custom_attribute_model = custom_attributes_models.UserStoryCustomAttribute
|
_custom_attribute_model = custom_attributes_models.UserStoryCustomAttribute
|
||||||
_container_model = "userstories.UserStory"
|
_container_model = "userstories.UserStory"
|
||||||
_container_field = "user_story"
|
_container_field = "user_story"
|
||||||
|
@ -400,8 +399,7 @@ class UserStoryCustomAttributesValuesExportSerializer(BaseCustomAttributesValues
|
||||||
exclude = ("id",)
|
exclude = ("id",)
|
||||||
|
|
||||||
|
|
||||||
class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer,
|
class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer):
|
||||||
serializers.ModelSerializer):
|
|
||||||
_custom_attribute_model = custom_attributes_models.TaskCustomAttribute
|
_custom_attribute_model = custom_attributes_models.TaskCustomAttribute
|
||||||
_container_field = "task"
|
_container_field = "task"
|
||||||
|
|
||||||
|
@ -410,8 +408,7 @@ class TaskCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExpor
|
||||||
exclude = ("id",)
|
exclude = ("id",)
|
||||||
|
|
||||||
|
|
||||||
class IssueCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer,
|
class IssueCustomAttributesValuesExportSerializer(BaseCustomAttributesValuesExportSerializer):
|
||||||
serializers.ModelSerializer):
|
|
||||||
_custom_attribute_model = custom_attributes_models.IssueCustomAttribute
|
_custom_attribute_model = custom_attributes_models.IssueCustomAttribute
|
||||||
_container_field = "issue"
|
_container_field = "issue"
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,8 @@ class IssueCustomAttributeSerializer(BaseCustomAttributeSerializer):
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
|
|
||||||
class BaseCustomAttributesValuesSerializer:
|
class BaseCustomAttributesValuesSerializer(ModelSerializer):
|
||||||
attributes_values = JsonField(source="attributes_values", label="attributes values", required=True)
|
attributes_values = JsonField(source="attributes_values", label="attributes values")
|
||||||
_custom_attribute_model = None
|
_custom_attribute_model = None
|
||||||
_container_field = None
|
_container_field = None
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class BaseCustomAttributesValuesSerializer:
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
class UserStoryCustomAttributesValuesSerializer(BaseCustomAttributesValuesSerializer, ModelSerializer):
|
class UserStoryCustomAttributesValuesSerializer(BaseCustomAttributesValuesSerializer):
|
||||||
_custom_attribute_model = models.UserStoryCustomAttribute
|
_custom_attribute_model = models.UserStoryCustomAttribute
|
||||||
_container_model = "userstories.UserStory"
|
_container_model = "userstories.UserStory"
|
||||||
_container_field = "user_story"
|
_container_field = "user_story"
|
||||||
|
|
|
@ -117,7 +117,7 @@ def test_issue_custom_attributes_values_create(client):
|
||||||
client.login(member.user)
|
client.login(member.user)
|
||||||
response = client.json.post(url, json.dumps(data))
|
response = client.json.post(url, json.dumps(data))
|
||||||
assert response.status_code == 201
|
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)
|
issue = issue.__class__.objects.get(id=issue.id)
|
||||||
assert issue.custom_attributes_values.attributes_values == data["attributes_values"]
|
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)
|
client.login(member.user)
|
||||||
response = client.json.patch(url, json.dumps(data))
|
response = client.json.patch(url, json.dumps(data))
|
||||||
assert response.status_code == 200
|
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)
|
issue = issue.__class__.objects.get(id=issue.id)
|
||||||
assert issue.custom_attributes_values.attributes_values == data["attributes_values"]
|
assert issue.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ def test_task_custom_attributes_values_create(client):
|
||||||
client.login(member.user)
|
client.login(member.user)
|
||||||
response = client.json.post(url, json.dumps(data))
|
response = client.json.post(url, json.dumps(data))
|
||||||
assert response.status_code == 201
|
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)
|
task = task.__class__.objects.get(id=task.id)
|
||||||
assert task.custom_attributes_values.attributes_values == data["attributes_values"]
|
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)
|
client.login(member.user)
|
||||||
response = client.json.patch(url, json.dumps(data))
|
response = client.json.patch(url, json.dumps(data))
|
||||||
assert response.status_code == 200
|
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)
|
task = task.__class__.objects.get(id=task.id)
|
||||||
assert task.custom_attributes_values.attributes_values == data["attributes_values"]
|
assert task.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ def test_userstory_custom_attributes_values_create(client):
|
||||||
client.login(member.user)
|
client.login(member.user)
|
||||||
response = client.json.post(url, json.dumps(data))
|
response = client.json.post(url, json.dumps(data))
|
||||||
assert response.status_code == 201
|
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)
|
user_story = user_story.__class__.objects.get(id=user_story.id)
|
||||||
assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]
|
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)
|
client.login(member.user)
|
||||||
response = client.json.patch(url, json.dumps(data))
|
response = client.json.patch(url, json.dumps(data))
|
||||||
assert response.status_code == 200
|
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)
|
user_story = user_story.__class__.objects.get(id=user_story.id)
|
||||||
assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]
|
assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue