def test_save_none_in_menu(self): form = ImportMenusForm(data={ 'klass': 'menuhin.tests.data.TestMenu1', 'site': 1, }, files=None) self.assertTrue(form.is_valid()) result = form.save() self.assertIsNone(result)
def test_menu_class_instance_from_cleaned_data(self): form = ImportMenusForm(data={ 'klass': 'menuhin.tests.data.TestMenu2', 'site': 1, }, files=None) self.assertTrue(form.is_valid()) klass = form._menu_class_instance_from_cleaned_data() self.assertIsInstance(klass, TestMenu2)
def test_invalid_cleaned_data_instance(self): form = ImportMenusForm(data={ 'klass': 'menuhin.tests.data.TestMenu999999', 'site': 1, }, files=None) self.assertFalse(form.is_valid()) # now fake some stuff, just to cover the branch. form.cleaned_data = { 'klass': 'menuhin.tests.data.TestMenu999999' } with self.assertRaises(ValueError): form._menu_class_instance_from_cleaned_data()
def test_save_some_in_menu(self): try: admin.site.unregister(User) except NotRegistered: pass admin.site.register(User, UserAdmin) try: admin.site.unregister(MenuItem) except NotRegistered: pass admin.site.register(MenuItem, MenuItemAdmin) form = ImportMenusForm(data={ 'klass': 'menuhin.tests.data.TestMenu2', 'site': 1, }, files=None) self.assertTrue(form.is_valid()) result = form.save() self.assertIsNotNone(result) self.assertEqual(len(result), 3)