Exemplo n.º 1
0
    def test_can_find_by_id(self):
        doc = MongoMintDocument(db.connection, "mint_object_upsert")
        genius = "Spencer Reid"
        model1 = dict(name=genius)
        doc.upsert(model1)
        id = model1["_id"]
        assert(type(id) == ObjectId)

        # Triial case, already right type:
        model2 = doc.find_by_id(id)
        assert(model2["name"] == genius)

        # Validate can load by string
        # Convert to string first
        model3 = doc.find_by_id(str(id))
        assert(model3["name"] == genius)
        doc.collection.drop()
Exemplo n.º 2
0
    def test_can_do_object_upsert(self):
        doc = MongoMintDocument(db.connection, "mint_object_upsert")
        model1 = dict(name="John")
        assert("_id" not in model1)
        doc.upsert(model1)
        assert("_id" in model1)

        model1["name"] = "Jenniffer"

        doc.upsert(model1)

        # JCL todo wrap in method
        model2 = doc.collection.find_one({"_id" : model1["_id"]})
        assert(model2["_id"] == model1["_id"])
        assert(model2["name"] == "Jenniffer")

        doc.collection.drop()