Exemplo n.º 1
0
 def test_the_data_is_persistent_orm_model(self):
     configure_orm({
         'db_config': db_config,
         'modules': ['tests.testapp', 'tests.testapp2'],
     })
     # every model declared has the same db_manager
     self.assertTrue(orm_app.db_manager is Book.objects.db_manager)
Exemplo n.º 2
0
    def test_ormconfigure_no_db_config(self):
        with self.assertRaises(ModuleError) as exc:
            configure_orm({
                # 'db_config': db_config,
                'modules': ['tests.testapp', 'tests.testapp2'],
            })

        self.assertTrue(
            'Imposible to configure without database' in exc.exception.args[0])
Exemplo n.º 3
0
def orm_setup(request, event_loop):
    config_file = os.path.join(os.getcwd(), "tests", "asyncorm.ini")
    orm = configure_orm(config_file, loop=event_loop)

    event_loop.run_until_complete(orm.db_backend.transaction_start())
    yield orm
    event_loop.run_until_complete(orm.db_backend.transaction_start())
Exemplo n.º 4
0
    def __init__(self, methodName="runTest", loop=None):
        config_file = os.path.join(os.getcwd(), "tests", "asyncorm.ini")
        self.orm_app = configure_orm(config_file)
        self.loop = loop or asyncio.get_event_loop()
        self._function_cache = {}

        super(AsyncormTestCase, self).__init__(methodName=methodName)
Exemplo n.º 5
0
    def test_ormconfigure_no_models(self):
        orm = configure_orm({'db_config': db_config, 'modules': None})

        with self.assertRaises(ModuleError) as exc:
            orm.get_model('here.there.what')

        self.assertTrue('There are no modules declared in the orm' ==
                        exc.exception.args[0])
Exemplo n.º 6
0
    def test_get_model_not_correct_format(self):
        orm = configure_orm({
            'db_config': db_config,
            'modules': ['tests.testapp', 'tests.testapp2'],
        })

        with self.assertRaises(ModelError) as exc:
            orm.get_model('here.there.what')

        self.assertTrue('The string declared should be in format ' in
                        exc.exception.args[0])
Exemplo n.º 7
0
import asyncio
import unittest
import os

from .testapp.models import Author, Book

from asyncorm.application import configure_orm

config_file = os.path.join(os.getcwd(), 'tests', 'asyncorm.ini')
orm_app = configure_orm(config_file)

loop = orm_app.loop

drop_tables = [
    'Publisher', 'Author', 'library', 'Organization', 'Developer', 'Client',
    'Developer_Organization', 'Author_Publisher', 'Appointment', 'Reader'
]


async def clear_table(table_name):
    query = orm_app.db_manager.construct_query([{
        'action': 'db__drop_table',
        'table_name': table_name
    }])
    await orm_app.db_manager.request(query)


for table_name in drop_tables:
    task = loop.create_task(clear_table(table_name))
    loop.run_until_complete(asyncio.gather(task))
Exemplo n.º 8
0
import asyncio
import unittest

from .testapp.models import Author, Book

from asyncorm.application import configure_orm

db_config = {
    'database': 'asyncorm',
    'host': 'localhost',
    'user': '******',
    'password': '******',
}
orm_app = configure_orm({
    'db_config': db_config,
    'modules': ['tests.testapp', 'tests.testapp2'],
})

loop = orm_app.loop

drop_tables = [
    'Publisher',
    'Author',
    'library',
    'Organization',
    'Developer',
    'Client',
    'Developer_Organization',
    'Author_Publisher',
]