# Path: tests/fixture_data.py
# 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: tests/utils.py
# def make_call_stub(retval=None):
#     calls = []
# 
#     def call_stub(*args, **kwargs):
#         calls.append({'args': args, 'kwargs': kwargs})
#         return retval
# 
#     call_stub.calls = calls
#     return call_stub
# 
# Path: valohai_cli/commands/project/open.py
# @click.command()
# def open() -> None:
#     """
#     Open the project's view in a web browser.
#     """
#     project = get_project(require=True)
#     project_data = request('get', f'/api/v0/projects/{project.id}/').json()
#     open_browser(project_data)


import webbrowser
import requests_mock
from tests.fixture_data import PROJECT_DATA
from tests.utils import make_call_stub
from valohai_cli.commands.project.open import open




def test_open(monkeypatch, runner, logged_in_and_linked):
    call_stub = make_call_stub()
    monkeypatch.setattr(webbrowser, 'open', call_stub)
    with requests_mock.mock() as m:
        project_data = dict(PROJECT_DATA)

# Path: tests/fixture_data.py
# 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: tests/utils.py
# def make_call_stub(retval=None):
#     calls = []
# 
#     def call_stub(*args, **kwargs):
#         calls.append({'args': args, 'kwargs': kwargs})
#         return retval
# 
#     call_stub.calls = calls
#     return call_stub
# 
# Path: valohai_cli/commands/project/open.py
# @click.command()
# def open() -> None:
#     """
#     Open the project's view in a web browser.
#     """
#     project = get_project(require=True)
#     project_data = request('get', f'/api/v0/projects/{project.id}/').json()
#     open_browser(project_data)


# Path: tests/commands/project/test_open.py
import webbrowser
import requests_mock
from tests.fixture_data import PROJECT_DATA
from tests.utils import make_call_stub
from valohai_cli.commands.project.open import open





def test_open(monkeypatch, runner, logged_in_and_linked):
    call_stub = make_call_stub()
    monkeypatch.setattr(webbrowser, 'open', call_stub)
    with requests_mock.mock() as m:
        project_data = dict(PROJECT_DATA)

        m.get(f"https://app.valohai.com/api/v0/projects/{project_data['id']}/", json=project_data)