Example #1
0
def scan(spec_path, docs_path, log_level):
    """Automated Testing and Documentation for your REST API."""

    logging.basicConfig(level=log_level)
    logger = logging.getLogger(__name__)
    SETTINGS.update({"spec_path": spec_path, "docs_path": docs_path})

    spec_path = SETTINGS["spec_path"]
    try:
        api_spec = load_yaml(spec_path)
    except FileNotFoundError as e:
        error_message = "Could not find spec file: {}".format(spec_path)
        logger.error(error_message)
        return

    try:
        request_builder = RequestsBuilder(api_spec)
    except Exception as e:
        error_message = "Error loading API spec."
        error_message = "{} {}".format(error_message, str(e))
        logger.error(error_message)
        return

    request_builder.build_all()
    responses = request_builder.call_all()
    DocsWriter(docs_path).write(responses)
Example #2
0
def scan(spec_path, output_path, reporter, template, log_level):
    """Automated Testing and Documentation for your REST API."""

    logging.basicConfig(level=log_level)
    logger = logging.getLogger(__name__)
    SETTINGS.update({"spec_path": spec_path, "output_path": output_path})

    # custom templates to be implemented later
    if template is not None:
        logger.warn(
            "Custom templates are not supported yet. Soon to be. Hang tight.")

    spec_path = SETTINGS["spec_path"]
    try:
        api_spec = load_yaml(spec_path)
    except FileNotFoundError as e:
        error_message = f"Could not find spec file: {spec_path}. {str(e)}"
        logger.error(error_message)
        return

    try:
        api_tree = APITree(api_spec)
    except Exception as e:
        error_message = "Error loading API spec."
        error_message = "{} {}".format(error_message, str(e))
        logger.error(error_message)
        return

    RequestsMaker(api_tree).make_all()
    Reporter(output_path, reporter,
             template).write(api_tree.responses.values())
Example #3
0
import factory

from scanapi.reporter import Reporter
from scanapi.requests_maker import RequestsMaker
from scanapi.tree.api_node import APINode
from scanapi.tree.api_tree import APITree
from scanapi.tree.endpoint_node import EndpointNode
from scanapi.yaml_loader import load_yaml

WITH_ENDPOINTS_MINIMAL_SPEC = load_yaml(
    "tests/data/specs/with_endpoints/minimal_get.yaml")
WITH_ENDPOINTS_WITH_ROOT_REQUESTS = load_yaml(
    "tests/data/specs/with_endpoints/get_with_root_requests.yaml")
WITH_ENDPOINTS_GET_WITH_HEADER_BODY_PARAMS = load_yaml(
    "tests/data/specs/with_endpoints/get_with_header_body_params.yaml")
WITHOUT_ENDPOINTS_MINIMAL_SPEC = load_yaml(
    "tests/data/specs/without_endpoints/minimal_get.yaml")
METHOD_NOT_ALLOWED_SPEC = load_yaml(
    "tests/data/specs/invalid/method_not_allowed.yaml")


class APITreeFactory(factory.Factory):
    class Meta:
        model = APITree

    api_spec = WITHOUT_ENDPOINTS_MINIMAL_SPEC

    class Params:
        with_endpoints_minimal = factory.Trait(
            api_spec=WITH_ENDPOINTS_MINIMAL_SPEC)
        with_endpoints_with_root_requests = factory.Trait(
Example #4
0
 def api_spec(self):
     return load_yaml(
         "tests/data/specs/with_endpoints/get_with_root_requests.yaml"
     )
Example #5
0
 def api_spec(self):
     return load_yaml(
         "tests/data/specs/without_endpoints/minimal_get.yaml")
Example #6
0
def settings():
    if not os.path.isfile(SETTINGS_FILE):
        return DEFAULT_SETTINGS

    user_config = load_yaml(SETTINGS_FILE)
    return {**DEFAULT_SETTINGS, **user_config}