def test(): # Arrange users.create(db2.engine) # Act config = { 'STORES': [{ 'name': 'db1', }, { 'name': 'db2', 'url': db2.url, }], 'TASKS': [{ 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': ['users'], }] } with chdir(__file__): carry.run(config) # Assert count = db2.engine.execute(select([func.count() ]).select_from(users)).scalar() assert count == 0 assert exc.exceptions.size == 1 assert isinstance(exc.exceptions[0], exc.ConsumerError)
def test(): # Arrange users.create(db2.engine) # Act config = { 'STORES': [{ 'name': 'db1', }, { 'name': 'db2', 'url': db2.url, }], 'TASKS': [{ 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': ['users'], }] } with chdir(__file__): carry.run(config) # Assert count = db2.engine.execute(select([func.count() ]).select_from(users)).scalar() assert count == 4
def test(): # Arrange users.create(db1.engine) users2.create(db2.engine) db1.engine.execute(users.insert(), [{ 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }]) # Act config = { 'STORES': [{ 'name': 'db1', 'url': db1.url, }, { 'name': 'db2', 'url': db2.url, }], 'TASKS': [{ 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': [ carry.table('users2', header={ 'name': 'name2', 'id': 'id', 'fullname': 'fullname2', 'reg_time': 'reg_time2', 'unknown': 'unknown', }, source_name='users') ], }] } carry.run(config) # Assert count = db2.engine.execute(select([func.count() ]).select_from(users2)).scalar() assert count == 0 assert exc.exceptions.size == 1 assert isinstance(exc.exceptions[0], exc.NoSuchColumnsError)
def main(): if len(sys.argv) > 1: config_path = sys.argv[1] else: config_path = 'carfile.py' if not os.path.exists(config_path): print("Can't find the config file {}".format(config_path)) else: carry.run(config_path)
def test(): # Arrange users.create(db1.engine) users.create(db2.engine) db1.engine.execute( users.insert(), [ {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()} ] ) db2.engine.execute( users.insert(), [ {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()}, {'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now()} ] ) # Act config = { 'STORES': [ { 'name': 'db1', 'url': db1.url, }, { 'name': 'db2', 'url': db2.url, } ], 'TASKS': [ { 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': [ 'UseRs', ], } ] } with chdir(__file__): carry.run(config) # Assert count = db2.engine.execute(select([func.count()]).select_from(users)).scalar() assert count == 3
def test(): # Arrange users.create(db1.engine) users.create(db2.engine) db1.engine.execute(users.insert(), [{ 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }]) # Act def Assert(): inspector = reflection.Inspector.from_engine(db1.engine) assert 'users_view' in inspector.get_view_names() config = { 'STORES': [{ 'name': 'db1', 'url': db1.url, 'create_view': True, }, { 'name': 'db2', 'url': db2.url, }], 'TASKS': [{ 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': ['users_view', carry.py(Assert, dependency=['users_view'])], }] } with chdir(__file__): carry.run(config) # Teardown db2.engine.execute('DROP TABLE users_view')
def test(): # Arrange users.create(db1.engine) db1.engine.execute(users.insert(), [{ 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }]) # Act config = { 'STORES': [{ 'name': 'db1', 'url': db1.url, }, { 'name': 'db2', }], 'TASKS': [{ 'from': [{ 'name': 'db1' }], 'to': { 'name': 'db2', }, 'orders': ['users'], }] } with chdir(__file__): carry.run(config) # Assert with chdir(__file__): csv_dir = os.path.join('.', 'db2') csv_file = os.path.join(csv_dir, 'users.csv') with open(csv_file, 'rb') as fo: assert fo.read().decode('utf-8').count('\n') == 4 os.remove(csv_file) os.rmdir(csv_dir)
def run_migration(migration_name): migration_objs = get_migration_objects() migration_obj = migration_objs.get(migration_name) carry.run(migration_obj.get_migration_config())
def test(drop123): # Arrange users.create(db1.engine) addresses.create(db2.engine) db1.engine.execute(users.insert(), [{ 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }, { 'name': 'wendy', 'fullname': 'Wendy Williams', 'reg_time': datetime.datetime.now() }]) db2.engine.execute(addresses.insert(), [{ 'user_id': 1, 'email_address': '*****@*****.**' }, { 'user_id': 2, 'email_address': '*****@*****.**' }]) # Act config = { 'STORES': [{ 'name': 'db1', 'url': db1.url, }, { 'name': 'db2', 'url': db2.url, }, { 'name': 'db3', 'url': db3.url, }], 'TASKS': [{ 'from': [ { 'name': 'db1' }, { 'name': 'db2' }, ], 'to': { 'name': 'db3', }, 'orders': [ 'users', 'addresses', ], }] } carry.run(config) # Assert count = db3.engine.execute(select([func.count() ]).select_from(users)).scalar() assert count == 3 count = db3.engine.execute(select([func.count() ]).select_from(addresses)).scalar() assert count == 2
STORES = [{ 'name': '', 'url': '', }, { 'name': '', 'url': '', }] TASKS = [{ 'from': [{ 'name': '' }], 'to': { 'name': '', }, 'orders': [] }] if __name__ == '__main__': import carry carry.run(__file__)