示例#1
0
 def test_set_local_key_to_id_is_saved(self):
     post = LinkedPost(title='P1', content='P2')
     author = LinkedAuthor(name='A1')
     post.save()
     author.save()
     post.author_id = author.id
     post.save()
     collection = Connection.get_collection(LinkedPost)
     for item in collection.find({}):
         self.assertEqual(item['authorId'], ObjectId(author.id))
示例#2
0
 def test_set_local_key_to_unset_is_saved(self):
     post = LinkedPost(title='P1', content='P2')
     author = LinkedAuthor(name='A1')
     post.author = author
     post.save()
     post.author_id = None
     post.save()
     collection = Connection.get_collection(LinkedPost)
     for item in collection.find({}):
         self.assertNotIn('authorId', item)
示例#3
0
 def test_many_1_unlink_unset_is_saved(self):
     author = LinkedAuthor(name='A')
     post = LinkedPost(title='T', content='C')
     post.author = author
     post.save()
     post.author_id = None
     post.save()
     self.assertEqual(author.is_new, False)
     self.assertEqual(author.is_modified, False)
     self.assertEqual(author.modified_fields, ())
     self.assertEqual(post.is_new, False)
     self.assertEqual(post.is_modified, False)
     self.assertEqual(post.modified_fields, ())
     collection = Connection.get_collection(LinkedPost)
     for item in collection.find({}):
         self.assertNotIn('authorId', item)