# Path: scalrctl/defaults.py
# CONFIG_DIRECTORY = os.path.expanduser(os.environ.get("SCALRCLI_HOME", os.path.join(os.path.expanduser("~"), ".scalr")))
# CONFIG_PATH = os.path.join(CONFIG_DIRECTORY, "%s.yaml" % os.environ.get("SCALRCLI_PROFILE", "default"))
# VERSION = open(os.path.join(os.path.dirname(__file__), "VERSION")).read().strip()
# API_LEVELS = [
#     'user',
#     'account',
#     'global',
# ]
# 
# Path: scalrctl/examples.py
# DOCS_HOST = 'https://api-explorer.scalr.com'
# EXCLUDES = [
#     '/{envId}/farm-roles/{farmRoleId}/servers/',
#     '/{envId}/servers/',
# ]
# DEFAULTS = {
#     'string': '',
#     'boolean': True,
#     'integer': 1,
#     'number': 1,
#     'array': []
# }
# def _read_spec(api_level, extension="json"):
# def _item_by_ref(spec_data, ref):
# def _generate_params(spec_data, schema):
# def generate_post_data(spec_data, endpoint):
# def get_definition(spec_data, endpoint):
# def get_doc_url(api_level, endpoint):
# def create_post_example(api_level, endpoint):


import json
import pytest
import requests
from scalrctl import defaults, examples


@pytest.fixture(scope="module")
def post_endpoints(specs):
    endpoints = []
    for api_level, spec_data in specs.items():
        for endpoint, params_spec in spec_data['paths'].items():
            if 'post' in params_spec:
                endpoints.append((api_level, endpoint))
    return endpoints


def _is_valid_endpoint(endpoint):
    return not ('/actions/' in endpoint or endpoint in examples.EXCLUDES)


def test_create_post_example(post_endpoints):
    for api_level, endpoint in post_endpoints:
        try:
            examples.create_post_example(api_level, endpoint)
        except Exception as e:
            assert not _is_valid_endpoint(endpoint) \
                   and str(e) == 'Invalid API endpoint'
        else:
            assert _is_valid_endpoint(endpoint)


def test_get_object_name(specs, post_endpoints):
    for api_level, endpoint in post_endpoints:
        if _is_valid_endpoint(endpoint):

# Path: scalrctl/defaults.py
# CONFIG_DIRECTORY = os.path.expanduser(os.environ.get("SCALRCLI_HOME", os.path.join(os.path.expanduser("~"), ".scalr")))
# CONFIG_PATH = os.path.join(CONFIG_DIRECTORY, "%s.yaml" % os.environ.get("SCALRCLI_PROFILE", "default"))
# VERSION = open(os.path.join(os.path.dirname(__file__), "VERSION")).read().strip()
# API_LEVELS = [
#     'user',
#     'account',
#     'global',
# ]
# 
# Path: scalrctl/examples.py
# DOCS_HOST = 'https://api-explorer.scalr.com'
# EXCLUDES = [
#     '/{envId}/farm-roles/{farmRoleId}/servers/',
#     '/{envId}/servers/',
# ]
# DEFAULTS = {
#     'string': '',
#     'boolean': True,
#     'integer': 1,
#     'number': 1,
#     'array': []
# }
# def _read_spec(api_level, extension="json"):
# def _item_by_ref(spec_data, ref):
# def _generate_params(spec_data, schema):
# def generate_post_data(spec_data, endpoint):
# def get_definition(spec_data, endpoint):
# def get_doc_url(api_level, endpoint):
# def create_post_example(api_level, endpoint):


# Path: tests/small/test_examples.py
import json
import pytest
import requests
from scalrctl import defaults, examples



@pytest.fixture(scope="module")
def post_endpoints(specs):
    endpoints = []
    for api_level, spec_data in specs.items():
        for endpoint, params_spec in spec_data['paths'].items():
            if 'post' in params_spec:
                endpoints.append((api_level, endpoint))
    return endpoints


def _is_valid_endpoint(endpoint):
    return not ('/actions/' in endpoint or endpoint in examples.EXCLUDES)


def test_create_post_example(post_endpoints):
    for api_level, endpoint in post_endpoints:
        try:
            examples.create_post_example(api_level, endpoint)
        except Exception as e:
            assert not _is_valid_endpoint(endpoint) \
                   and str(e) == 'Invalid API endpoint'
        else:
            assert _is_valid_endpoint(endpoint)


def test_get_object_name(specs, post_endpoints):
    for api_level, endpoint in post_endpoints:
        if _is_valid_endpoint(endpoint):

            object_name = examples.get_definition(specs[api_level], endpoint)