testFunctionsForServer.py
import unittest
from CSAir_server import *
class ServerFunctionTests(unittest.TestCase):
def test_n_to_br(self):
string = "Hello\nWorld!"
assert "Hello<br />World!" in n_to_br(string)
def test_gen_route_list(self):
route_str = "LIM-SCL-MIA"
route_list = generate_route_list(route_str)
assert route_list[0] == 'LIM'
assert route_list[1] == 'SCL'
assert route_list[2] == 'MIA'
def test_shortest_route(self):
graph = parse_json('../map_data.json')
log = ServerLog()
route_list = generate_shortest_route(graph, 'SCL', 'MEX', None, None, log)
assert route_list[0] == 'SCL'
assert route_list[1] == 'LIM'
assert route_list[2] == 'MEX'
assert "Found shortest route between SCL and MEX" in log.get_log()
def test_gen_route_string(self):
route_list = []
route_list.append('LIM')
route_list.append('SCL')
route_list.append('MIA')
assert "LIM-SCL-MIA" == generate_route_string(route_list)
def test_generate_map_url_from_list(self):
graph = parse_json('../map_data.json')
route_list = []
route_list.append('LIM')
route_list.append('SCL')
route_list.append('MIA')
assert "http://www.gcmap.com/map?P=LIM-SCL%0D%0ASCL-MIA%0D%0A&MS=wls&MR=1800&MX=720x360&PM=*" == generate_map_url_from_list(graph, route_list)
def test_gen_city_menu(self):
graph = parse_json('../map_data.json')
menu = generate_city_menu(graph)
assert "BGW (Bagdad)" in menu
assert "HKG (Hong Kong)" in menu
if __name__ == '__main__':
unittest.main()