def test_has_traffic(): profile = {"avgFramesPerSecond": 1, "streamCount": 2, "avgPacketSize": 3, "other": 4} assert has_traffic(profile) profile.pop("streamCount") assert not has_traffic(profile) profile["streamCount"] = 2 profile.pop("avgFramesPerSecond") assert not has_traffic(profile) profile["avgFramesPerSecond"] = 1 profile.pop("avgPacketSize") assert not has_traffic(profile)
def process_locations(profile_list, port_map=None): """Process profiles with port locations and return list of verdicts.""" result = [] if not port_map: port_map = port_info.PhysicalPortMap() # pre-check location_list = [] for profile in profile_list: if "portLocations" in profile: if traffic_check.has_traffic(profile): location_list += [str(loc) for loc in profile["portLocations"]] preflight.check(port_map, traffic_check.get_soft_locations(port_map, location_list)) # actual check for profile in profile_list: if "portLocations" in profile: prof_result = {"profileId": profile["profileId"], "portLocations": []} location_list = [str(loc) for loc in profile["portLocations"]] for location in location_list: confidence = calc_confidence(profile, port_map, location) prof_result["portLocations"].append({ "location": location, "confidence": confidence.percent, "reason": confidence.reason}) result.append(prof_result) return result