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)
def test_alter_local_key_is_saved(self): post = LinkedPost(title='P1', content='P2') a1 = LinkedAuthor(name='A1') post.author = a1 post.save() a2 = LinkedAuthor(name='A2') post.author_id = a2.id post.save() collection = Connection.get_collection(LinkedPost) for item in collection.find({}): self.assertEqual(item['authorId'], ObjectId(a2.id))
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()