Exemple #1
0
 def test_validate_validates_one_field_inside_nested_if_required(self):
     author = Author(name='A', articles=[{}, {}])
     with self.assertRaises(ValidationException) as context:
         author.validate(all_fields=False)
     exception = context.exception
     self.assertEqual(len(exception.keypath_messages), 1)
     self.assertEqual(exception.keypath_messages['articles.0.title'],
                      "value required")
Exemple #2
0
 def test_validate_validates_with_class_config_by_default(self):
     author = Author(name='A', articles=[{}, {}])
     with self.assertRaises(ValidationException) as context:
         author.validate()
     exception = context.exception
     self.assertEqual(len(exception.keypath_messages), 2)
     self.assertEqual(exception.keypath_messages['articles.0.title'],
                      "value required")
     self.assertEqual(exception.keypath_messages['articles.0.content'],
                      "value required")
 def test_jobject_is_not_modified_if_nested_is_mutated(self):
     author = Author(name='Kia',
                     articles=[{
                         'title': 'Long',
                         'content': 'Khng Ti Ua E Sim Lai'
                     }])
     author._mark_not_new()
     author.articles[0]._mark_not_new()
     author.articles[0].title = 'M Guan Kong Tsai Huê'
     self.assertEqual(author.is_modified, False)
     self.assertEqual(author.modified_fields, ())
     self.assertEqual(author.articles[0].is_modified, True)
     self.assertEqual(author.articles[0].modified_fields, ('title', ))
Exemple #4
0
 def test_initialize_accepts_nested_keypaths_for_instances(self):
     author = Author(name='Kieng')
     article = Article(**{'title': 'E Sai',
                          'content': 'Tsê Tioh Si Kim Sieng Ua Ê Tsuê Ai',
                          'author': author,
                          'author.name': 'abc.def'})
     self.assertEqual(article.author.name, 'abc.def')
Exemple #5
0
 def test_set_accepts_nested_keypaths_for_instances_with_list_indexing(
         self):
     author = Author(name='Kieng')
     article = Article(
         **{
             'title': 'E Sai',
             'content': 'Tsê Tioh Si Kim Sieng Ua Ê Tsuê Ai',
             'author': author
         })
     article.set(**{'author[name]': 'abca.def'})
     self.assertEqual(article.author.name, 'abca.def')
Exemple #6
0
 def test_validate_validates_linked_objects_anyway(self):
     author = Author(name='Tsit Tiu',
                     articles=[{
                         'title': 'Khua Tioh Sê Kai',
                         'content': 'Ai Gua Tsuê'
                     }, {
                         'title': 'Thên Ha Si Lan Ê',
                         'content': 'Tsiu Ho Lang Tsai'
                     }])
     author._mark_not_new()
     author.articles[0]._mark_not_new()
     author.articles[1]._mark_not_new()
     author.articles[0].content = None
     with self.assertRaises(ValidationException) as context:
         author.validate()
     exception = context.exception
     self.assertEqual(len(exception.keypath_messages), 1)
     self.assertEqual(exception.keypath_messages['articles.0.content'],
                      "value required")
Exemple #7
0
 def test_set_accepts_nested_keypaths_for_instances_in_lists(self):
     article = Article(title='T', content='C')
     author = Author(**{'name': 'Kieng', 'articles': [article]})
     author.set(**{'articles.0.title': 'QQQQQ'})
     self.assertEqual(author.articles[0].title, 'QQQQQ')
Exemple #8
0
 def test_set_accepts_object(self):
     author = Author(name='Kieng')
     article = Article(title='E Sai',
                       content='Tsê Tioh Si Kim Sieng Ua Ê Tsuê Ai')
     article.set(author=author)
     self.assertEqual(author, article.author)
Exemple #9
0
 def test_set_accepts_object_list(self):
     article = Article(title='Khi Sit', content='Ua Sim Lai Tsa Tiu E Tsai')
     author = Author(name='Hun')
     author.set(articles=[article])
     self.assertEqual(author.articles, [article])