Skip to content

Commit

Permalink
feat(delete): Prepare deletion of ddm_pooled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-AP committed May 21, 2024
1 parent d5807b9 commit 66c0224
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 127 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'wagtail',
'modelcluster',
'taggit',
'ddm_pooled'
]

MIDDLEWARE = [
Expand Down
10 changes: 0 additions & 10 deletions ddm_pooled/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
from django.contrib import admin
from ddm_pooled.models import PooledProject


class PooledProjectAdmin(admin.ModelAdmin):
"""
Provides an overview of all Pooled Donation Projects.
"""
list_display = ['project']


admin.site.register(PooledProject, PooledProjectAdmin)
16 changes: 16 additions & 0 deletions ddm_pooled/migrations/0007_delete_pooledproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.17 on 2024-05-21 16:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ddm_pooled', '0006_delete_poolparticipant'),
]

operations = [
migrations.DeleteModel(
name='PooledProject',
),
]
12 changes: 0 additions & 12 deletions ddm_pooled/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,3 @@
from django.db import models


class PooledProject(models.Model):
project = models.OneToOneField('ddm.DonationProject', on_delete=models.CASCADE)
external_id = models.CharField(max_length=50, null=False, unique=True)

get_donation_consent = models.BooleanField(default=True)
donation_briefing = RichTextUploadingField(
null=True, blank=True,
verbose_name='Donation Briefing Text',
help_text='If "get donation consent" is enabled, will be displayed before '
'the debriefing page.',
config_name='ddm_ckeditor'
)
105 changes: 0 additions & 105 deletions ddm_pooled/tests.py
Original file line number Diff line number Diff line change
@@ -1,105 +0,0 @@
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils import timezone
from rest_framework import status
from rest_framework.test import APITestCase

from ddm.models.core import Participant, ResearchProfile, DonationProject
from ddm.tests.test_participation_flow import ParticipationFlowBaseTestCase
from ddm_pooled.models import PooledProject
from ddm_pooled.settings import POOL_KW, PROJECT_KW


User = get_user_model()


class ParticipantAPITests(APITestCase):
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create_user(**{
'username': 'u', 'password': '123', 'email': '[email protected]'
})
profile = ResearchProfile.objects.create(user=cls.user)
project = DonationProject.objects.create(
name='Base Project', slug='base', owner=profile)
cls.pooled_project = PooledProject.objects.create(
project=project, external_id='external_id')
Participant.objects.create(
project=project,
external_id='abc',
start_time=timezone.now(),
extra_data={'pool_id': 'test_pool'}
)

def test_get_participants(self):
"""
Ensure the correct participant information is retrieved.
"""
url = reverse('participant-list')
data = {
'extra_data': {'pool_id': 'test_pool'},
'external_id': '1',
'completed': False
}
self.client.force_authenticate(user=self.user)
response = self.client.get(
url, {POOL_KW: 'test_pool', PROJECT_KW: 'external_id'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 1)
self.assertCountEqual(dict(response.data[0]), data)

def test_get_participants_without_poolid(self):
"""
Ensure query without pool_id raises 400.
"""
url = reverse('participant-list')
self.client.force_authenticate(user=self.user)
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)


class TestPoolDonateView(ParticipationFlowBaseTestCase):

@classmethod
def setUpTestData(cls):
super().setUpTestData()
cls.pooled_project = PooledProject.objects.create(
project=cls.project_base, external_id='abc')

def setUp(self):
super().setUp()
self.initialize_project_and_session()
self.participant = self.get_participant(self.project_base.pk)
self.participant.current_step = 3
self.participant.save()

def test_redirect_to_donation_question(self):
response = self.client.get(self.debriefing_url)
self.assertEqual(response.status_code, 302)
self.assertRedirects(
response, reverse('ddm-pool-donate', args=[self.project_base.slug]))

def test_post_valid_form(self):
response = self.client.post(
reverse('ddm-pool-donate', args=[self.project_base.slug]),
{'donation_consent': '1'}
)
self.assertRedirects(response, reverse('debriefing', args=[self.project_base.slug]))
self.assertEqual(response.status_code, 302)
self.participant.refresh_from_db()
self.assertEqual(self.participant.extra_data['pool_donate'], True)

def test_post_invalid_form(self):
response = self.client.post(
reverse('ddm-pool-donate', args=[self.project_base.slug]),
{'donation_consent': 'fubar'}
)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'ddm_pooled/pool_donation_consent.html')

def test_skip_donation_question(self):
self.pooled_project.get_donation_consent = False
self.pooled_project.save()
response = self.client.get(self.debriefing_url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'ddm/public/debriefing.html')

0 comments on commit 66c0224

Please sign in to comment.