def test_custom_violation_error_message_clone(self): constraint = BaseConstraint( "base_name", violation_error_message="custom %(name)s message", ).clone() self.assertEqual( constraint.get_violation_error_message(), "custom base_name message", )
def test_deconstruction(self): constraint = BaseConstraint( "base_name", violation_error_message="custom %(name)s message", ) path, args, kwargs = constraint.deconstruct() self.assertEqual(path, "django.db.models.BaseConstraint") self.assertEqual(args, ()) self.assertEqual( kwargs, {"name": "base_name", "violation_error_message": "custom %(name)s message"}, )
def test_constraint_sql(self): c = BaseConstraint('name') msg = 'This method must be implemented by a subclass.' with self.assertRaisesMessage(NotImplementedError, msg): c.constraint_sql(None, None)
def test_remove_sql(self): c = BaseConstraint('name') msg = 'This method must be implemented by a subclass.' with self.assertRaisesMessage(NotImplementedError, msg): c.remove_sql(None, None)
def test_contains_expressions(self): c = BaseConstraint('name') self.assertIs(c.contains_expressions, False)
def test_create_sql(self): c = BaseConstraint("name") msg = "This method must be implemented by a subclass." with self.assertRaisesMessage(NotImplementedError, msg): c.create_sql(None, None)
def test_default_violation_error_message(self): c = BaseConstraint("name") self.assertEqual( c.get_violation_error_message(), "Constraint “name” is violated." )