Beispiel #1
0
 def test_local_key_from_param_is_saved(self):
     a1 = LinkedAuthor(name='A1')
     a1.save()
     post = LinkedPost(title='P1', content='P2', authorId=a1.id)
     post.save()
     collection = Connection.get_collection(LinkedPost)
     for item in collection.find({}):
         self.assertEqual(item['authorId'], ObjectId(a1.id))
Beispiel #2
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))
Beispiel #3
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)
Beispiel #4
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)
 def test_encode_new_object_correctly_with_existing_objects_1_many(self):
     author = LinkedAuthor(name='A')
     post = LinkedPost(title='P', content='P')
     author.save()
     post.author = author
     post.save()