Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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)