def test_bulk_delete_participation(self) -> None: self.set_tenant(0) user = self.users[0] first_contact = Contact.objects.create(email='*****@*****.**', first_name='First', last_name='Smith') second_contact = Contact.objects.create(email='*****@*****.**', first_name='Second', last_name='Smith') campaign = Campaign.objects.create(name='cool campaign', owner=user) Participation.objects.bulk_create([ Participation(campaign=campaign, contact=first_contact), Participation(campaign=campaign, contact=second_contact), ]) t_client = TenantClient(self.get_current_tenant()) t_client.handler = ForceAuthClientHandler(enforce_csrf_checks=False) t_client.handler._force_user = user self.assertTrue(t_client.login(username=user.username, password='******'), 'Test user was not logged in') url = reverse.reverse('api:campaigns-contacts-list', args=[campaign.pk, ]) with modify_settings(ALLOWED_HOSTS={'append': self.get_current_tenant().domain_url}): response = t_client.delete(urljoin(url, '?contact__in=%s' % str(first_contact.id)), content_type='application/json', ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, str(response.content)) participation = Participation.objects.get(campaign=campaign) self.assertEqual(second_contact, participation.contact)
def test_bulk_delete_with_filtering(self) -> None: self.set_tenant(0) first_contact = Contact.objects.create(email='*****@*****.**', first_name='First', last_name='Smith') second_contact = Contact.objects.create(email='*****@*****.**', first_name='Second', last_name='Smith') third_contact = Contact.objects.create(email='*****@*****.**', first_name='Third', last_name='Smith') t_client = TenantClient(self.get_current_tenant()) t_client.handler = ForceAuthClientHandler(enforce_csrf_checks=False) t_client.handler._force_user = self.user self.assertTrue( t_client.login(username=self.user.username, password='******'), 'Test user was not logged in') ids_for_delete = [ first_contact.id, third_contact.id, ] url = reverse.reverse('api:contacts-list') with modify_settings( ALLOWED_HOSTS={'append': self.get_current_tenant().domain_url }): response = t_client.delete( urljoin( url, '?id__in=%s' % ','.join(str(pk) for pk in ids_for_delete))) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, str(response.content)) self.assertFalse( Contact.objects.filter(id__in=ids_for_delete).exists()) self.assertTrue(Contact.objects.filter(id=second_contact.id).exists())