# Path: tests/fixture_data.py
# EXECUTION_DATA = {
#     'counter': random.randint(1, 100),
#     'ctime': '2017-02-08T11:09:16.120102Z',
#     'id': execution_id,
#     'project': PROJECT_DATA,
#     'commit': {
#         'repository': 666,
#         'identifier': '000',
#         'ref': 'master',
#         'commit_time': '2017-02-15T08:46:58Z',
#         'url': 'https://app.valohai.com/api/v0/commits/7/'
#     },
#     'task': None,
#     'duration': 777,
#     'status': 'complete',
#     'step': 'run training',
#     'url': f'https://app.valohai.com/api/v0/executions/{execution_id}/',
#     'urls': {
#         'copy': 'https://app.valohai.com/api/v0/executions/34/copy/',
#         'display': 'https://app.valohai.com/p/test/mnist/execution/34/',
#         'stop': 'https://app.valohai.com/api/v0/executions/34/stop/',
#     },
#     'parameters': {
#         'dropout': 0.9,
#         'learning_rate': 0.001,
#         'max_steps': 300,
#     },
#     'outputs': [
#         OUTPUT_DATUM_DATA,
#     ],
#     'environment': {
#         'id': '88888888-8888-8888-8888-888888888888',
#         'name': 'local',
#         'owner': None,
#         'unfinished_job_count': 0,
#     },
#     'cumulative_metadata': {
#         'oispa': 'beer',
#     },
# }
# 
# Path: valohai_cli/commands/execution/list.py
# @click.command()
# @click.option(
#     '--status',
#     multiple=True,
#     help='Filter by status (default: all)',
#     type=click.Choice(sorted(execution_statuses | {'incomplete'}))
# )
# @click.option(
#     '--count',
#     '--limit',
#     '-n',
#     type=int,
#     default=9001,
#     help='How many executions to show',
# )
# def list(status: str, count: int) -> None:
#     """
#     Show a list of executions for the project.
#     """
#     project = get_project(require=True)
#     assert project
#     params = {
#         'project': project.id,
#         'limit': count,
#         'ordering': '-counter',
#         'deleted': 'false',
#     }
#     if status:
#         params['status'] = set(status)
#     executions = request('get', '/api/v0/executions/', params=params).json()['results']
#     if settings.output_format == 'json':
#         return print_json(executions)
#     if not executions:
#         info(f'{project}: No executions.')
#         return
#     for execution in executions:
#         execution['url'] = execution['urls']['display']
#         execution['duration'] = str(
#             timedelta(seconds=round(execution['duration']))
#             if execution['duration']
#             else ''
#         ).rjust(10)
# 
#     print_table(
#         executions,
#         columns=['counter', 'status', 'step', 'duration', 'url'],
#         headers=['#', 'Status', 'Step', 'Duration', 'URL'],
#     )


import requests_mock
from tests.fixture_data import EXECUTION_DATA
from valohai_cli.commands.execution.list import list



def test_list(runner, logged_in_and_linked):

    with requests_mock.mock() as m:
        m.get(
            'https://app.valohai.com/api/v0/executions/',
            json={
                'results': [
                    EXECUTION_DATA,

# Path: tests/fixture_data.py
# EXECUTION_DATA = {
#     'counter': random.randint(1, 100),
#     'ctime': '2017-02-08T11:09:16.120102Z',
#     'id': execution_id,
#     'project': PROJECT_DATA,
#     'commit': {
#         'repository': 666,
#         'identifier': '000',
#         'ref': 'master',
#         'commit_time': '2017-02-15T08:46:58Z',
#         'url': 'https://app.valohai.com/api/v0/commits/7/'
#     },
#     'task': None,
#     'duration': 777,
#     'status': 'complete',
#     'step': 'run training',
#     'url': f'https://app.valohai.com/api/v0/executions/{execution_id}/',
#     'urls': {
#         'copy': 'https://app.valohai.com/api/v0/executions/34/copy/',
#         'display': 'https://app.valohai.com/p/test/mnist/execution/34/',
#         'stop': 'https://app.valohai.com/api/v0/executions/34/stop/',
#     },
#     'parameters': {
#         'dropout': 0.9,
#         'learning_rate': 0.001,
#         'max_steps': 300,
#     },
#     'outputs': [
#         OUTPUT_DATUM_DATA,
#     ],
#     'environment': {
#         'id': '88888888-8888-8888-8888-888888888888',
#         'name': 'local',
#         'owner': None,
#         'unfinished_job_count': 0,
#     },
#     'cumulative_metadata': {
#         'oispa': 'beer',
#     },
# }
# 
# Path: valohai_cli/commands/execution/list.py
# @click.command()
# @click.option(
#     '--status',
#     multiple=True,
#     help='Filter by status (default: all)',
#     type=click.Choice(sorted(execution_statuses | {'incomplete'}))
# )
# @click.option(
#     '--count',
#     '--limit',
#     '-n',
#     type=int,
#     default=9001,
#     help='How many executions to show',
# )
# def list(status: str, count: int) -> None:
#     """
#     Show a list of executions for the project.
#     """
#     project = get_project(require=True)
#     assert project
#     params = {
#         'project': project.id,
#         'limit': count,
#         'ordering': '-counter',
#         'deleted': 'false',
#     }
#     if status:
#         params['status'] = set(status)
#     executions = request('get', '/api/v0/executions/', params=params).json()['results']
#     if settings.output_format == 'json':
#         return print_json(executions)
#     if not executions:
#         info(f'{project}: No executions.')
#         return
#     for execution in executions:
#         execution['url'] = execution['urls']['display']
#         execution['duration'] = str(
#             timedelta(seconds=round(execution['duration']))
#             if execution['duration']
#             else ''
#         ).rjust(10)
# 
#     print_table(
#         executions,
#         columns=['counter', 'status', 'step', 'duration', 'url'],
#         headers=['#', 'Status', 'Step', 'Duration', 'URL'],
#     )


# Path: tests/commands/execution/test_list.py
import requests_mock
from tests.fixture_data import EXECUTION_DATA
from valohai_cli.commands.execution.list import list




def test_list(runner, logged_in_and_linked):

    with requests_mock.mock() as m:
        m.get(
            'https://app.valohai.com/api/v0/executions/',
            json={
                'results': [
                    EXECUTION_DATA,

                    EXECUTION_DATA,