コード例 #1
0
 def test_str_raises_if_value_is_not_string(self):
     article = SimpleArticle(title=66)
     with self.assertRaises(ValidationException) as context:
         article.validate()
     self.assertEqual(len(context.exception.keypath_messages), 1)
     self.assertEqual(context.exception.keypath_messages['title'],
                      "value is not str")
コード例 #2
0
 def test_validate_by_default_validates_one_field(self):
     article = SimpleArticle()
     with self.assertRaises(ValidationException) as context:
         article.validate()
     exception = context.exception
     self.assertEqual(len(exception.keypath_messages), 1)
     self.assertEqual(exception.keypath_messages['title'], "value required")
コード例 #3
0
 def test_validate_validates_all_fields_if_option_is_passed(self):
     article = SimpleArticle()
     with self.assertRaises(ValidationException) as context:
         article.validate(all_fields=True)
     exception = context.exception
     self.assertEqual(len(exception.keypath_messages), 2)
     self.assertEqual(exception.keypath_messages['title'], "value required")
     self.assertEqual(exception.keypath_messages['content'],
                      "value required")
コード例 #4
0
 def test_validate_only_validate_modified_fields_for_non_new_object(self):
     article = SimpleArticle(title='my', content='side')
     article._mark_not_new()
     article.content = None
     article._modified_fields = []
     article.validate(all_fields=True)
コード例 #5
0
 def test_validate_does_not_raise_and_returns_self_for_valid_object(self):
     article = SimpleArticle(title='U Ia Huê', content='Bê Tshua Bo')
     self.assertEqual(article, article.validate())