Beispiel #1
0
 def test_gathers_original_method(self):
     self.bar_feature.decorate = ("save",)
     self.bar_feature._decorate_save = staticmethod(lambda method: lambda *args, **kwargs: None)
     self.model = install("bar", orm="foo")(self.model)
     self.childmodel = type("ChildModel", (self.model,), {})
     self.childmodel = install("bar", orm="foo")(self.childmodel)
     self.assertEqual(self.model.save.original(self.model()), "save")
     self.assertEqual(self.childmodel.save.original(self.childmodel()), "save")
Beispiel #2
0
 def test_gathers_original_method(self):
     self.bar_feature.decorate = ('save', )
     self.bar_feature._decorate_save = staticmethod(
         lambda method: lambda *args, **kwargs: None)
     self.model = install('bar', orm='foo')(self.model)
     self.childmodel = type('ChildModel', (self.model, ), {})
     self.childmodel = install('bar', orm='foo')(self.childmodel)
     self.assertEqual(self.model.save.original(self.model()), 'save')
     self.assertEqual(self.childmodel.save.original(self.childmodel()),
                      'save')
Beispiel #3
0
 def test_successful_uninstall(self):
     self.model = install("bar", orm="foo")(self.model)
     self.assertIn("foo", self.model.architect.__dict__)
     self.assertIn("bar", self.model.architect.__dict__)
     uninstall("bar")(self.model)
     self.assertNotIn("foo", self.model.architect.__dict__)
     self.assertNotIn("bar", self.model.architect.__dict__)
Beispiel #4
0
 def test_uninstall_restores_decorated_method(self):
     self.foo_feature.decorate = ("save",)
     self.foo_feature._decorate_save = staticmethod(lambda method: lambda *args, **kwargs: None)
     self.model = install("foo", orm="foo")(self.model)
     self.assertIsNone(self.model.save(self.model()))
     self.model = uninstall("foo")(self.model)
     self.assertEqual(self.model.save(self.model()), "save")
Beispiel #5
0
 def test_successful_uninstall(self):
     self.model = install('bar', orm='foo')(self.model)
     self.assertIn('foo', self.model.architect.__dict__)
     self.assertIn('bar', self.model.architect.__dict__)
     uninstall('bar')(self.model)
     self.assertNotIn('foo', self.model.architect.__dict__)
     self.assertNotIn('bar', self.model.architect.__dict__)
Beispiel #6
0
 def test_uninstall_restores_decorated_method(self):
     self.foo_feature.decorate = ('save', )
     self.foo_feature._decorate_save = staticmethod(
         lambda method: lambda *args, **kwargs: None)
     self.model = install('foo', orm='foo')(self.model)
     self.assertIsNone(self.model.save(self.model()))
     self.model = uninstall('foo')(self.model)
     self.assertEqual(self.model.save(self.model()), 'save')
Beispiel #7
0
 def _get_orm_table_with_partitioning(self):
     config = self.config.sql_settings.partition_config[0]
     partition = install(
         'partition', type='range', subtype=config.subtype,
         constraint=config.constraint, column=config.column, db=self.engine.url,
         orm='sqlalchemy', return_null=True
     )
     orm_table = self.get_sqlalchemy_orm_table()
     partition(orm_table)
     return orm_table
Beispiel #8
0
 def test_dynamically_changes_model_object(self):
     self.model = install('foo', orm='foo')(self.model)
     obj1 = self.model().architect.foo.model_obj
     self.assertEqual(
         self.model.__dict__['architect'].map[self.model]['features']
         ['foo'].model_obj, obj1)
     obj2 = self.model().architect.foo.model_obj
     self.assertEqual(
         self.model.__dict__['architect'].map[self.model]['features']
         ['foo'].model_obj, obj2)
Beispiel #9
0
 def _get_orm_table_with_partitioning(self):
     config = self.config.sql_settings.partition_config[0]
     partition = install(
         'partition', type='range', subtype=config.subtype,
         constraint=config.constraint, column=config.column, db=self.engine.url,
         orm='sqlalchemy', return_null=True
     )
     orm_table = self.get_sqlalchemy_orm_table()
     partition(orm_table)
     return orm_table
Beispiel #10
0
 def _install_partition(self):
     if self.config.sql_settings.partition_config:
         config = self.config.sql_settings.partition_config[0]
         partition = install(
             'partition', type='range', subtype=config.subtype,
             constraint=config.constraint, column=config.column, db=self.engine.url,
             orm='sqlalchemy', return_null=True
         )
         mapping = self.get_sqlalchemy_mapping()
         partition(mapping)
         mapping.architect.partition.get_partition().prepare()
Beispiel #11
0
 def _install_partition(self):
     if self.config.sql_settings.partition_config:
         config = self.config.sql_settings.partition_config[0]
         partition = install(
             'partition', type='range', subtype=config.subtype,
             constraint=config.constraint, column=config.column, db=self.engine.url,
             orm='sqlalchemy'
         )
         mapping = self.get_sqlalchemy_mapping()
         partition(mapping)
         mapping.architect.partition.get_partition().prepare()
Beispiel #12
0
for database in test_databases:
    dbname = database.capitalize()
    Base = declarative_base()
    locals()['{0}_engine'.format(database)] = engine = create_engine(
        databases[database])

    # Generation of entities for date range partitioning
    for item in ('day', 'week', 'month', 'year'):
        for return_null in (True, False):
            name = '{0}RangeDate{1}{2}'.format(
                dbname, item.capitalize(), 'ReturnNULL' if return_null else '')
            partition = install('partition',
                                type='range',
                                subtype='date',
                                constraint=item,
                                column='created',
                                db=engine.url,
                                return_null=return_null)

            locals()[name] = partition(
                type(
                    name, (Base, ), {
                        '__tablename__':
                        'test_rangedate{0}{1}'.format(
                            item, '_return_null' if return_null else ''),
                        'id':
                        Column(Integer, primary_key=True),
                        'name':
                        Column(String(length=255)),
                        'created':
Beispiel #13
0
    def test_raises_feature_uninstall_error(self):
        from architect.exceptions import FeatureUninstallError

        self.model = install("foo", orm="foo")(self.model)
        self.assertRaises(FeatureUninstallError, lambda: uninstall("bar")(self.model))
Beispiel #14
0
 def test_merges_several_features(self):
     self.model = install('bar', orm='foo')(self.model)
     self.model = uninstall('foo')(self.model)
     self.model = install('foo', orm='foo')(self.model)
     self.assertIn('foo', self.model.architect.__dict__)
     self.assertIn('bar', self.model.architect.__dict__)
Beispiel #15
0
 def test_register_hooks(self):
     self.foo_feature.register_hooks = staticmethod(
         lambda model: setattr(model, 'foo', 'foo'))
     self.model = install('foo', orm='foo')(self.model)
     self.assertEqual(self.model.foo, 'foo')
Beispiel #16
0
    def test_raises_method_autodecorate_error(self):
        from architect.exceptions import MethodAutoDecorateError as MADError

        self.foo_feature.decorate = ("save",)
        self.assertRaises(MADError, lambda: install("foo", orm="foo")(mock.Mock(spec=["__name__"])))
Beispiel #17
0
    def test_raises_orm_error(self):
        from architect.exceptions import ORMError

        self.assertRaises(ORMError, lambda: install("partition", orm="bar")(self.model))
Beispiel #18
0
 def test_dynamically_changes_model_object(self):
     self.model = install("foo", orm="foo")(self.model)
     obj1 = self.model().architect.foo.model_obj
     self.assertEqual(self.model.__dict__["architect"].map[self.model]["features"]["foo"].model_obj, obj1)
     obj2 = self.model().architect.foo.model_obj
     self.assertEqual(self.model.__dict__["architect"].map[self.model]["features"]["foo"].model_obj, obj2)
Beispiel #19
0
 def test_register_hooks(self):
     self.foo_feature.register_hooks = staticmethod(lambda model: setattr(model, "foo", "foo"))
     self.model = install("foo", orm="foo")(self.model)
     self.assertEqual(self.model.foo, "foo")
Beispiel #20
0
 def test_raises_orm_error(self):
     from architect.exceptions import ORMError
     self.assertRaises(ORMError, lambda: install('partition', orm='bar')
                       (self.model))
Beispiel #21
0
 def test_merges_several_features(self):
     self.model = install("bar", orm="foo")(self.model)
     self.model = uninstall("foo")(self.model)
     self.model = install("foo", orm="foo")(self.model)
     self.assertIn("foo", self.model.architect.__dict__)
     self.assertIn("bar", self.model.architect.__dict__)
Beispiel #22
0
from architect import install

databases = {
    'sqlite': 'sqlite://',
    'postgresql': 'postgresql+psycopg2://postgres@localhost/architect',
    'mysql': 'mysql+pymysql://root@localhost/architect'
}

dsn = databases[os.environ.get('DB')]
engine = create_engine(dsn)
Base = declarative_base()

# Generation of entities for date range partitioning
for item in ('day', 'week', 'month', 'year'):
    name = 'RangeDate{0}'.format(item.capitalize())
    partition = install('partition', type='range', subtype='date', constraint=item, column='created', db=engine.url)

    locals()[name] = partition(type(name, (Base,), {
        '__tablename__': 'test_rangedate{0}'.format(item),
        'id': Column(Integer, primary_key=True),
        'name': Column(String(length=255)),
        'created': Column(DateTime, nullable=True)
    }))

if os.environ.get('DB') == 'postgresql':
    # Generation of entities for integer range partitioning
    for item in ('2', '5'):
        name = 'RangeInteger{0}'.format(item)
        partition = install('partition', type='range', subtype='integer', constraint=item, column='num', db=engine.url)

        locals()[name] = partition(type(name, (Base,), {
Beispiel #23
0
 def test_raises_feature_install_error(self):
     from architect.exceptions import FeatureInstallError
     self.assertRaises(FeatureInstallError,
                       lambda: install('foobar', orm='foo')(self.model))
Beispiel #24
0
 def test_raises_method_autodecorate_error(self):
     from architect.exceptions import MethodAutoDecorateError as MADError
     self.foo_feature.decorate = ('save', )
     self.assertRaises(
         MADError, lambda: install('foo', orm='foo')
         (mock.Mock(spec=['__name__'])))
Beispiel #25
0
]

for database in test_databases:
    dbname = database.capitalize()
    connection = connectionForURI(databases[database])

    # Generation of entities for date range partitioning
    for item in ('day', 'week', 'month', 'year'):

        class sqlmeta(object):
            table = 'test_rangedate{0}'.format(item)

        name = '{0}RangeDate{1}'.format(dbname, item.capitalize())
        partition = install('partition',
                            type='range',
                            subtype='date',
                            constraint=item,
                            column='created')

        locals()[name] = partition(
            type(
                name, (SQLObject, ), {
                    'name': StringCol(),
                    'created': DateTimeCol(default=None),
                    'sqlmeta': sqlmeta,
                    '_connection': connection
                }))

        locals()[name].createTable(True)

    if database == 'pgsql':
Beispiel #26
0
    "test.models", (object,), {"__dict__": "", "__file__": "", "__loader__": "", "__spec__": ""}
)

from django.db import models
from django.core import management
from architect import install

# Generation of entities for date range partitioning
for item in ("day", "week", "month", "year"):

    class Meta(object):
        app_label = "test"
        db_table = "test_rangedate{0}".format(item)

    name = "RangeDate{0}".format(item.capitalize())
    partition = install("partition", type="range", subtype="date", constraint=item, column="created")

    locals()[name] = partition(
        type(
            name,
            (models.Model,),
            {
                "__module__": "test.models",
                "name": models.CharField(max_length=255),
                "created": models.DateTimeField(null=True),
                "Meta": Meta,
            },
        )
    )

if os.environ.get("DB") in ("pgsql", "postgresql"):