CSAir

.idea
    .name 13 B
    Assignment2.0.iml 295 B
    dictionaries
       lantay77.xml 357 B
    encodings.xml 171 B
    misc.xml 348 B
    modules.xml 289 B
    runConfigurations
       Server.xml 1008 B
       Unittests_in_Tests.xml 1 KB
    scopes
       scope_settings.xml 143 B
    vcs.xml 189 B
    workspace.xml 59 KB
CSAir.py 11 KB
CSAir_helpers.py 9 KB
CSAir_json.py 7 KB
CSAir_server.py 5 KB
Graph
    DiGraph.py 9 KB
    Edge.py 518 B
    Node.py 360 B
Location.py 1 KB
ManualTestPlan.odt 441 KB
ManualTestPlan.pdf 1029 KB
Query.py 2 KB
README 499 B
Server.py 8 KB
Tests
    expected
       brief_print_expected.txt 13 B
       continents_expected.txt 58 B
       expected.json 1 KB
       hubs_expected.txt 70 B
       list_expected.txt 28 B
       longest_expected.txt 36 B
       other_expected.txt 205 B
       print_expected.txt 130 B
       shortest_expected.txt 37 B
    invalid.json 15 KB
    out
       brief_print_test.txt 13 B
       continents_test.txt 58 B
       hubs_test.txt 70 B
       list_test.txt 28 B
       longest_test.txt 36 B
       other_test.txt 205 B
       out.json 1 KB
       print_test.txt 130 B
       shortest_test.txt 37 B
    testCSAir.py 3 KB
    testFunctionsForServer.py 1 KB
    testGraph.py 1 KB
    testLocation.py 938 B
    testServer.py 6 KB
    test_2.1.py 8 KB
    valid.json 871 B
    valid2.json 582 B
add_city_post.py 800 B
changes 633 B
cmi_hub.json 1 KB
map_data.json 15 KB
map_data_r2.json 15 KB
static
    bootstrap.js 59 KB
    css
       bootstrap-theme.css 20 KB
       bootstrap-theme.css.map 22 KB
       bootstrap-theme.min.css 18 KB
       bootstrap.css 129 KB
       bootstrap.css.map 215 KB
       bootstrap.min.css 106 KB
       starter-template.css 186 B
    fonts
       glyphicons-halflings-regular.eot 19 KB
       glyphicons-halflings-regular.svg 61 KB
       glyphicons-halflings-regular.ttf 40 KB
       glyphicons-halflings-regular.woff 22 KB
    js
       bootstrap.js 59 KB
       bootstrap.min.js 31 KB
templates
    city.html 13 KB
    routes.html 10 KB
uploads
testServer.py
import unittest
import requests
import subprocess


class ServerTests(unittest.TestCase):
    def setUp(self):
        self.server_process = subprocess.Popen("C:\Python34\python.exe "
                                               "C:/Users/Lantay77/Documents/CS242/Assignment2.2/Server.py",
                                               cwd=r'C:\Users\lantay77\Documents\CS242\Assignment2.2')

    def tearDown(self):
        self.server_process.kill()

    def test_home(self):
        req = requests.get("http://127.0.0.1:5000/")
        assert "Longest flight: SYD to LAX. 12051km" in req.text
        assert "6 connections from: IST (Istanbul)" in req.text
        assert "Cities in South America:" in req.text

    def test_display_city(self):
        req = requests.get("http://127.0.0.1:5000/?code=atl")
        assert "Name: Atlanta" in req.text
        assert "Region: 3" in req.text
        assert "distance: 957" in req.text

    def test_display_invalid_city(self):
        req = requests.get("http://127.0.0.1:5000/?code=notvalid")
        assert "NOTVALID does not exist" in req.text

    def test_add_api(self):
        req = requests.get("http://127.0.0.1:5000/add_city?api=true&cityCode=CMI")
        assert "Name: Univ Of Illinois-Willard" in req.text
        assert "CMI successfully added from Wunderground API." in req.text

        req = requests.get("http://127.0.0.1:5000/add_city?api=true&cityCode=CMI")
        assert "Error: Unable to add CMI from API." in req.text

    def test_remove_city(self):
        req = requests.get("http://127.0.0.1:5000/?rm=MIA")
        assert "MIA successfully removed." in req.text
        assert "Miami" not in req.text

    def test_edit_city(self):
        req = requests.get("http://127.0.0.1:5000/add_city?cityCode=ATLA&cityName=Atlanta&cityCountry=US&cityContinent=North%20America&cityTimezone=-5&cityLatitude=34N&cityLongitude=84W&cityPop=5700000&cityRegion=3&edit=true&old_code=ATL")
        assert "Code: ATLA" in req.text
        assert "ATLA info:" in req.text
        assert "ATLA to" in req.text

    def test_add_city(self):
        req = requests.get("http://127.0.0.1:5000/add_city?cityCode=ATLA&cityName=Atlanta&cityCountry=US&cityContinent=North%20America&cityTimezone=-5&cityLatitude=34N&cityLongitude=84W&cityPop=5700000&cityRegion=3")
        assert "Code: ATLA" in req.text
        assert "ATLA info:" in req.text
        assert "Name: Atlanta" in req.text
        assert "No routes" in req.text

        req = requests.get("http://127.0.0.1:5000/add_city?cityCode=ATLA&cityName=Atlanta&cityCountry=US&cityContinent=North%20America&cityTimezone=-5&cityLatitude=34N&cityLongitude=84W&cityPop=5700000&cityRegion=3")
        assert "Error: Unable to add city, a city with the same code already exists." in req.text

    def test_invalid_add(self):
        req = requests.get("http://127.0.0.1:5000/add_city?cityCode=ATLA&cityName=Atlanta&cityCountry=US&cityContinent=North%20America&cityTimezone=-5&cityLatitude=AAA&cityLongitude=84H&cityPop=AA&cityRegion=3")
        assert "Error: Unable to add city, population must be a number." in req.text
        assert "Error: Invalid latitude letter" in req.text
        assert "Error: Invalid longitude letter" in req.text

    def test_edit_from_api(self):
        req = requests.get("http://127.0.0.1:5000/add_city?api=true&cityCode=LAX&edit=true&old_code=LAX")
        assert "Code: LAX" in req.text
        assert "Timezone: America/Los_Angeles" in req.text
        assert "Editing LAX succeeded:" in req.text
        assert "Name: Los Angeles International" in req.text

    def test_manual_route(self):
        req = requests.get("http://127.0.0.1:5000/routes?route=SCL-LIM-MEX")
        assert "SCL-LIM-MEX" in req.text
        assert "Total distance: 6684km" in req.text

        # test clear
        req = requests.get("http://127.0.0.1:5000/routes?clear=routes")
        assert "SCL-LIM-MEX" not in req.text

    def test_shortest_route(self):
        req = requests.get("http://127.0.0.1:5000/routes?source=MOW&dest=SCL")
        assert "MOW-LED-ESS-LON-NYC-WAS-MIA-BOG-LIM-SCL" in req.text
        assert "Total distance: 17001km" in req.text

    def test_noquery(self):
        req = requests.get("http://127.0.0.1:5000/routes?route=MOW-LED-ESS-LON-NYC-WAS-MIA-BOG-LIM-SCL&noquery=y")
        req = requests.get("http://127.0.0.1:5000/routes")
        assert "MOW-LED-ESS-LON-NYC-WAS-MIA-BOG-LIM-SCL" not in req.text

    def test_add_route(self):
        req = requests.get("http://127.0.0.1:5000/routes?source=LIM&dest=MOW&direction=false&distance=500&add=y")
        assert "LIM-MOW" in req.text
        assert "Total cost: $175.00" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=LIM")
        assert "distance: 500" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=MOW")
        assert "distance: 500" not in req.text

    def test_add_route_bidirectional(self):
        req = requests.get("http://127.0.0.1:5000/routes?source=LIM&dest=MOW&direction=true&distance=500&add=y")
        assert "LIM-MOW" in req.text
        assert "Total cost: $175.00" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=LIM")
        assert "distance: 500" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=MOW")
        assert "distance: 500" in req.text

    def test_rm_route(self):
        req = requests.get("http://127.0.0.1:5000/routes?source=LIM&dest=SCL&direction=false&rm=y")
        assert "Successfully removed route: LIM to SCL" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=LIM")
        assert "distance: 2453" not in req.text
        req = requests.get("http://127.0.0.1:5000/?code=SCL")
        assert "distance: 2453" in req.text

    def test_rm_route_bidirectional(self):
        req = requests.get("http://127.0.0.1:5000/routes?source=LIM&dest=SCL&direction=true&rm=y")
        assert "Successfully removed route: LIM to SCL" in req.text
        req = requests.get("http://127.0.0.1:5000/?code=LIM")
        assert "distance: 2453" not in req.text
        req = requests.get("http://127.0.0.1:5000/?code=SCL")
        assert "distance: 2453" not in req.text

if __name__ == '__main__':
    unittest.main()