Skip to content

@ColonelThirtyTwo /models.py secret
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Django InlineFormset ValueError
from django.db import models
class Container(models.Model):
pass
class Item(models.Model):
container = models.ForeignKey(Container)
data = models.CharField(max_length=123)
from django.test import TestCase
from django.forms.models import inlineformset_factory, BaseInlineFormSet
from test_app.models import Container, Item
TestFormSet = inlineformset_factory(Container, Item, extra=0)
class MyTestCase(TestCase):
def setUp(self):
self.container = Container.objects.create()
self.existingItem = Item.objects.create(container=self.container, data="asdf")
self.test_data = {
"item_set-TOTAL_FORMS": "2",
"item_set-MAX_NUM_FORMS": "1000",
"item_set-INITIAL_FORMS": "1",
"item_set-0-id": "", # Not valid
"item_set-0-data": "foo",
"item_set-1-id": str(self.existingItem.id),
"item_set-1-data": str(self.existingItem.data),
}
def test_django_formset_int_error(self):
formset = TestFormSet(self.test_data, instance=self.container)
try:
formset.is_valid()
except ValueError:
self.fail("Formset.is_valid() raised unexpected exception.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.