# 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',
#     },
# }
# 
# PROJECT_DATA = {
#     'id': '000',
#     'name': 'nyan',
#     'description': 'nyan',
#     'owner': 1,
#     'ctime': '2016-12-16T12:25:52.718310Z',
#     'mtime': '2017-01-20T14:35:02.196871Z',
#     'urls': {
#         'display': 'https://app.valohai.com/p/nyan/nyan/',
#     }
# }
# 
# Path: valohai_cli/commands/project/fetch.py
# @click.command()
# def fetch() -> None:
#     """
#     Fetch new commits for the linked project.
#     """
#     project = get_project(require=True)
#     resp = request('post', f'/api/v0/projects/{project.id}/fetch/')
#     data = resp.json()
#     commits = data.get('commits', ())
#     if commits:
#         for commit in commits:
#             success(f"Fetched: {commit['ref']} ({commit['identifier']})")
#         success(f'{len(commits)} new commits were fetched!')
#     else:
#         info('No new commits.')
#     errors = data.get('errors', ())
#     for error in errors:
#         warning(error)


import requests_mock
from tests.fixture_data import EXECUTION_DATA, PROJECT_DATA
from valohai_cli.commands.project.fetch import fetch



def test_fetch(runner, logged_in_and_linked):
    with requests_mock.mock() as m:
        commit_data = EXECUTION_DATA['commit']
        m.post(

# 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',
#     },
# }
# 
# PROJECT_DATA = {
#     'id': '000',
#     'name': 'nyan',
#     'description': 'nyan',
#     'owner': 1,
#     'ctime': '2016-12-16T12:25:52.718310Z',
#     'mtime': '2017-01-20T14:35:02.196871Z',
#     'urls': {
#         'display': 'https://app.valohai.com/p/nyan/nyan/',
#     }
# }
# 
# Path: valohai_cli/commands/project/fetch.py
# @click.command()
# def fetch() -> None:
#     """
#     Fetch new commits for the linked project.
#     """
#     project = get_project(require=True)
#     resp = request('post', f'/api/v0/projects/{project.id}/fetch/')
#     data = resp.json()
#     commits = data.get('commits', ())
#     if commits:
#         for commit in commits:
#             success(f"Fetched: {commit['ref']} ({commit['identifier']})")
#         success(f'{len(commits)} new commits were fetched!')
#     else:
#         info('No new commits.')
#     errors = data.get('errors', ())
#     for error in errors:
#         warning(error)


# Path: tests/commands/project/test_fetch.py
import requests_mock
from tests.fixture_data import EXECUTION_DATA, PROJECT_DATA
from valohai_cli.commands.project.fetch import fetch




def test_fetch(runner, logged_in_and_linked):
    with requests_mock.mock() as m:
        commit_data = EXECUTION_DATA['commit']
        m.post(

            f"https://app.valohai.com/api/v0/projects/{PROJECT_DATA['id']}/fetch/",