示例#1
0
    def test_workflow_url_to_id(self):
        result_map = {
            'www.google.com': False,
            'https://app.workbenchdata.com/workflows/4370/': 4370,
            'https://staging.workbenchdata.com/workflows/18': 18,
            'not a url': False,
            'https://staging.workbenchdata.com/workflows/': False
        }

        for url, expected_result in result_map.items():
            if not expected_result:
                with self.assertRaises(Exception):
                    workflow_url_to_id(url)
            else:
                self.assertEqual(workflow_url_to_id(url), expected_result)
示例#2
0
    def render(params, table, *, fetch_result, **kwargs):
        if not fetch_result:
            return ProcessResult(table)

        if fetch_result.status == 'error':
            return ProcessResult(table, error=fetch_result.error)

        if fetch_result.dataframe.empty:
            return ProcessResult(table,
                                 error='The workflow you chose is empty')

        type = params.get_param_menu_idx('type')
        url = params.get_param_string('url').strip()
        source_columns = params.get_param_checkbox('source_columns')

        try:
            right_id = str(utils.workflow_url_to_id(url))
            concat_table = pd.concat([table, fetch_result.dataframe],
                                     keys=['Current', right_id],
                                     join=_join_type_map[type], sort=False)
        except Exception as err:  # TODO specify which errors
            return ProcessResult(table, error=str(err.args[0]))

        # Default, only includes columns of left table
        if type == 0:
            concat_table = concat_table[table.columns]

        if source_columns:
            # Allow duplicates set to True because sanitize handles name
            # collisions
            source_series = concat_table.reset_index()['level_0']
            concat_table.insert(0, _source_column_name,
                                source_series.values, allow_duplicates=True)

        return ProcessResult(concat_table)
示例#3
0
def render(table, params, *, fetch_result, **kwargs):
    if not fetch_result:
        return table

    if fetch_result.status == 'error':
        return fetch_result.error

    if fetch_result.dataframe.empty:
        return 'The workflow you chose is empty'

    columns_from: str = params['columns_from']
    url: str = params['url'].strip()
    add_source_column: bool = params['add_source_column']

    try:
        right_id = str(utils.workflow_url_to_id(url))
        concat_table = pd.concat([table, fetch_result.dataframe],
                                 keys=['Current', right_id],
                                 join=_JoinTypes[columns_from], sort=False)
    except Exception as err:  # TODO specify which errors
        return str(err.args[0])

    # Default, only includes columns of left table
    if columns_from == 'input':
        concat_table = concat_table[table.columns]

    if add_source_column:
        # Allow duplicates set to True because sanitize handles name
        # collisions
        source_series = concat_table.index.get_level_values(0)
        concat_table.insert(0, _SourceColumnName, source_series.values,
                            allow_duplicates=True)
    concat_table.reset_index(drop=True, inplace=True)

    return concat_table
示例#4
0
async def fetch(params, *, workflow_id: int,
                get_workflow_owner: Callable[[], Awaitable[User]],
                **kwargs) -> ProcessResult:
    url: str = params['url']

    if not url.strip():
        return None

    try:
        other_workflow_id = utils.workflow_url_to_id(url)
    except ValueError as err:
        return ProcessResult(error=str(err))

    return await utils.fetch_external_workflow(workflow_id, await
                                               get_workflow_owner(),
                                               other_workflow_id)