def list_command(test, output_json, limit): # Should require login if there are publicly visible records pc = PilotClient() if not pc.is_logged_in(): click.echo('You are not logged in.') return search_authorizer = pc.get_authorizers()['search.api.globus.org'] sc = globus_sdk.SearchClient(authorizer=search_authorizer) # TO DO: iterate instead of upping limit search_results = sc.search(index_id=pc.get_index(test), q='*', limit=limit) if output_json: click.echo(json.dumps(search_results.data, indent=4)) return fmt = '{:21.20}{:11.10}{:10.9}{:7.6}{:7.6}{:7.6}{}' columns = [ ('Title', lambda r: r['dc']['titles'][0]['title']), ('Data', lambda r: r['ncipilot']['data_type']), ('Dataframe', lambda r: r['ncipilot']['dataframe_type']), ('Rows', lambda r: str(r['field_metadata']['numrows'])), ('Cols', lambda r: str(r['field_metadata']['numcols'])), ('Size', get_size), ('Filename', get_identifier), ] # Build row data rows = [] for result in search_results['gmeta']: content = result['content'][0] if content.get('testing'): content = content['testing'] row = [] for _, function in columns: try: row.append(function(content)) except Exception: row.append('') # raise rows.append(row) formatted_rows = [fmt.format(*r) for r in rows] header = fmt.format(*[c[0] for c in columns]) output = '{}\n{}'.format(header, '\n'.join(formatted_rows)) click.echo(output)
def test_get_test_index(): pc = PilotClient() index = pc.get_index(test=True) assert index == pc.SEARCH_INDEX_TEST
def test_get_index(): pc = PilotClient() assert pc.get_index() == pc.SEARCH_INDEX
def test_get_index(mock_projects): pc = PilotClient() pc.project.current = 'foo-project' assert pc.get_index() == 'foo-search-index' assert pc.get_index(project='foo-project-test') == 'foo-test-search-index'
def test_invalid_project_with_explicit_name(mock_projects): pc = PilotClient() with pytest.raises(PilotInvalidProject): pc.get_index('does-not-exist')
def test_invalid_project(mock_projects): pc = PilotClient() with pytest.raises(PilotInvalidProject): pc.get_index()