def test_duplicate_model_class_name(): """Test that duplicate model class names are supported by SQLClient model registry. """ # Since we're going to shadow the same model name, we need an alias to it # for testing. global DupAModel _DupAModel = DupAModel class DupAModel(DupModel): __tablename__ = 'test_dup_dup_a' id = sa.Column(sa.types.Integer(), primary_key=True) db = SQLClient(model_class=DupModel) db.create_all() assert 'tests.fixtures.DupAModel' in db.models assert db.models['tests.fixtures.DupAModel'] is _DupAModel assert 'tests.test_client.DupAModel' in db.models assert db.models['tests.test_client.DupAModel'] is DupAModel model1 = DupAModel() assert db.save(model1) is model1 model2 = _DupAModel() assert db.save(model2) is model2 del DupAModel
def test_duplicate_model_class_name(): """Test that duplicate model class names are supported by SQLClient model registry. """ # Since we're going to shadow the same model name, we need an alias to it # for testing. global DupAModel _DupAModel = DupAModel class DupAModel(DupModel): __tablename__ = 'test_dup_dup_a' id = sa.Column(sa.types.Integer(), primary_key=True) db = SQLClient(model_class=DupModel) db.create_all() assert 'tests.fixtures.DupAModel' in db.models assert db.models['tests.fixtures.DupAModel'] is _DupAModel assert 'tests.test_client.DupAModel' in db.models assert db.models['tests.test_client.DupAModel'] is DupAModel model1 = DupAModel() assert db.save(model1) is model1 model2 = _DupAModel() assert db.save(model2) is model2 del DupAModel
def db(): config = {'SQL_DATABASE_URI': 'sqlite://', 'SQL_ECHO': False} _db = SQLClient(config, model_class=Model) _db.create_all() yield _db _db.shutdown() _db.drop_all()
def db(): config = {"SQL_DATABASE_URI": "sqlite://", "SQL_ECHO": False} _db = SQLClient(config, model_class=Model) _db.create_all() yield _db _db.disconnect() _db.drop_all()
def filedb(tmpdir): dbpath = str(tmpdir.mkdir(random_alpha()).join('file.db')) config = {'SQL_DATABASE_URI': 'sqlite:///{0}'.format(dbpath)} _filedb = SQLClient(config, model_class=Model) _filedb.create_all() yield _filedb _filedb.shutdown() os.remove(dbpath)
def filedb(tmpdir): dbpath = str(tmpdir.mkdir(random_alpha()).join("file.db")) config = {"SQL_DATABASE_URI": f"sqlite:///{dbpath}"} _filedb = SQLClient(config, model_class=Model) _filedb.create_all() yield _filedb _filedb.disconnect() os.remove(dbpath)
def db(): config = { 'SQL_DATABASE_URI': 'sqlite://', 'SQL_ECHO': False } _db = SQLClient(config, model_class=Model) _db.create_all() yield _db _db.disconnect() _db.drop_all()
def filedb(tmpdir): dbpath = str(tmpdir.mkdir(random_alpha()).join('file.db')) config = { 'SQL_DATABASE_URI': 'sqlite:///{0}'.format(dbpath) } _filedb = SQLClient(config, model_class=Model) _filedb.create_all() yield _filedb _filedb.disconnect() os.remove(dbpath)
'SQL_ISOLATION_LEVEL': 'SERIALIZABLE', 'SQL_ECHO': True, 'SQL_ECHO_POOL': False, 'SQL_CONVERT_UNICODE': True, 'SQL_POOL_SIZE': 5, 'SQL_POOL_TIMEOUT': 30, 'SQL_POOL_RECYCLE': 3600, 'SQL_MAX_OVERFLOW': 10, 'SQL_AUTOCOMMIT': False, 'SQL_AUTOFLUSH': True, 'SQL_EXPIRE_ON_COMMIT': True } db = SQLClient(config, model_class=Model) db.create_all() data = {'name': 'Jenny', 'email': '*****@*****.**', 'phone': '555-867-5309'} user = db.User.save(data) assert user.to_dict() == { 'id': 1, 'name': 'Jenny', 'email': '*****@*****.**', 'phone': '5558675309' } assert user is db.User.get(data.id) assert user is db.User.find_one(id=user.id) assert user is db.User.find(User.id == user.id)[0]