Skip to content

Commit

Permalink
Add test for copy reuse with filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 24, 2025
1 parent 8c3a08c commit dc637c9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions rdmo/projects/tests/test_viewset_project_value_copy_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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

0 comments on commit dc637c9

Please sign in to comment.