# Path: src/tests/behave/api/features/common/utils.py
# def get_entity_list_container_field(name):
#     """Returns the container field used in list responses
# 
#     GET /active_computers       -> {"items": [...]}
#     GET /jobs                   -> {"jobs": [...]}
#     """
#     if name == "active_computers":
#         return "items"
#     elif name == "inventory_computers":
#         return "items"
#     elif name == "rpc_tasks":
#         return "tasks"
#     elif name == "rpc_jobs":
#         return "jobs"
#     return name
# 
# def get_entity_id_field(name):
#     """Returns the id field used for entities in list responses
# 
#     GET /active_computers       -> {"items": [{"mercury_id": "...", ...}}]}
#     GET /jobs                   -> {"jobs": [{"job_id": "...", ...}}]}
#     """
#     if name == "active_computers":
#         return "mercury_id"
#     elif name == "inventory_computers":
#         return "mercury_id"
#     elif name == "rpc_tasks":
#         return "task_id"
#     elif name == "rpc_jobs":
#         return "job_id"
#     return name
# 
# def read_json_from_file(filename, location):
#     filename = "{0}/{1}".format(location, filename)
#     with open(filename) as file:
#         data = json.loads(file.read())
#     return data


import json
import operator
from functools import reduce
from behave import given, when, step
from src.tests.behave.api.features.common.utils import (
    get_entity_list_container_field,
    get_entity_id_field,
    read_json_from_file,
)
    # trim trailing &
    suffix = suffix.rstrip("&")
    context.services[service_name]["offset_param_data"] = param_data

    service_client = context.services[service_name]["client"]
    data = context.services[service_name]["details"]["query"]

    context.services[service_name]["offset_resp"] = service_client.post(
        data=json.dumps(data), url_suffix=suffix
    )
    # so we can use existing checks on this response too
    context.services[service_name]["resp"] = context.services[service_name][
        "offset_resp"
    ]


@step(
    "the {service_name} entities in the response contain the data from {filename}"
)
def step_the_entities_in_the_response_contain_the_data_from_filename(
    context, service_name, filename
):
    """
    :type context: behave.runner.Context
    :type service_name: str
    :type field: str
    :type value: str
    """
    service_client = context.services[service_name]["client"]
    service_resp = context.services[service_name]["resp"]

# Path: src/tests/behave/api/features/common/utils.py
# def get_entity_list_container_field(name):
#     """Returns the container field used in list responses
# 
#     GET /active_computers       -> {"items": [...]}
#     GET /jobs                   -> {"jobs": [...]}
#     """
#     if name == "active_computers":
#         return "items"
#     elif name == "inventory_computers":
#         return "items"
#     elif name == "rpc_tasks":
#         return "tasks"
#     elif name == "rpc_jobs":
#         return "jobs"
#     return name
# 
# def get_entity_id_field(name):
#     """Returns the id field used for entities in list responses
# 
#     GET /active_computers       -> {"items": [{"mercury_id": "...", ...}}]}
#     GET /jobs                   -> {"jobs": [{"job_id": "...", ...}}]}
#     """
#     if name == "active_computers":
#         return "mercury_id"
#     elif name == "inventory_computers":
#         return "mercury_id"
#     elif name == "rpc_tasks":
#         return "task_id"
#     elif name == "rpc_jobs":
#         return "job_id"
#     return name
# 
# def read_json_from_file(filename, location):
#     filename = "{0}/{1}".format(location, filename)
#     with open(filename) as file:
#         data = json.loads(file.read())
#     return data


# Path: src/tests/behave/api/features/steps/query.py
import json
import operator
from functools import reduce
from behave import given, when, step
from src.tests.behave.api.features.common.utils import (
    get_entity_list_container_field,
    get_entity_id_field,
    read_json_from_file,
)

    # trim trailing &
    suffix = suffix.rstrip("&")
    context.services[service_name]["offset_param_data"] = param_data

    service_client = context.services[service_name]["client"]
    data = context.services[service_name]["details"]["query"]

    context.services[service_name]["offset_resp"] = service_client.post(
        data=json.dumps(data), url_suffix=suffix
    )
    # so we can use existing checks on this response too
    context.services[service_name]["resp"] = context.services[service_name][
        "offset_resp"
    ]


@step(
    "the {service_name} entities in the response contain the data from {filename}"
)
def step_the_entities_in_the_response_contain_the_data_from_filename(
    context, service_name, filename
):
    """
    :type context: behave.runner.Context
    :type service_name: str
    :type field: str
    :type value: str
    """
    service_client = context.services[service_name]["client"]
    service_resp = context.services[service_name]["resp"]

    container_field = get_entity_list_container_field(service_name)