From dc637c91a373dec2469b9f8becd0c3ce690bc9a1 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 24 Jan 2025 15:44:33 +0100 Subject: [PATCH] Add test for copy reuse with filter --- .../test_viewset_project_value_copy_set.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rdmo/projects/tests/test_viewset_project_value_copy_set.py b/rdmo/projects/tests/test_viewset_project_value_copy_set.py index 5b44e3610..c8e31564d 100644 --- a/rdmo/projects/tests/test_viewset_project_value_copy_set.py +++ b/rdmo/projects/tests/test_viewset_project_value_copy_set.py @@ -3,6 +3,9 @@ from django.contrib.auth.models import User from django.urls import reverse +from rdmo.options.models import OptionSet +from rdmo.questions.models import Question + from ..models import Membership, Project, Value urlnames = { @@ -244,3 +247,43 @@ def test_copy_reuse_invalid(db, client): assert response.status_code == 404 assert Value.objects.count() == values_count + 1 # one is the created set/id value assert Project.objects.get(id=other_project_id).values.count() == 1 + + +def test_copy_reuse_filter(db, client): + ''' + A set can be copied (imported) into an already existing set. + ''' + client.login(username='user', password='user') + + user = User.objects.get(username='user') + + set_value = Value.objects.get(id=set_value_id) + values_count = Value.objects.count() + + # change one question in the catalog + question = Question.objects.get(id=44) + question.optionsets.add(OptionSet.objects.get(id=1)) + + question = Question.objects.get(id=47) + question.optionsets.clear() + + # add the user to the project with the set value as well as the other project + Membership.objects.create(project_id=set_value.project.id, user=user, role='author') + Membership.objects.create(project_id=other_project_id, user=user, role='author') + + url = reverse(urlnames['copy-set'], args=[other_project_id]) + data = { + 'attribute': set_value.attribute.id, + 'set_prefix': set_value.set_prefix, + 'set_index': 0, + 'text': 'new' + } + response = client.post(url, data=json.dumps(dict(**data, copy_set_value=set_value_id)), + content_type="application/json") + assert response.status_code == 201 + assert Value.objects.get( + project=other_project_id, + snapshot=None, + **data + ) + assert Value.objects.count() == values_count + set_values_count + 1 - 2 # one is for set/id and two are skipped