def test_AnsibleInfoModule_payload():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(resources["vcenter_vm"], definitions)
    assert module.payload() == {
        "get": {"body": {}, "path": {"vm": "vm"}, "query": {}},
        "list": {"body": {}, "path": {}, "query": {"filter.vms": "filter.vms"}},
    }

    paths = rm.SwaggerFile.load_paths(my_raw_paths_data_with_param_in_path)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(
        resources["vcenter_vmtemplate_libraryitems_checkouts"], definitions
    )
    assert module.payload() == {
        "check_in": {
            "body": {"message": "spec/message"},
            "path": {"template_library_item": "template_library_item", "vm": "vm"},
            "query": {"action": "action"},
        },
        "check_out": {
            "body": {
                "name": "spec/name",
                "placement": "spec/placement",
                "powered_on": "spec/powered_on",
            },
            "path": {"template_library_item": "template_library_item"},
            "query": {"action": "action"},
        },
    }
def test_AnsibleInfoModule_parameters():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm_info"
    assert module.parameters() == [
        {
            "collectionFormat": "multi",
            "description": "desc of multi",
            "in": "query",
            "items": {"type": "string"},
            "name": "filter.vms",
            "operationIds": ["list"],
            "type": "array",
        },
        {
            "description": "Id of the VM Required with I(state=['get'])",
            "in": "path",
            "name": "vm",
            "operationIds": ["get"],
            "required_if": ["get"],
            "type": "string",
        },
    ]
def test_AnsibleModule_parameters():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModule(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm"
    assert module.parameters() == [{"enum": [], "name": "state", "type": "str"}]
def test_AnsibleInfoModule_parameters():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm_info"
    assert module.parameters() == [
        {
            "_loc_in_payload": "filter.vms",
            "description": "desc of multi",
            "elements": "string",
            "in": "query",
            "name": "filter.vms",
            "operationIds": ["list"],
            "required": None,
            "type": "array",
        },
        {
            "_loc_in_payload": "vm",
            "description": "Id of the VM",
            "in": "path",
            "name": "vm",
            "operationIds": ["get"],
            "required_if": ["get"],
            "type": "string",
        },
    ]
def test_filter_out_trusted_module():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModuleBase(resources["vcenter_vm"], definitions)
    assert module.is_trusted()
    module.name = "something_we_dont_trust"
    assert not module.is_trusted()
def test_AnsibleModule_parameters_complex():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data_with_param_in_path)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    print("R: %s" % resources)
    module = rm.AnsibleModule(
        resources["vcenter_vmtemplate_libraryitems_checkouts"], definitions
    )
    assert module.name == "vcenter_vmtemplate_libraryitems_checkouts"
    assert module.parameters() == [
        {
            "description": "action=check-out",
            "enum": ["check-in", "check-out"],
            "in": "query",
            "name": "action",
            "operationIds": ["check_in", "check_out"],
            "required_if": ["check_in", "check_out"],
            "type": "string",
        },
        {
            "description": "Message describing the changes made to the virtual machine. "
            "Required with I(state=['check_in'])",
            "name": "message",
            "operationIds": ["check_in"],
            "required_if": ["check_in"],
            "type": "string",
        },
        {
            "description": "Name of the virtual machine to check out of the library "
            "item.",
            "name": "name",
            "operationIds": ["check_out"],
            "required": False,
            "type": "string",
        },
        {
            "description": "Information used to place the checked out virtual machine.",
            "name": "placement",
            "operationIds": ["check_out"],
            "required": False,
            "subkeys": [
                {
                    "description": "Cluster onto which the virtual machine should "
                    "be placed. If {@name #cluster} and {@name "
                    "#resourcePool} are both specified, {@name "
                    "#resourcePool} must belong to {@name #cluster}. "
                    "If {@name #cluster} and {@name #host} are both "
                    "specified, {@name #host} must be a member of "
                    "{@name #cluster}.",
                    "name": "cluster",
                    "required": False,
                    "type": "string",
                },
                {
                    "description": "Virtual machine folder into which the virtual "
                    "machine should be placed.",
                    "name": "folder",
                    "required": False,
                    "type": "string",
                },
                {
                    "description": "Host onto which the virtual machine should be "
                    "placed. If {@name #host} and {@name "
                    "#resourcePool} are both specified, {@name "
                    "#resourcePool} must belong to {@name #host}. If "
                    "{@name #host} and {@name #cluster} are both "
                    "specified, {@name #host} must be a member of "
                    "{@name #cluster}.",
                    "name": "host",
                    "required": False,
                    "type": "string",
                },
                {
                    "description": "Resource pool into which the virtual machine "
                    "should be placed.",
                    "name": "resource_pool",
                    "required": False,
                    "type": "string",
                },
            ],
            "type": "dict",
        },
        {
            "description": "Specifies whether the virtual machine should be powered on "
            "after check out.",
            "name": "powered_on",
            "operationIds": ["check_out"],
            "required": False,
            "type": "boolean",
        },
        {
            "default": "present",
            "enum": ["check_in", "check_out"],
            "name": "state",
            "type": "str",
        },
        {
            "description": "Identifier of the content library item containing the source "
            + "virtual machine template to be checked out.",
            "in": "path",
            "name": "template_library_item",
            "operationIds": ["check_in", "check_out"],
            "required_if": ["check_in", "check_out"],
            "type": "string",
        },
        {
            "description": "Identifier of the virtual machine to check into the library "
            "item. Required with I(state=['check_in'])",
            "in": "path",
            "name": "vm",
            "operationIds": ["check_in"],
            "required_if": ["check_in"],
            "type": "string",
        },
    ]
def test_AnsibleModuleBase():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModuleBase(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm"