Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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