Ejemplo n.º 1
0
    def test_create_tables(self):
        ws = Workspace(self.client, self.db_client, self.config)

        ws.create_tables()

        self.db_client.assert_has_calls([
            mock.call.write(
                workspace.CREATE_PROJECTS_TABLE.format(
                    table_name=workspace.PROJECTS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_PROJECT_MEMBERSHIPS_TABLE.format(
                    table_name=workspace.PROJECT_MEMBERSHIPS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_USERS_TABLE.format(
                    table_name=workspace.USERS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_FOLLOWERS_TABLE.format(
                    table_name=workspace.FOLLOWERS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELDS_TABLE.format(
                    table_name=workspace.CUSTOM_FIELDS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELD_ENUM_VALUES_TABLE.format(
                    table_name=workspace.CUSTOM_FIELD_ENUM_VALUES_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELD_VALUES_TABLE.format(
                    table_name=workspace.CUSTOM_FIELD_VALUES_TABLE_NAME)),
        ],
                                        any_order=True)
Ejemplo n.º 2
0
def main():
    args = arg_parser().parse_args()

    client = build_asana_client(args)

    db_client = None
    if args.odbc_string:
        print("Connecting to database.")
        db_client = pyodbc.connect(args.odbc_string)
        db_client.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
        db_client.setencoding(encoding='utf-8')

    db_wrapper = DatabaseWrapper(db_client, dump_sql=args.dump_sql, dry=args.dry)

    workspace = Workspace(client, db_wrapper, args)
    project = Project(
            client, db_wrapper, workspace, args, default_fields(workspace))

    if args.command == 'create':
        project.create_table()
        workspace.create_tables()
    elif args.command == 'export':
        project.export()
    elif args.command == 'synchronize':
        project.synchronize()

    if not args.dry:
        db_client.commit()

    if args.dump_perf:
        print("API Requests: {}".format(client.num_requests))
        print("DB Commands: reads = {}, writes = {}, executed = {}".format(
            db_wrapper.num_reads, db_wrapper.num_writes, db_wrapper.num_commands_executed))