diff --git a/aircot/functions.py b/aircot/functions.py index 96f8e36..410d55b 100644 --- a/aircot/functions.py +++ b/aircot/functions.py @@ -172,7 +172,7 @@ def set_friendly_mil(icao: int, attitude: str = "u", affil: str = "") -> tuple: if icao_in_known_range(icao, "MIL"): affil = "M" attitude = "f" - return affil, attitude + return attitude, affil def set_neutral_civ(icao: int, attitude: str = "u", affil: str = "") -> tuple: @@ -180,7 +180,7 @@ def set_neutral_civ(icao: int, attitude: str = "u", affil: str = "") -> tuple: if icao_in_known_range(icao): affil = "C" attitude = "n" - return affil, attitude + return attitude, affil def is_known_country_icao(icao: int, attitude: str = "u"): @@ -238,16 +238,26 @@ def get_speed(gs: float = 0.0): return str(speed) -def set_name_callsign(icao: str, reg, craft_type, flight, known_craft={}): +def set_name_callsign(icao: str, reg=None, craft_type=None, flight=None, known_craft={}): + """ + Sets the Name and Callsign of the CoT Event. + Populates the fields with ICAO, Reg, Craft Type and Flight data, if available. + """ name: str = known_craft.get("CALLSIGN") if name: callsign = name else: name = f"ICAO-{icao}" - if flight: + if flight and reg and craft_type: callsign = "-".join([flight.strip().upper(), reg, craft_type]) - else: + elif reg and craft_type: callsign = "-".join([reg, craft_type]) + elif reg: + callsign = reg + elif flight: + callsign = flight.strip().upper() + else: + callsign = name return name, callsign diff --git a/tests/test_aircot.py b/tests/test_aircot.py index 1d50a2f..0f8abcd 100644 --- a/tests/test_aircot.py +++ b/tests/test_aircot.py @@ -77,14 +77,14 @@ def test_icao_in_range(): def test_set_neutral_civ(): icao = 0xC80000 # NZ-CIV Range - affil, attitude = aircot.functions.set_neutral_civ(icao) + attitude, affil = aircot.functions.set_neutral_civ(icao) assert affil == "C" assert attitude == "n" def test_negative_set_neutral_civ(): icao = 0xC87F00 # NZ-MIL Range - affil, attitude = aircot.functions.set_neutral_civ(icao) + attitude, affil = aircot.functions.set_neutral_civ(icao) assert "" == affil assert "u" == attitude @@ -97,14 +97,14 @@ def test_icao_in_range_mil(): def test_set_friendly_mil(): icao = 0xC87F00 # NZ-MIL Range - affil, attitude = aircot.functions.set_friendly_mil(icao) + attitude, affil = aircot.functions.set_friendly_mil(icao) assert affil == "M" assert attitude == "f" def test_negative_set_friendly_mil(): icao = 0xC80000 # NZ-CIV Range - affil, attitude = aircot.functions.set_friendly_mil(icao) + attitude, affil = aircot.functions.set_friendly_mil(icao) assert "" == affil assert "u" == attitude @@ -166,3 +166,73 @@ def test_negative_get_speed(): gs = "" speed = aircot.functions.get_speed(gs) assert speed == "9999999.0" + + +def test_negative_set_neutral_civ_lux(): + icao = 0x4D0223 # from sn + affil, attitude = aircot.functions.set_neutral_civ(icao) + assert "u" == affil + assert "" == attitude + + +def test_adsb_to_cot_type_lux(): + icao = 0x4D0223 + category = "1" + flight = "SVW20E" + cot_type = aircot.adsb_to_cot_type(icao, category, flight) + assert "a-n-A-C-F" == cot_type + + +def test_set_name_callsign_icao(): + #icao: str, reg, craft_type, flight, known_craft = {} + icao = "icao123" + reg = "reg123" + craft_type = "craft_type123" + flight = "flight123" + name, callsign = aircot.set_name_callsign(icao) + assert "ICAO-icao123" == name + assert "ICAO-icao123" == callsign + + +def test_set_name_callsign_icao_reg(): + #icao: str, reg, craft_type, flight, known_craft = {} + icao = "icao123" + reg = "reg123" + craft_type = "craft_type123" + flight = "flight123" + name, callsign = aircot.set_name_callsign(icao, reg) + assert "ICAO-icao123" == name + assert "reg123" == callsign + + +def test_set_name_callsign_icao_reg_craft_type(): + #icao: str, reg, craft_type, flight, known_craft = {} + icao = "icao123" + reg = "reg123" + craft_type = "craft_type123" + flight = "flight123" + name, callsign = aircot.set_name_callsign(icao, reg, craft_type) + assert "ICAO-icao123" == name + assert "reg123-craft_type123" == callsign + + +def test_set_name_callsign_icao_reg_craft_type_flight(): + #icao: str, reg, craft_type, flight, known_craft = {} + icao = "icao123" + reg = "reg123" + craft_type = "craft_type123" + flight = "flight123" + name, callsign = aircot.set_name_callsign(icao, reg, craft_type, flight) + assert "ICAO-icao123" == name + assert "FLIGHT123-reg123-craft_type123" == callsign + + +def test_set_name_callsign_icao_flight(): + #icao: str, reg, craft_type, flight, known_craft = {} + icao = "icao123" + reg = "reg123" + craft_type = "craft_type123" + flight = "flight123" + name, callsign = aircot.set_name_callsign(icao, flight=flight) + assert "ICAO-icao123" == name + assert "FLIGHT123" == callsign \ No newline at end of file