def setUp(self): super(TestAppDataForms, self).setUp() MyAppContainer = AppDataContainer.from_form(self.MyForm) app_registry.register('myapp', MyAppContainer) self.data = {'title': 'First!', 'publish_from': '2010-10-1'} MyOtherContainer = AppDataContainer.from_form(self.MyOtherForm) app_registry.register('myotherapp', MyOtherContainer)
def setUp(self): super(TestAppDataForms, self).setUp() MyAppContainer = AppDataContainer.from_form(self.MyForm) app_registry.register('myapp', MyAppContainer) self.data = { 'title': 'First!', 'publish_from': '2010-10-1' } MyOtherContainer = AppDataContainer.from_form(self.MyOtherForm) app_registry.register('myotherapp', MyOtherContainer)
def setUp(self): super(TestSerialization, self).setUp() MyAppContainer = AppDataContainer.from_form(self.MyForm) app_registry.register('myapp', MyAppContainer) self.article = Article() self.article.app_data.myapp.publish_from = date(2012, 8, 26) self.article.save()
def test_container_from_form(self): class MyForm(AppDataForm): publish_from = forms.DateField() MyAppContainer = AppDataContainer.from_form(MyForm) app_registry.register('myapp', MyAppContainer) art = Article() tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer))
def test_get_fallback_value(self): class MyForm(AppDataForm): title = forms.CharField(max_length=25, initial='Hullo!') MyAppContainer = AppDataContainer.from_form(MyForm) app_registry.register('myapp', MyAppContainer) art = Article() tools.assert_equals(None, art.app_data.myapp.get('foo')) tools.assert_equals('bar', art.app_data.myapp.get('foo', 'bar'))
def test_initial_get_used_as_default(self): class MyForm(AppDataForm): title = forms.CharField(max_length=25, initial='Hullo!') MyAppContainer = AppDataContainer.from_form(MyForm) app_registry.register('myapp', MyAppContainer) art = Article() tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer)) tools.assert_equals('Hullo!', art.app_data.myapp.get('title'))
def test_get_semantics_for_getitem(self): class MyForm(AppDataForm): title = forms.CharField(max_length=25, initial='Hullo!') description = forms.CharField(max_length=25, required=False) MyAppContainer = AppDataContainer.from_form(MyForm) app_registry.register('myapp', MyAppContainer) art = Article() tools.assert_equals('Hullo!', art.app_data.myapp.title) # empty initial value falls back to field's type tools.assert_equals('', art.app_data.myapp.description)
def setUp(self): super(TestMultiForm, self).setUp() MyAppContainer = AppDataContainer.from_form(self.MyForm) app_registry.register('myapp', MyAppContainer) app_registry.register('myapp2', AppDataContainer.from_form(self.MyForm2))