Ticket #18172: bug-18172-testcase.patch

File bug-18172-testcase.patch, 3.0 KB (added by msopacua, 3 years ago)

Testcase

  • tests/modeltests/model_forms/models.py

    diff -r 31cfaa8a671b tests/modeltests/model_forms/models.py
    a b  
    272272    slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
    273273    subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
    274274    posted = models.DateField(blank=True, null=True)
     275
     276@python_2_unicode_compatible
     277class Seller(models.Model) :
     278    name = models.CharField(max_length=50)
     279
     280    def __iter__(self) :
     281        for item in self.items.all() :
     282            yield item
     283
     284    def __str__(self) :
     285        return self.name
     286
     287class Antique(models.Model) :
     288    owner = models.ForeignKey(Seller, related_name='items')
     289    name = models.CharField(max_length=50)
     290
     291class Auction(models.Model) :
     292    location = models.CharField(max_length=50)
     293    sellers = models.ManyToManyField(Seller)
  • tests/modeltests/model_forms/tests.py

    diff -r 31cfaa8a671b tests/modeltests/model_forms/tests.py
    a b  
    1717    Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook,
    1818    DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
    1919    ImprovedArticleWithParentLink, Inventory, PhoneNumber, Post, Price,
    20     Product, TextFile, Writer, WriterProfile, test_images)
     20    Product, TextFile, Writer, WriterProfile, Seller, Antique, Auction,
     21    test_images)
    2122
    2223if test_images:
    2324    from .models import ImageFile, OptionalImageFile
     
    176177        model = Price
    177178        exclude = ('quantity',)
    178179
     180class AuctionForm(forms.ModelForm) :
     181    class Meta:
     182        model = Auction
    179183
    180184class ModelFormBaseTest(TestCase):
    181185    def test_base_form(self):
     
    14841488                         ['name'])
    14851489        self.assertHTMLEqual(six.text_type(CustomFieldForExclusionForm()),
    14861490                         '''<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>''')
     1491
     1492    def test_iterable_model_m2m(self) :
     1493        john = Seller.objects.create(name='John Smith')
     1494        jane = Seller.objects.create(name='Jane Smith')
     1495        chair = Antique.objects.create(name='Victorian armchair', owner=john)
     1496        table = Antique.objects.create(name='Victorian table', owner=john)
     1497        bowl = Antique.objects.create(name='Mayan medicine bowl', owner=jane)
     1498        form = AuctionForm()
     1499        self.assertHTMLEqual(form.as_p(), """<p><label for="id_location">Location:</label> <input id="id_location" type="text" name="location" maxlength="50" /></p>
     1500        <p><label for="id_sellers">Sellers:</label> <select multiple="multiple" name="sellers" id="id_sellers">
     1501        <option value="1">John Smith</option>
     1502        <option value="2">Jane Smith</option>
     1503        </select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>""")
Back to Top