# Path: tests/fixture_data.py
# EVENT_RESPONSE_DATA = {
#     'total': 5,
#     'truncated': False,
#     'events': [
#         {
#             'time': '2017-02-16T15:25:33.037000',
#             'stream': 'status',
#             'message': 'hOI!!! I\'m temmie!'
#         },
#         {
#             'time': '2017-02-16T15:25:33.037000',
#             'stream': 'stderr',
#             'message': 'oh no',
#         },
#     ],
# }
# 
# 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',
#     },
# }
# 
# OUTPUT_DATUM_DATA = {
#     "id": datum_id,
#     "size": 509739,
#     "ctime": "2019-05-23T14:26:35.604807Z",
#     "file_ctime": "2019-05-23T14:26:33.607583Z",
#     "file_mtime": "2019-05-23T14:26:33.607583Z",
#     "name": "yvrw91fdvwz21.png",
#     "output_execution": {
#         "id": execution_id,
#     },
# }
# 
# OUTPUT_DATUM_DOWNLOAD_RESPONSE_DATA = {
#     'url': f'https://example.com/{str(uuid.uuid4())}',
# }
# 
# OUTPUT_DATUM_RESPONSE_DATA = {
#     "count": 1,
#     "next": None,
#     "previous": None,
#     "results": [OUTPUT_DATUM_DATA],
# }
# 
# 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/',
#     }
# }


import re
import requests_mock
from typing import Pattern
from tests.fixture_data import (
    EVENT_RESPONSE_DATA,
    EXECUTION_DATA,
    OUTPUT_DATUM_DATA,
    OUTPUT_DATUM_DOWNLOAD_RESPONSE_DATA,
    OUTPUT_DATUM_RESPONSE_DATA,
    PROJECT_DATA,
)



API_PREFIX = 'https://app.valohai.com/api/v0/'


def get_startswith_re(text: str) -> Pattern:
    return re.compile('^' + re.escape(text))


def get_execution_data_mock():
    exec_id = EXECUTION_DATA['id']
    datum_id = OUTPUT_DATUM_DATA['id']
    m = requests_mock.mock()
    project_id = PROJECT_DATA['id']
    execution_counter = EXECUTION_DATA['counter']

# Path: tests/fixture_data.py
# EVENT_RESPONSE_DATA = {
#     'total': 5,
#     'truncated': False,
#     'events': [
#         {
#             'time': '2017-02-16T15:25:33.037000',
#             'stream': 'status',
#             'message': 'hOI!!! I\'m temmie!'
#         },
#         {
#             'time': '2017-02-16T15:25:33.037000',
#             'stream': 'stderr',
#             'message': 'oh no',
#         },
#     ],
# }
# 
# 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',
#     },
# }
# 
# OUTPUT_DATUM_DATA = {
#     "id": datum_id,
#     "size": 509739,
#     "ctime": "2019-05-23T14:26:35.604807Z",
#     "file_ctime": "2019-05-23T14:26:33.607583Z",
#     "file_mtime": "2019-05-23T14:26:33.607583Z",
#     "name": "yvrw91fdvwz21.png",
#     "output_execution": {
#         "id": execution_id,
#     },
# }
# 
# OUTPUT_DATUM_DOWNLOAD_RESPONSE_DATA = {
#     'url': f'https://example.com/{str(uuid.uuid4())}',
# }
# 
# OUTPUT_DATUM_RESPONSE_DATA = {
#     "count": 1,
#     "next": None,
#     "previous": None,
#     "results": [OUTPUT_DATUM_DATA],
# }
# 
# 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/commands/execution/utils.py
import re
import requests_mock
from typing import Pattern
from tests.fixture_data import (
    EVENT_RESPONSE_DATA,
    EXECUTION_DATA,
    OUTPUT_DATUM_DATA,
    OUTPUT_DATUM_DOWNLOAD_RESPONSE_DATA,
    OUTPUT_DATUM_RESPONSE_DATA,
    PROJECT_DATA,
)




API_PREFIX = 'https://app.valohai.com/api/v0/'


def get_startswith_re(text: str) -> Pattern:
    return re.compile('^' + re.escape(text))


def get_execution_data_mock():
    exec_id = EXECUTION_DATA['id']
    datum_id = OUTPUT_DATUM_DATA['id']
    m = requests_mock.mock()
    project_id = PROJECT_DATA['id']
    execution_counter = EXECUTION_DATA['counter']

    m.get(f'{API_PREFIX}projects/{project_id}/', json=PROJECT_DATA)