コード例 #1
0
    def test_configuration(self):
        with self.assertRaises(ModuleError) as exc:
            get_model('Tato')
        self.assertTrue(
            'The model does not exists' in exc.exception.args[0]
        )

        # the orm is configure on the start of tests, but the data is kept
        self.assertEqual(
            orm_app.db_manager.conn_data['password'],
            db_config['password']
        )
        self.assertEqual(
            orm_app.db_manager.conn_data['database'],
            db_config['database']
        )

        # every model declared has the same db_manager
        self.assertTrue(orm_app.db_manager is Book.objects.db_manager)
コード例 #2
0
from asyncorm.application import get_model
from asyncorm.exceptions import FieldError, ModelError, SerializerError
from asyncorm.serializers import ModelSerializer, SerializerMethod

from .testapp.models import Book, Author
from .testapp.serializer import BookSerializer, BookSerializer2
from .testapp2.models import Developer, Client, Organization
from .test_helper import AioTestCase

# You can get the book by model_name
Book2 = get_model('Book')
# And get the author by module.model_name
Author2 = get_model('testapp.Author')


class ModelTests(AioTestCase):

    def test_class__init__(self):
        # classmethods tests
        # no matter how you import them they are the same object
        self.assertTrue(Author is Author2)
        self.assertTrue(Book is Book2)

        self.assertEqual(Book().cls_tablename(), 'library')
        self.assertEqual(Author().cls_tablename(), 'Author')

    def test_get_fields(self):
        fields = Book.get_fields()

        self.assertEqual(len(fields), 7)
        self.assertEqual(
コード例 #3
0
ファイル: module_tests.py プロジェクト: strahe/asyncorm
    def test_get_model_model_does_not_exist(self):
        with self.assertRaises(ModuleError) as exc:
            get_model('Tato')

        self.assertTrue('The model does not exists' in exc.exception.args[0])
コード例 #4
0
ファイル: module_tests.py プロジェクト: strahe/asyncorm
from asyncorm.application import get_model, orm_app, configure_orm
from asyncorm.exceptions import ModelError, ModuleError

from .test_helper import AioTestCase

Book = get_model('Book')

db_config = {
    'database': 'asyncorm',
    'host': 'localhost',
    'user': '******',
    'password': '******',
}


class ModuleTests(AioTestCase):
    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])

    def test_ormconfigure_no_db_config(self):
        with self.assertRaises(ModuleError) as exc:
            configure_orm({
                # 'db_config': db_config,
                'modules': ['tests.testapp', 'tests.testapp2'],
            })