def test_validation(self): # Fail without 'name' member. self.failUnlessRaises(ImproperlyConfigured, validate, \ TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured, e: self.failUnlessEqual(e.message, \ "No 'name' attribute found for tool TestInvalidTool.")
class ValidateTestCase(TestCase): """ Testcase testing object_tools.validation ObjectTool validation. """ @classmethod def setUpClass(cls): from django.contrib.auth.models import User cls.user_klass = User def test_validation(self): # Fail without 'name' member. self.failUnlessRaises( ImproperlyConfigured, validate, TestInvalidTool, self.user_klass ) try: validate(TestInvalidTool, self.user_klass) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'name' attribute found for tool TestInvalidTool." ) TestInvalidTool.name = 'test_invalid_tool' # Fail without 'label' member. self.failUnlessRaises( ImproperlyConfigured, validate, TestInvalidTool, self.user_klass ) try: validate(TestInvalidTool, self.user_klass) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'label' attribute found for tool TestInvalidTool." )
class ValidateTestCase(TestCase): """ Testcase testing object_tools.validation ObjectTool validation. """ def test_validation(self): # Fail without 'name' member. self.failUnlessRaises(ImproperlyConfigured, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'name' attribute found for tool TestInvalidTool.") TestInvalidTool.name = 'test_invalid_tool' # Fail without 'label' member. self.failUnlessRaises(ImproperlyConfigured, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'label' attribute found for tool TestInvalidTool.")
def register(self, object_tool_class, model_class=None): """ Registers the given model(s) with the given object tool class. The model(s) should be Model classes, not instances. If a model class isn't given the object tool class will be registered for all models. If a model is already registered, this will raise AlreadyRegistered. If a model is abstract, this will raise ImproperlyConfigured. """ if not object_tool_class: return None # Don't validate unless required. if object_tool_class and settings.DEBUG: from object_tools.validation import validate validate(object_tool_class, model_class) #= lambda model, adminclass: None if not model_class: models = get_models() else: models = [ model_class, ] for model in models: if model._meta.abstract: raise ImproperlyConfigured('The model %s is abstract, so it \ cannot be registered with object tools.' % \ model.__name__) # Instantiate the object_tools class to save in the registry if self._registry.has_key(model): self._registry[model].append(object_tool_class(model)) else: self._registry[model] = [ object_tool_class(model), ]
def test_validation(self): # Fail without 'name' member. self.assertRaises(ImproperlyConfigured, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured as e: message = str(e) self.assertEqual( message, "No 'name' attribute found for tool TestInvalidTool.") TestInvalidTool.name = 'test_invalid_tool' # Fail without 'label' member. self.assertRaises(ImproperlyConfigured, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured as e: message = str(e) self.assertEqual( message, "No 'label' attribute found for tool TestInvalidTool.") TestInvalidTool.label = 'Test Invalid Tool' # Fail without 'view' member. self.assertRaises(NotImplementedError, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except NotImplementedError as e: message = str(e) self.assertEqual( message, "No 'view' method found for tool TestInvalidTool.")
def register(self, object_tool_class, model_class=None): """ Registers the given model(s) with the given object tool class. The model(s) should be Model classes, not instances. If a model class isn't given the object tool class will be registered for all models. If a model is already registered, this will raise AlreadyRegistered. If a model is abstract, this will raise ImproperlyConfigured. """ if not object_tool_class: return None # Don't validate unless required. if object_tool_class and settings.DEBUG: from object_tools.validation import validate validate(object_tool_class, model_class) #= lambda model, adminclass: None if not model_class: models = get_models() else: models = [model_class, ] for model in models: if model._meta.abstract: raise ImproperlyConfigured( 'The model %s is abstract, so it \ cannot be registered with object tools.' % model.__name__) # Instantiate the object_tools class to save in the registry if model in self._registry: self._registry[model].append(object_tool_class(model)) else: self._registry[model] = [object_tool_class(model), ]
def test_validation(self): # Fail without 'name' member. self.assertRaises( ImproperlyConfigured, validate, TestInvalidTool, User ) try: validate(TestInvalidTool, User) except ImproperlyConfigured as e: message = str(e) self.assertEqual( message, "No 'name' attribute found for tool TestInvalidTool." ) TestInvalidTool.name = 'test_invalid_tool' # Fail without 'label' member. self.assertRaises( ImproperlyConfigured, validate, TestInvalidTool, User ) try: validate(TestInvalidTool, User) except ImproperlyConfigured as e: message = str(e) self.assertEqual( message, "No 'label' attribute found for tool TestInvalidTool." ) TestInvalidTool.label = 'Test Invalid Tool' # Fail without 'view' member. self.assertRaises( NotImplementedError, validate, TestInvalidTool, User ) try: validate(TestInvalidTool, User) except NotImplementedError as e: message = str(e) self.assertEqual( message, "No 'view' method found for tool TestInvalidTool." )
# Fail without 'label' member. self.failUnlessRaises(ImproperlyConfigured, validate, \ TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured, e: self.failUnlessEqual(e.message, \ "No 'label' attribute found for tool TestInvalidTool.") TestInvalidTool.label = 'Test Invalid Tool' # Fail without 'view' member. self.failUnlessRaises(NotImplementedError, validate, TestInvalidTool, \ User) try: validate(TestInvalidTool, User) except NotImplementedError, e: self.failUnlessEqual(e.message, \ "'view' method not implemented for tool TestInvalidTool.") class ObjectToolsInclusionTagsTestCase(TestCase): """ Testcase for object_tools.templatetags.object_tools_inclusion_tags. """ def test_object_tools(self): autodiscover() context = template.Context({ 'model': User, 'request': RequestFactory().get('/'), })
try: validate(TestInvalidTool, self.user_klass) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'label' attribute found for tool TestInvalidTool." ) TestInvalidTool.label = 'Test Invalid Tool' # Fail without 'view' member. self.failUnlessRaises( NotImplementedError, validate, TestInvalidTool, self.user_klass ) try: validate(TestInvalidTool, self.user_klass) except NotImplementedError, e: self.failUnlessEqual( e.message, "No 'view' method found for tool TestInvalidTool." ) class ObjectToolsInclusionTagsTestCase(TestCase): """ Testcase for object_tools.templatetags.object_tools_inclusion_tags. """ @classmethod def setUpClass(cls): from django.contrib.auth.models import User cls.user_klass = User
self.failUnlessRaises(ImproperlyConfigured, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except ImproperlyConfigured, e: self.failUnlessEqual( e.message, "No 'label' attribute found for tool TestInvalidTool.") TestInvalidTool.label = 'Test Invalid Tool' # Fail without 'view' member. self.failUnlessRaises(NotImplementedError, validate, TestInvalidTool, User) try: validate(TestInvalidTool, User) except NotImplementedError, e: self.failUnlessEqual( e.message, "No 'view' method found for tool TestInvalidTool.") class ObjectToolsInclusionTagsTestCase(TestCase): """ Testcase for object_tools.templatetags.object_tools_inclusion_tags. """ def setUp(self): self.factory = RequestFactory() self.user = User.objects.create_user(username='******') def test_object_tools(self): autodiscover()