US #55: Custom fields - Change 'values' field in CustomAttributesValues models to 'attributes_values'
parent
d1d0825d2e
commit
22e62b4f65
|
@ -350,7 +350,7 @@ class CustomAttributesValuesExportSerializerMixin:
|
|||
return ret
|
||||
|
||||
try:
|
||||
values = obj.custom_attributes_values.values
|
||||
values = obj.custom_attributes_values.attributes_values
|
||||
custom_attributes = self.custom_attribute_queryset(obj.project).values('id', 'name')
|
||||
|
||||
return _use_name_instead_id_as_key_in_custom_attributes_values(custom_attributes, values)
|
||||
|
@ -359,15 +359,15 @@ class CustomAttributesValuesExportSerializerMixin:
|
|||
|
||||
|
||||
class BaseCustomAttributesValuesExportSerializer:
|
||||
values = JsonField(source="values", label="values", required=True)
|
||||
attributes_values = JsonField(source="attributes_values",required=True)
|
||||
_custom_attribute_model = None
|
||||
_container_field = None
|
||||
|
||||
def validate_values(self, attrs, source):
|
||||
def validate_attributes_values(self, attrs, source):
|
||||
# values must be a dict
|
||||
data_values = attrs.get("values", None)
|
||||
data_values = attrs.get("attributes_values", None)
|
||||
if self.object:
|
||||
data_values = (data_values or self.object.values)
|
||||
data_values = (data_values or self.object.attributes_values)
|
||||
|
||||
if type(data_values) is not dict:
|
||||
raise ValidationError(_("Invalid content. It must be {\"key\": \"value\",...}"))
|
||||
|
|
|
@ -111,7 +111,7 @@ def store_custom_attributes(project, data, field, serializer):
|
|||
def store_custom_attributes_values(obj, data_values, obj_field, serializer_class):
|
||||
data = {
|
||||
obj_field: obj.id,
|
||||
"values": data_values,
|
||||
"attributes_values": data_values,
|
||||
}
|
||||
|
||||
serializer = serializer_class(data=data)
|
||||
|
|
|
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
|
||||
('version', models.IntegerField(default=1, verbose_name='version')),
|
||||
('values', django_pgjson.fields.JsonField(default={}, verbose_name='values')),
|
||||
('attributes_values', django_pgjson.fields.JsonField(default={}, verbose_name='attributes values')),
|
||||
('issue', models.OneToOneField(related_name='custom_attributes_values', to='issues.Issue', verbose_name='issue')),
|
||||
],
|
||||
options={
|
||||
|
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
|
||||
('version', models.IntegerField(default=1, verbose_name='version')),
|
||||
('values', django_pgjson.fields.JsonField(default={}, verbose_name='values')),
|
||||
('attributes_values', django_pgjson.fields.JsonField(default={}, verbose_name='attributes values')),
|
||||
('task', models.OneToOneField(related_name='custom_attributes_values', to='tasks.Task', verbose_name='task')),
|
||||
],
|
||||
options={
|
||||
|
@ -52,7 +52,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
|
||||
('version', models.IntegerField(default=1, verbose_name='version')),
|
||||
('values', django_pgjson.fields.JsonField(default={}, verbose_name='values')),
|
||||
('attributes_values', django_pgjson.fields.JsonField(default={}, verbose_name='attributes values')),
|
||||
('user_story', models.OneToOneField(related_name='custom_attributes_values', to='userstories.UserStory', verbose_name='user story')),
|
||||
],
|
||||
options={
|
||||
|
|
|
@ -42,7 +42,8 @@ class Migration(migrations.Migration):
|
|||
tablename := TG_ARGV[0]::text;
|
||||
|
||||
EXECUTE 'UPDATE ' || quote_ident(tablename) || '
|
||||
SET values = json_object_delete_keys(values, ' || quote_literal(key) || ')';
|
||||
SET attributes_values = json_object_delete_keys(attributes_values, ' ||
|
||||
quote_literal(key) || ')';
|
||||
|
||||
RETURN NULL;
|
||||
END; $clean_key_in_custom_attributes_values$
|
||||
|
|
|
@ -78,7 +78,7 @@ class IssueCustomAttribute(AbstractCustomAttribute):
|
|||
#######################################################
|
||||
|
||||
class AbstractCustomAttributesValues(OCCModelMixin, models.Model):
|
||||
values = JsonField(null=False, blank=False, default={}, verbose_name=_("values"))
|
||||
attributes_values = JsonField(null=False, blank=False, default={}, verbose_name=_("attributes_values"))
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
|
|
@ -76,15 +76,15 @@ class IssueCustomAttributeSerializer(BaseCustomAttributeSerializer):
|
|||
|
||||
|
||||
class BaseCustomAttributesValuesSerializer:
|
||||
values = JsonField(source="values", label="values", required=True)
|
||||
attributes_values = JsonField(source="attributes_values", label="attributes values", required=True)
|
||||
_custom_attribute_model = None
|
||||
_container_field = None
|
||||
|
||||
def validate_values(self, attrs, source):
|
||||
def validate_attributes_values(self, attrs, source):
|
||||
# values must be a dict
|
||||
data_values = attrs.get("values", None)
|
||||
data_values = attrs.get("attributes_values", None)
|
||||
if self.object:
|
||||
data_values = (data_values or self.object.values)
|
||||
data_values = (data_values or self.object.attributes_values)
|
||||
|
||||
if type(data_values) is not dict:
|
||||
raise ValidationError(_("Invalid content. It must be {\"key\": \"value\",...}"))
|
||||
|
|
|
@ -188,37 +188,37 @@ def extract_attachments(obj) -> list:
|
|||
@as_tuple
|
||||
def extract_user_story_custom_attributes(obj) -> list:
|
||||
with suppress(ObjectDoesNotExist):
|
||||
custom_attributes_values = obj.custom_attributes_values.values
|
||||
custom_attributes_values = obj.custom_attributes_values.attributes_values
|
||||
for attr in obj.project.userstorycustomattributes.all():
|
||||
with suppress(KeyError):
|
||||
value = custom_attributes_values[str(attr.id)]
|
||||
yield {"id": attr.id,
|
||||
"name": attr.name,
|
||||
"values": value}
|
||||
"value": value}
|
||||
|
||||
|
||||
@as_tuple
|
||||
def extract_task_custom_attributes(obj) -> list:
|
||||
with suppress(ObjectDoesNotExist):
|
||||
custom_attributes_values = obj.custom_attributes_values.values
|
||||
custom_attributes_values = obj.custom_attributes_values.attributes_values
|
||||
for attr in obj.project.taskcustomattributes.all():
|
||||
with suppress(KeyError):
|
||||
value = custom_attributes_values[str(attr.id)]
|
||||
yield {"id": attr.id,
|
||||
"name": attr.name,
|
||||
"values": value}
|
||||
"value": value}
|
||||
|
||||
|
||||
@as_tuple
|
||||
def extract_issue_custom_attributes(obj) -> list:
|
||||
with suppress(ObjectDoesNotExist):
|
||||
custom_attributes_values = obj.custom_attributes_values.values
|
||||
custom_attributes_values = obj.custom_attributes_values.attributes_values
|
||||
for attr in obj.project.issuecustomattributes.all():
|
||||
with suppress(KeyError):
|
||||
value = custom_attributes_values[str(attr.id)]
|
||||
yield {"id": attr.id,
|
||||
"name": attr.name,
|
||||
"values": value}
|
||||
"value": value}
|
||||
|
||||
|
||||
def project_freezer(project) -> dict:
|
||||
|
|
|
@ -270,10 +270,11 @@ class Command(BaseCommand):
|
|||
project=project)),
|
||||
tags=self.sd.words(1, 10).split(" "))
|
||||
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.issuecustomattributes.all() if self.sd.boolean()}
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.issuecustomattributes.all()
|
||||
if self.sd.boolean()}
|
||||
if custom_attributes_values:
|
||||
IssueCustomAttributesValues.objects.create(issue=bug,
|
||||
values=custom_attributes_values)
|
||||
attributes_values=custom_attributes_values)
|
||||
|
||||
for i in range(self.sd.int(*NUM_ATTACHMENTS)):
|
||||
attachment = self.create_attachment(bug, i+1)
|
||||
|
@ -318,10 +319,11 @@ class Command(BaseCommand):
|
|||
|
||||
task.save()
|
||||
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.taskcustomattributes.all() if self.sd.boolean()}
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.taskcustomattributes.all()
|
||||
if self.sd.boolean()}
|
||||
if custom_attributes_values:
|
||||
TaskCustomAttributesValues.objects.create(task=task,
|
||||
values=custom_attributes_values)
|
||||
attributes_values=custom_attributes_values)
|
||||
|
||||
for i in range(self.sd.int(*NUM_ATTACHMENTS)):
|
||||
attachment = self.create_attachment(task, i+1)
|
||||
|
@ -360,10 +362,11 @@ class Command(BaseCommand):
|
|||
|
||||
role_points.save()
|
||||
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.userstorycustomattributes.all() if self.sd.boolean()}
|
||||
custom_attributes_values = {str(ca.id): self.sd.paragraph() for ca in project.userstorycustomattributes.all()
|
||||
if self.sd.boolean()}
|
||||
if custom_attributes_values:
|
||||
UserStoryCustomAttributesValues.objects.create(user_story=us,
|
||||
values=custom_attributes_values)
|
||||
attributes_values=custom_attributes_values)
|
||||
|
||||
|
||||
for i in range(self.sd.int(*NUM_ATTACHMENTS)):
|
||||
|
|
|
@ -389,7 +389,7 @@ class UserStoryCustomAttributesValuesFactory(Factory):
|
|||
model = "custom_attributes.UserStoryCustomAttributesValues"
|
||||
strategy = factory.CREATE_STRATEGY
|
||||
|
||||
values = {}
|
||||
attributes_values = {}
|
||||
user_story = factory.SubFactory("tests.factories.UserStoryFactory")
|
||||
|
||||
|
||||
|
@ -398,7 +398,7 @@ class TaskCustomAttributesValuesFactory(Factory):
|
|||
model = "custom_attributes.TaskCustomAttributesValues"
|
||||
strategy = factory.CREATE_STRATEGY
|
||||
|
||||
values = {}
|
||||
attributes_values = {}
|
||||
task = factory.SubFactory("tests.factories.TaskFactory")
|
||||
|
||||
|
||||
|
@ -407,7 +407,7 @@ class IssueCustomAttributesValuesFactory(Factory):
|
|||
model = "custom_attributes.IssueCustomAttributesValues"
|
||||
strategy = factory.CREATE_STRATEGY
|
||||
|
||||
values = {}
|
||||
attributes_values = {}
|
||||
issue = factory.SubFactory("tests.factories.IssueFactory")
|
||||
|
||||
|
||||
|
|
|
@ -102,15 +102,15 @@ def data():
|
|||
#m.public_issue_cav = f.IssueCustomAttributesValuesFactory(project=m.public_project,
|
||||
# issue=f.IssueFactory(project=m.public_project,
|
||||
# owner=m.project_owner),
|
||||
# values={str(m.public_issue_ca.id):"test"})
|
||||
# attributes_values={str(m.public_issue_ca.id):"test"})
|
||||
#m.private_issue_cav1 = f.IssueCustomAttributesValuesFactory(project=m.private_project1,
|
||||
# issue=f.IssueFactory(project=m.private_project1,
|
||||
# owner=m.project_owner),
|
||||
# values={str(m.private_issue_ca1.id):"test"})
|
||||
# attributes_values={str(m.private_issue_ca1.id):"test"})
|
||||
#m.private_issue_cav2 = f.IssueCustomAttributesValuesFactory(project=m.private_project2,
|
||||
# issue=f.IssueFactory(project=m.private_project2,
|
||||
# owner=m.project_owner),
|
||||
# values={str(m.private_issue_ca2.id):"test"})
|
||||
# attributes_values={str(m.private_issue_ca2.id):"test"})
|
||||
|
||||
return m
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ def test_issue_custom_attributes_values_create(client):
|
|||
url = reverse("issue-custom-attributes-values-list")
|
||||
data = {
|
||||
"issue": issue.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -117,9 +117,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
issue = issue.__class__.objects.get(id=issue.id)
|
||||
assert issue.custom_attributes_values.values == data["values"]
|
||||
assert issue.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_issue_custom_attributes_values_create_with_error_invalid_key(client):
|
||||
|
@ -135,7 +135,7 @@ def test_issue_custom_attributes_values_create_with_error_invalid_key(client):
|
|||
url = reverse("issue-custom-attributes-values-list")
|
||||
data = {
|
||||
"issue": issue.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
"123456": "test_2"
|
||||
},
|
||||
|
@ -160,7 +160,7 @@ def test_issue_custom_attributes_values_update(client):
|
|||
|
||||
custom_attrs_val = f.IssueCustomAttributesValuesFactory(
|
||||
issue=issue,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -168,7 +168,7 @@ def test_issue_custom_attributes_values_update(client):
|
|||
|
||||
url = reverse("issue-custom-attributes-values-detail", args=[issue.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
ct2_id: "test_2_updated"
|
||||
},
|
||||
|
@ -179,9 +179,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
issue = issue.__class__.objects.get(id=issue.id)
|
||||
assert issue.custom_attributes_values.values == data["values"]
|
||||
assert issue.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_issue_custom_attributes_values_update_with_error_invalid_key(client):
|
||||
|
@ -197,7 +197,7 @@ def test_issue_custom_attributes_values_update_with_error_invalid_key(client):
|
|||
|
||||
custom_attrs_val = f.IssueCustomAttributesValuesFactory(
|
||||
issue=issue,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -205,7 +205,7 @@ def test_issue_custom_attributes_values_update_with_error_invalid_key(client):
|
|||
|
||||
url = reverse("issue-custom-attributes-values-detail", args=[issue.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
"123456": "test_2_updated"
|
||||
},
|
||||
|
@ -231,7 +231,7 @@ def test_issue_custom_attributes_values_delete(client):
|
|||
url = reverse("issue-custom-attributes-values-detail", args=[issue.id])
|
||||
custom_attrs_val = f.IssueCustomAttributesValuesFactory(
|
||||
issue=issue,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -258,7 +258,7 @@ def test_issue_custom_attributes_values_delete_us(client):
|
|||
url = reverse("issues-detail", args=[issue.id])
|
||||
custom_attrs_val = f.IssueCustomAttributesValuesFactory(
|
||||
issue=issue,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -287,19 +287,18 @@ def test_trigger_update_issuecustomvalues_afeter_remove_issuecustomattribute():
|
|||
ct2_id = "{}".format(custom_attr_2.id)
|
||||
|
||||
custom_attrs_val = f.IssueCustomAttributesValuesFactory(
|
||||
project=issue.project,
|
||||
issue=issue,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id in custom_attrs_val.attributes_values.keys()
|
||||
|
||||
custom_attr_2.delete()
|
||||
custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id not in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id not in custom_attrs_val.attributes_values.keys()
|
||||
|
|
|
@ -107,7 +107,7 @@ def test_task_custom_attributes_values_create(client):
|
|||
url = reverse("task-custom-attributes-values-list")
|
||||
data = {
|
||||
"task": task.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -116,9 +116,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
task = task.__class__.objects.get(id=task.id)
|
||||
assert task.custom_attributes_values.values == data["values"]
|
||||
assert task.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_task_custom_attributes_values_create_with_error_invalid_key(client):
|
||||
|
@ -134,7 +134,7 @@ def test_task_custom_attributes_values_create_with_error_invalid_key(client):
|
|||
url = reverse("task-custom-attributes-values-list")
|
||||
data = {
|
||||
"task": task.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
"123456": "test_2"
|
||||
},
|
||||
|
@ -158,7 +158,7 @@ def test_task_custom_attributes_values_update(client):
|
|||
|
||||
custom_attrs_val = f.TaskCustomAttributesValuesFactory(
|
||||
task=task,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -166,7 +166,7 @@ def test_task_custom_attributes_values_update(client):
|
|||
|
||||
url = reverse("task-custom-attributes-values-detail", args=[task.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
ct2_id: "test_2_updated"
|
||||
},
|
||||
|
@ -176,9 +176,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
task = task.__class__.objects.get(id=task.id)
|
||||
assert task.custom_attributes_values.values == data["values"]
|
||||
assert task.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_task_custom_attributes_values_update_with_error_invalid_key(client):
|
||||
|
@ -194,14 +194,14 @@ def test_task_custom_attributes_values_update_with_error_invalid_key(client):
|
|||
|
||||
custom_attrs_val = f.TaskCustomAttributesValuesFactory(
|
||||
task=task,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
)
|
||||
url = reverse("task-custom-attributes-values-detail", args=[task.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
"123456": "test_2_updated"
|
||||
},
|
||||
|
@ -228,7 +228,7 @@ def test_task_custom_attributes_values_delete(client):
|
|||
url = reverse("task-custom-attributes-values-detail", args=[task.id])
|
||||
custom_attrs_val = f.TaskCustomAttributesValuesFactory(
|
||||
task=task,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -255,7 +255,7 @@ def test_task_custom_attributes_values_delete_us(client):
|
|||
url = reverse("tasks-detail", args=[task.id])
|
||||
custom_attrs_val = f.TaskCustomAttributesValuesFactory(
|
||||
task=task,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -284,19 +284,18 @@ def test_trigger_update_userstorycustomvalues_afeter_remove_userstorycustomattri
|
|||
ct2_id = "{}".format(custom_attr_2.id)
|
||||
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
project=user_story.project,
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id in custom_attrs_val.attributes_values.keys()
|
||||
|
||||
custom_attr_2.delete()
|
||||
custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id not in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id not in custom_attrs_val.attributes_values.keys()
|
||||
|
|
|
@ -107,7 +107,7 @@ def test_userstory_custom_attributes_values_create(client):
|
|||
url = reverse("userstory-custom-attributes-values-list")
|
||||
data = {
|
||||
"user_story": user_story.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -116,9 +116,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
user_story = user_story.__class__.objects.get(id=user_story.id)
|
||||
assert user_story.custom_attributes_values.values == data["values"]
|
||||
assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_userstory_custom_attributes_values_create_with_error_invalid_key(client):
|
||||
|
@ -134,7 +134,7 @@ def test_userstory_custom_attributes_values_create_with_error_invalid_key(client
|
|||
url = reverse("userstory-custom-attributes-values-list")
|
||||
data = {
|
||||
"user_story": user_story.id,
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1",
|
||||
"123456": "test_2"
|
||||
},
|
||||
|
@ -158,7 +158,7 @@ def test_userstory_custom_attributes_values_update(client):
|
|||
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -166,7 +166,7 @@ def test_userstory_custom_attributes_values_update(client):
|
|||
|
||||
url = reverse("userstory-custom-attributes-values-detail", args=[user_story.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
ct2_id: "test_2_updated"
|
||||
},
|
||||
|
@ -176,9 +176,9 @@ 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["values"]) == data["values"]
|
||||
assert json.loads(response.data["attributes_values"]) == data["attributes_values"]
|
||||
user_story = user_story.__class__.objects.get(id=user_story.id)
|
||||
assert user_story.custom_attributes_values.values == data["values"]
|
||||
assert user_story.custom_attributes_values.attributes_values == data["attributes_values"]
|
||||
|
||||
|
||||
def test_userstory_custom_attributes_values_update_with_error_invalid_key(client):
|
||||
|
@ -194,7 +194,7 @@ def test_userstory_custom_attributes_values_update_with_error_invalid_key(client
|
|||
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -202,7 +202,7 @@ def test_userstory_custom_attributes_values_update_with_error_invalid_key(client
|
|||
|
||||
url = reverse("userstory-custom-attributes-values-detail", args=[user_story.id])
|
||||
data = {
|
||||
"values": {
|
||||
"attributes_values": {
|
||||
ct1_id: "test_1_updated",
|
||||
"123456": "test_2_updated"
|
||||
},
|
||||
|
@ -228,7 +228,7 @@ def test_userstory_custom_attributes_values_delete(client):
|
|||
url = reverse("userstory-custom-attributes-values-detail", args=[user_story.id])
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -255,7 +255,7 @@ def test_userstory_custom_attributes_values_delete_us(client):
|
|||
url = reverse("userstories-detail", args=[user_story.id])
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
|
@ -284,19 +284,18 @@ def test_trigger_update_userstorycustomvalues_afeter_remove_userstorycustomattri
|
|||
ct2_id = "{}".format(custom_attr_2.id)
|
||||
|
||||
custom_attrs_val = f.UserStoryCustomAttributesValuesFactory(
|
||||
project=user_story.project,
|
||||
user_story=user_story,
|
||||
values= {
|
||||
attributes_values= {
|
||||
ct1_id: "test_1",
|
||||
ct2_id: "test_2"
|
||||
},
|
||||
)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id in custom_attrs_val.attributes_values.keys()
|
||||
|
||||
custom_attr_2.delete()
|
||||
custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id)
|
||||
|
||||
assert ct1_id in custom_attrs_val.values.keys()
|
||||
assert ct2_id not in custom_attrs_val.values.keys()
|
||||
assert ct1_id in custom_attrs_val.attributes_values.keys()
|
||||
assert ct2_id not in custom_attrs_val.attributes_values.keys()
|
||||
|
|
|
@ -279,7 +279,7 @@ def test_valid_user_story_import_with_custom_attributes_values(client):
|
|||
assert response.status_code == 201
|
||||
custom_attributes_values = apps.get_model("custom_attributes.UserStoryCustomAttributesValues").objects.get(
|
||||
user_story__subject=response.data["subject"])
|
||||
assert custom_attributes_values.values == {str(custom_attr.id): "test_value"}
|
||||
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
|
||||
|
||||
|
||||
def test_valid_issue_import_without_extra_data(client):
|
||||
|
@ -329,7 +329,7 @@ def test_valid_issue_import_with_custom_attributes_values(client):
|
|||
assert response.status_code == 201
|
||||
custom_attributes_values = apps.get_model("custom_attributes.IssueCustomAttributesValues").objects.get(
|
||||
issue__subject=response.data["subject"])
|
||||
assert custom_attributes_values.values == {str(custom_attr.id): "test_value"}
|
||||
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
|
||||
|
||||
|
||||
def test_valid_issue_import_with_extra_data(client):
|
||||
|
@ -610,7 +610,7 @@ def test_valid_task_import_with_custom_attributes_values(client):
|
|||
assert response.status_code == 201
|
||||
custom_attributes_values = apps.get_model("custom_attributes.TaskCustomAttributesValues").objects.get(
|
||||
task__subject=response.data["subject"])
|
||||
assert custom_attributes_values.values == {str(custom_attr.id): "test_value"}
|
||||
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
|
||||
|
||||
|
||||
def test_valid_task_import_with_extra_data(client):
|
||||
|
|
Loading…
Reference in New Issue