Skip to content

Commit

Permalink
add a test for what marc has been trying to do
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dirolf committed Mar 17, 2009
1 parent 7ddbdc5 commit 9eebac4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,29 @@ def test_auto_ref_and_deref(self):
self.assertEqual(db.test.c.find_one()["another test"], b)
self.assertEqual(db.test.c.find_one(), c)

# some stuff the user marc wanted to be able to do, make sure it works
def test_marc(self):
db = self.connection.pymongo_test
db.add_son_manipulator(AutoReference(db))
db.add_son_manipulator(NamespaceInjector())

db.drop_collection("users")
db.drop_collection("messages")

message_1 = {"title": "foo"}
db.messages.save(message_1)
message_2 = {"title": "bar"}
db.messages.save(message_2)

user = {"name": "marc",
"messages": [message_1, message_2]}
db.users.save(user)

message = db.messages.find_one()
db.messages.update(message, {"title": "buzz"})

self.assertEqual("buzz", db.users.find_one()["messages"][0]["title"])
self.assertEqual("bar", db.users.find_one()["messages"][1]["title"])

if __name__ == "__main__":
unittest.main()

0 comments on commit 9eebac4

Please sign in to comment.