# 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 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 random
from behave import when, step, then, given
from src.tests.behave.api.features.common.utils import (
    get_entity_list_container_field,
    read_json_from_file,
)
    offset_id = service_entities[4]["_id"]
    first_id = service_entities[5]["_id"]
    context.services[service_name]["offset_id"] = offset_id
    context.services[service_name]["first_id"] = first_id

    location = context.json_location
    data = read_json_from_file(filename, location)

    keys = data.keys()
    suffix = "?"
    for key in keys:
        if key == "offset_id":
            data["offset_id"] = offset_id
        suffix = "{0}{1}={2}&".format(suffix, key, data[key])
    # trim trailing &
    suffix = suffix.rstrip("&")
    context.services[service_name]["offset_param_data"] = data
    service_client = context.services[service_name]["client"]
    context.services[service_name]["offset_resp"] = service_client.get(
        url_suffix=suffix
    )


@step("the response contains a list of {service_name}")
def step_the_response_contains_a_list_of_service_ids(context, service_name):
    """
    :type context: behave.runner.Context
    :type service_name: str
    """
    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 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/list.py
import random
from behave import when, step, then, given
from src.tests.behave.api.features.common.utils import (
    get_entity_list_container_field,
    read_json_from_file,
)

    offset_id = service_entities[4]["_id"]
    first_id = service_entities[5]["_id"]
    context.services[service_name]["offset_id"] = offset_id
    context.services[service_name]["first_id"] = first_id

    location = context.json_location
    data = read_json_from_file(filename, location)

    keys = data.keys()
    suffix = "?"
    for key in keys:
        if key == "offset_id":
            data["offset_id"] = offset_id
        suffix = "{0}{1}={2}&".format(suffix, key, data[key])
    # trim trailing &
    suffix = suffix.rstrip("&")
    context.services[service_name]["offset_param_data"] = data
    service_client = context.services[service_name]["client"]
    context.services[service_name]["offset_resp"] = service_client.get(
        url_suffix=suffix
    )


@step("the response contains a list of {service_name}")
def step_the_response_contains_a_list_of_service_ids(context, service_name):
    """
    :type context: behave.runner.Context
    :type service_name: str
    """
    service_resp = context.services[service_name]["resp"]

    container_field = get_entity_list_container_field(service_name)