示例#1
0
 async def test_multiple_motor_db_connections(self):
     app = Quart(__name__)
     db1 = Motor(app=app, uri=f"{self.client_uri}test1")
     db2 = Motor(app=app, uri=f"{self.client_uri}test2")
     await app.startup()
     assert isinstance(db1.db, AsyncIOMotorDatabase)
     assert isinstance(db2.db, AsyncIOMotorDatabase)
示例#2
0
    async def test_motor_doesnt_connect_by_default(self):
        app = Quart(__name__)
        mongo = Motor(app=app, uri=self.uri)
        await app.startup()

        with pytest.raises(CouldNotConnect):
            _wait_until_connected(mongo, timeout=0.2)
示例#3
0
 async def test_find_one_or_404_notfound(self):
     app = Quart(__name__)
     mongo = Motor(app=app, uri=self.uri)
     await app.startup()
     await mongo.db.things.delete_many({})
     with pytest.raises(NotFound):
         await mongo.db.things.find_one_or_404({"_id": "thing"})
示例#4
0
 async def test_find_one_or_404_found(self):
     app = Quart(__name__)
     mongo = Motor(app=app, uri=self.uri)
     await app.startup()
     await mongo.db.things.insert_one({"_id": "thing", "val": "foo"})
     thing = await mongo.db.things.find_one_or_404({"_id": "thing"})
     assert thing["val"] == "foo"
     await mongo.db.things.delete_many({})
示例#5
0
    async def test_motor_custom_document_class(self):
        class CustomDict(dict):
            pass

        app = Quart(__name__)
        mongo = Motor(app=app, uri=self.uri, document_class=CustomDict)
        await app.startup()
        things = await mongo.db.things.find_one()
        assert things is None

        await mongo.db.things.insert_one({"_id": "thing", "val": "foo"})
        things = await mongo.db.things.find_one()
        await mongo.db.things.delete_many({})
        assert type(things) == CustomDict
示例#6
0
 async def test_motor_no_database_name_in_uri(self):
     app = Quart(__name__)
     mongo = Motor(app=app, uri=self.client_uri)
     await app.startup()
     assert mongo.db is None
示例#7
0
 async def test_motor_database_failure(self):
     app = Quart(__name__)
     with pytest.raises(ValueError):
         mongo = Motor(app=app)
示例#8
0
 async def test_motor_database_success(self):
     app = Quart(__name__)
     mongo = Motor(app=app, uri=self.uri)
     await app.startup()
     assert isinstance(mongo.db, AsyncIOMotorDatabase)
示例#9
0
 async def test_motor_invalid_uri(self):
     app = Quart(__name__)
     with pytest.raises(InvalidURI):
         mongo = Motor(app=app, uri="http://localhost:27017/test")
示例#10
0
 async def test__motor_client_connection(self):
     app = Quart(__name__)
     mongo = Motor(app=app, uri=self.client_uri)
     assert isinstance(mongo, Motor)
示例#11
0
async def main():
    app = Quart(__name__)
    db = Motor(app=app, uri="mongodb://localhost:27017/test").db
    print(await db['things'].find_one({"_id": "59674459"}))