| 1 |
""" |
| 2 |
Pytest configuration and fixtures for Meraki query tests. |
| 3 |
""" |
| 4 |
|
| 5 |
import json |
| 6 |
import pytest |
| 7 |
import yaml |
| 8 |
from pathlib import Path |
| 9 |
|
| 10 |
# Paths |
| 11 |
QUERY_FILE = Path(__file__).parent.parent.parent / "extensions" / "audit" / "event_query.yml" |
| 12 |
DATA_DIR = Path(__file__).parent / "api_fixtures" |
| 13 |
|
| 14 |
|
| 15 |
@pytest.fixture(scope="session") |
| 16 |
def query_data(): |
| 17 |
"""Load the event_query.yml file once for all tests.""" |
| 18 |
with open(QUERY_FILE) as f: |
| 19 |
return yaml.safe_load(f) |
| 20 |
|
| 21 |
|
| 22 |
@pytest.fixture |
| 23 |
def load_fixture(): |
| 24 |
"""Fixture factory to load JSON fixture files.""" |
| 25 |
|
| 26 |
def _load_fixture(module_fqcn): |
| 27 |
filepath = DATA_DIR / f"{module_fqcn}.json" |
| 28 |
if filepath.exists(): |
| 29 |
with open(filepath, "r") as f: |
| 30 |
return json.load(f) |
| 31 |
return None |
| 32 |
|
| 33 |
return _load_fixture |
| 34 |
|
| 35 |
|
| 36 |
@pytest.fixture |
| 37 |
def test_mappings(): |
| 38 |
"""Return the mapping between module_fqcn and method_name.""" |
| 39 |
return [ |
| 40 |
("cisco.meraki.networks_switch_mtu_info", "getNetworkSwitchMtu"), |
| 41 |
("cisco.meraki.devices_info", "getOrganizationDevices"), |
| 42 |
("cisco.meraki.devices_switch_ports_info", "getDeviceSwitchPort"), |
| 43 |
("cisco.meraki.networks_switch_stacks_info", "getNetworkSwitchStack"), |
| 44 |
( |
| 45 |
"cisco.meraki.networks_switch_stacks_routing_interfaces_info", |
| 46 |
"getNetworkSwitchStackRoutingInterfaces", |
| 47 |
), |
| 48 |
("cisco.meraki.devices_switch_ports", "updateDeviceSwitchPort"), |
| 49 |
( |
| 50 |
"cisco.meraki.organizations_switch_ports_by_switch_info", |
| 51 |
"getOrganizationSwitchPortsBySwitch", |
| 52 |
), |
| 53 |
( |
| 54 |
"cisco.meraki.devices_switch_ports_statuses_info", |
| 55 |
"getDeviceSwitchPortsStatuses", |
| 56 |
), |
| 57 |
( |
| 58 |
"cisco.meraki.networks_switch_access_policies_info", |
| 59 |
"getNetworkSwitchAccessPolicies", |
| 60 |
), |
| 61 |
( |
| 62 |
"cisco.meraki.networks_switch_settings_info", |
| 63 |
"getNetworkSwitchSettings", |
| 64 |
), |
| 65 |
( |
| 66 |
"cisco.meraki.networks_switch_access_policies", |
| 67 |
"updateNetworkSwitchAccessPolicy", |
| 68 |
), |
| 69 |
( |
| 70 |
"cisco.meraki.networks_switch_stacks_routing_interfaces", |
| 71 |
"createNetworkSwitchStackRoutingInterface", |
| 72 |
), |
| 73 |
( |
| 74 |
"cisco.meraki.networks_switch_stp_info", |
| 75 |
"getNetworkSwitchStp", |
| 76 |
), |
| 77 |
( |
| 78 |
"cisco.meraki.networks_switch_qos_rules_order", |
| 79 |
"createNetworkSwitchQosRule", |
| 80 |
), |
| 81 |
( |
| 82 |
"cisco.meraki.devices_switch_ports_cycle", |
| 83 |
"cycleDeviceSwitchPorts", |
| 84 |
), |
| 85 |
( |
| 86 |
"cisco.meraki.networks_switch_access_control_lists_info", |
| 87 |
"getNetworkSwitchAccessControlLists", |
| 88 |
), |
| 89 |
( |
| 90 |
"cisco.meraki.networks_switch_stacks", |
| 91 |
"createNetworkSwitchStack", |
| 92 |
), |
| 93 |
( |
| 94 |
"cisco.meraki.networks_switch_settings", |
| 95 |
"updateNetworkSwitchSettings", |
| 96 |
), |
| 97 |
( |
| 98 |
"cisco.meraki.networks_switch_stacks_routing_interfaces_dhcp_info", |
| 99 |
"getNetworkSwitchStackRoutingInterfaceDhcp", |
| 100 |
), |
| 101 |
( |
| 102 |
"cisco.meraki.networks_switch_access_policies", |
| 103 |
"createNetworkSwitchAccessPolicy", |
| 104 |
), |
| 105 |
( |
| 106 |
"cisco.meraki.networks_switch_stacks_routing_interfaces_dhcp", |
| 107 |
"updateNetworkSwitchStackRoutingInterfaceDhcp", |
| 108 |
), |
| 109 |
( |
| 110 |
"cisco.meraki.networks_switch_dhcp_server_policy_info", |
| 111 |
"getNetworkSwitchDhcpServerPolicy", |
| 112 |
), |
| 113 |
( |
| 114 |
"cisco.meraki.networks_switch_stp", |
| 115 |
"updateNetworkSwitchStp", |
| 116 |
), |
| 117 |
( |
| 118 |
"cisco.meraki.networks_switch_link_aggregations", |
| 119 |
"createNetworkSwitchLinkAggregation", |
| 120 |
), |
| 121 |
( |
| 122 |
"cisco.meraki.devices_switch_routing_interfaces_info", |
| 123 |
"getDeviceSwitchRoutingInterfaces", |
| 124 |
), |
| 125 |
( |
| 126 |
"cisco.meraki.devices_switch_routing_interfaces", |
| 127 |
"createDeviceSwitchRoutingInterface", |
| 128 |
), |
| 129 |
( |
| 130 |
"cisco.meraki.networks_switch_access_control_lists", |
| 131 |
"updateNetworkSwitchAccessControlLists", |
| 132 |
), |
| 133 |
( |
| 134 |
"cisco.meraki.networks_switch_routing_multicast_info", |
| 135 |
"getNetworkSwitchRoutingMulticast", |
| 136 |
), |
| 137 |
( |
| 138 |
"cisco.meraki.networks_switch_stacks_routing_interfaces_info", |
| 139 |
"getNetworkSwitchStackRoutingInterface", |
| 140 |
), |
| 141 |
( |
| 142 |
"cisco.meraki.networks_switch_routing_ospf_info", |
| 143 |
"getNetworkSwitchRoutingOspf", |
| 144 |
), |
| 145 |
( |
| 146 |
"cisco.meraki.networks_switch_alternate_management_interface_info", |
| 147 |
"getNetworkSwitchAlternateManagementInterface", |
| 148 |
), |
| 149 |
( |
| 150 |
"cisco.meraki.organizations_config_templates_switch_profiles_info", |
| 151 |
"getOrganizationConfigTemplateSwitchProfiles", |
| 152 |
), |
| 153 |
( |
| 154 |
"cisco.meraki.networks_switch_routing_ospf", |
| 155 |
"updateNetworkSwitchRoutingOspf", |
| 156 |
), |
| 157 |
( |
| 158 |
"cisco.meraki.networks_switch_dhcp_server_policy_arp_inspection_trusted_servers_info", |
| 159 |
"getNetworkSwitchDhcpServerPolicyArpInspectionTrustedServers", |
| 160 |
), |
| 161 |
( |
| 162 |
"cisco.meraki.networks_switch_dhcp_server_policy_arp_inspection_warnings_by_device_info", |
| 163 |
"getNetworkSwitchDhcpServerPolicyArpInspectionWarningsByDevice", |
| 164 |
), |
| 165 |
( |
| 166 |
"cisco.meraki.networks_switch_dhcp_v4_servers_seen_info", |
| 167 |
"getNetworkSwitchDhcpV4ServersSeen", |
| 168 |
), |
| 169 |
( |
| 170 |
"cisco.meraki.networks_switch_link_aggregations_info", |
| 171 |
"getNetworkSwitchLinkAggregations", |
| 172 |
), |
| 173 |
( |
| 174 |
"cisco.meraki.networks_switch_qos_rules_order_info", |
| 175 |
"getNetworkSwitchQosRule", |
| 176 |
), |
| 177 |
( |
| 178 |
"cisco.meraki.networks_switch_routing_multicast_rendezvous_points_info", |
| 179 |
"getNetworkSwitchRoutingMulticastRendezvousPoints", |
| 180 |
), |
| 181 |
( |
| 182 |
"cisco.meraki.devices_switch_routing_static_routes_info", |
| 183 |
"getDeviceSwitchRoutingStaticRoute", |
| 184 |
), |
| 185 |
( |
| 186 |
"cisco.meraki.networks_switch_stacks_remove", |
| 187 |
"removeNetworkSwitchStack", |
| 188 |
), |
| 189 |
( |
| 190 |
"cisco.meraki.devices_switch_warm_spare_info", |
| 191 |
"getDeviceSwitchWarmSpare", |
| 192 |
), |
| 193 |
( |
| 194 |
"cisco.meraki.organizations_summary_top_switches_by_energy_usage_info", |
| 195 |
"getOrganizationSummaryTopSwitchesByEnergyUsage", |
| 196 |
), |
| 197 |
( |
| 198 |
"cisco.meraki.networks_switch_stacks_add", |
| 199 |
"addNetworkSwitchStack", |
| 200 |
), |
| 201 |
( |
| 202 |
"cisco.meraki.devices_switch_routing_interfaces_dhcp_info", |
| 203 |
"getDeviceSwitchRoutingInterfaceDhcp", |
| 204 |
), |
| 205 |
( |
| 206 |
"cisco.meraki.devices_switch_routing_interfaces_dhcp", |
| 207 |
"updateDeviceSwitchRoutingInterfaceDhcp", |
| 208 |
), |
| 209 |
( |
| 210 |
"cisco.meraki.networks_switch_routing_multicast", |
| 211 |
"updateNetworkSwitchRoutingMulticast", |
| 212 |
), |
| 213 |
] |