Commit 8ad9192a authored by Bengfort's avatar Bengfort
Browse files

adapt participation status for existing participations

parent 9cbc81fe
Pipeline #13073 passed with stages
in 5 minutes and 40 seconds
from django.db import migrations
STUDY_FINISHED = 2
PARTICIPATION_AWAITING_RESPONSE = 5
def migrate_data(apps, schema_editor):
Study = apps.get_model('studies', 'Study')
for study in Study.objects.filter(is_anonymous_invitation=True):
if study.status == STUDY_FINISHED:
study.participation_set.all().delete()
else:
study.participation_set.all().update(status=PARTICIPATION_AWAITING_RESPONSE)
class Migration(migrations.Migration):
dependencies = [
('recruitment', '0039_subject_uuid_foreign_key'),
('studies', '0046_rename_study_is_onetime_invitation'),
]
operations = [
migrations.RunPython(migrate_data),
]
import pytest
from model_bakery import baker
from tests.markers import skip_old_migration
@pytest.mark.django_db(databases=['default', 'contacts'])
@skip_old_migration('0.73.0')
def test_change_status(migrator):
old_state = migrator.apply_initial_migration([
('recruitment', '0039_subject_uuid_foreign_key'),
('studies', '0046_rename_study_is_onetime_invitation'),
])
Study = old_state.apps.get_model('studies', 'Study')
Participation = old_state.apps.get_model('recruitment', 'Participation')
EDIT = 1
FINISHED = 2
INVITED = 3
AWAITING_RESPONSE = 5
study1 = baker.make(Study, is_anonymous_invitation=True, status=EDIT)
participation1 = baker.make(Participation, study=study1, status=INVITED)
study2 = baker.make(Study, is_anonymous_invitation=True, status=FINISHED)
participation2 = baker.make(Participation, study=study2, status=INVITED)
new_state = migrator.apply_tested_migration(
('recruitment', '0040_change_anonymous_invitation_participation_status')
)
Participation = new_state.apps.get_model('recruitment', 'Participation')
participation1 = Participation.objects.filter(pk=participation1.pk).first()
participation2 = Participation.objects.filter(pk=participation2.pk).first()
assert participation1.status == AWAITING_RESPONSE
assert participation2 is None
migrator.reset()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment