Ticket #24940: 24940-test.diff

File 24940-test.diff, 2.2 KB (added by Tim Graham, 9 years ago)
  • tests/generic_inline_admin/models.py

    diff --git a/tests/generic_inline_admin/models.py b/tests/generic_inline_admin/models.py
    index d15f2b9..491536b 100644
    a b class PhoneNumber(models.Model):  
    4848
    4949class Contact(models.Model):
    5050    name = models.CharField(max_length=50)
    51     phone_numbers = GenericRelation(PhoneNumber)
     51    phone_numbers = GenericRelation(PhoneNumber, related_query_name='phone_numbers')
    5252
    5353
    5454#
  • tests/generic_inline_admin/tests.py

    diff --git a/tests/generic_inline_admin/tests.py b/tests/generic_inline_admin/tests.py
    index c545608..cc09e73 100644
    a b from django.contrib.admin.sites import AdminSite  
    88from django.contrib.auth.models import User
    99from django.contrib.contenttypes.admin import GenericTabularInline
    1010from django.contrib.contenttypes.forms import generic_inlineformset_factory
     11from django.contrib.contenttypes.models import ContentType
    1112from django.core.urlresolvers import reverse
    1213from django.forms.formsets import DEFAULT_MAX_NUM
    1314from django.forms.models import ModelForm
    from django.test import (  
    1617)
    1718
    1819from .admin import MediaInline, MediaPermanentInline, site as admin_site
    19 from .models import Category, Episode, EpisodePermanent, Media
     20from .models import Category, Episode, EpisodePermanent, Media, PhoneNumber
    2021
    2122
    2223class TestDataMixin(object):
    class GenericInlineAdminWithUniqueTogetherTest(TestDataMixin, TestCase):  
    313314        response = self.client.post(reverse('admin:generic_inline_admin_contact_add'), post_data)
    314315        self.assertEqual(response.status_code, 302)  # redirect somewhere
    315316
     317    def test_delete(self):
     318        from .models import Contact
     319        c = Contact.objects.create(name='foo')
     320        PhoneNumber.objects.create(
     321            object_id=c.id,
     322            content_type=ContentType.objects.get_for_model(Contact),
     323            phone_number="555-555-5555",
     324        )
     325        response = self.client.post(reverse('admin:generic_inline_admin_contact_delete', args=[c.pk]))
     326        self.assertContains(response, 'Are you sure you want to delete')
     327
    316328
    317329@override_settings(ROOT_URLCONF="generic_inline_admin.urls")
    318330class NoInlineDeletionTest(SimpleTestCase):
Back to Top