Exemple #1
0
 def test_connect_to_replica_set_with_invalid_replicaset_name(self):
     try:
         connect('test', host="localhost:27017,localhost:27018", replicaSet=0, port=27017, io_loop=self.io_loop)
     except ConnectionError:
         exc_info = sys.exc_info()[1]
         expect(str(exc_info)).to_include('the replicaSet keyword parameter is required')
     else:
         assert False, "Should not have gotten this far"
Exemple #2
0
 def test_connect_to_replica_set_with_invalid_replicaset_name(self):
     try:
         connect('test',
                 host="localhost:27017,localhost:27018",
                 replicaSet=0,
                 port=27017,
                 io_loop=self.io_loop)
     except ConnectionError:
         exc_info = sys.exc_info()[1]
         expect(str(exc_info)).to_include(
             'the replicaSet keyword parameter is required')
     else:
         assert False, "Should not have gotten this far"
Exemple #3
0
    async def test_connect_to_replica_set(self):
        db = connect('test', host="localhost:27017,localhost:27018",
                     replicaSet="rs0", port=27018, io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)
Exemple #4
0
    async def test_can_connect_to_a_database(self):
        db = connect('test', host="localhost", port=27017,
                     io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)
Exemple #5
0
 def setUp(self, auto_connect=True):
     self.io_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     if auto_connect:
         self.db = connect(
             "test", host="localhost", port=27017, io_loop=self.io_loop
         )
Exemple #6
0
    def test_database_returns_collection_when_asked_for_a_name(self):
        db = connect("test",
                     host="localhost",
                     port=27017,
                     io_loop=self.io_loop)

        expect(db.something).to_be_instance_of(
            motor.motor_asyncio.AsyncIOMotorCollection)
Exemple #7
0
 def setUp(self, auto_connect=True):
     # super(AsyncTestCase, self).setUp(auto_connect=auto_connect)
     super().setUp(auto_connect=False)
     if auto_connect:
         self.db = aiomotorengine.connect(
             "test", host="localhost", port=27017, io_loop=self.io_loop
         )
         mongoengine.connect("test", host="localhost", port=27017)
Exemple #8
0
 def setUp(self, auto_connect=True):
     self.io_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     if auto_connect:
         self.db = connect("test",
                           host="localhost",
                           port=27017,
                           io_loop=self.io_loop)
Exemple #9
0
    async def test_database_ping(self):
        db = connect("test", host="localhost", port=27017,
                     io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)

        disconnect()
Exemple #10
0
 def setUp(self, auto_connect=True):
     # super(AsyncTestCase, self).setUp(auto_connect=auto_connect)
     super().setUp(auto_connect=False)
     if auto_connect:
         self.db = aiomotorengine.connect("test",
                                          host="localhost",
                                          port=27017,
                                          io_loop=self.io_loop)
         mongoengine.connect("test", host="localhost", port=27017)
Exemple #11
0
    async def test_can_connect_to_a_database(self):
        db = connect('test',
                     host="localhost",
                     port=27017,
                     io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)
Exemple #12
0
    async def test_connect_to_replica_set(self):
        db = connect('test',
                     host="localhost:27017,localhost:27018",
                     replicaSet="rs0",
                     port=27018,
                     io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)
Exemple #13
0
    async def test_database_ping(self):
        db = connect("test",
                     host="localhost",
                     port=27017,
                     io_loop=self.io_loop)

        res = await db.ping()
        ping_result = res['ok']
        expect(ping_result).to_equal(1.0)

        disconnect()
import asyncio

from aiohttp import web
from aiomotorengine import connect

from core.methods import reload_web_hook
from core.processing import process_response
from settings import APPLICATION_SECRET, DB_NAME, DB_HOST
from utils.logic import get_chat, get_message

routes = web.RouteTableDef()
loop = asyncio.get_event_loop()
connect(DB_NAME, host=DB_HOST, io_loop=loop)


@routes.post(f'/{APPLICATION_SECRET}')
async def handler(request):
    request_json = await request.json()
    return await process_response(
        chat=await get_chat(request_json),
        message=await get_message(request_json)
    )

app = web.Application()
app.add_routes(routes)


if __name__ == '__main__':
    asyncio.run(reload_web_hook())
    web.run_app(app)
Exemple #15
0
    def test_database_returns_collection_when_asked_for_a_name(self):
        db = connect("test", host="localhost", port=27017, io_loop=self.io_loop)

        expect(db.something).to_be_instance_of(
            motor.motor_asyncio.AsyncIOMotorCollection
        )