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
testCSAir.py
import unittest
import sys
import filecmp

from CSAir import *


class CSAir_tests(unittest.TestCase):

    #def setUp(self):
     #   self.graph = DiGraph.DiGraph()
    def setUp(self):
        self.graph = parse_json('valid.json')

    def tearDown(self):
        self.graph.clear()

    def test_parse_notfound(self):
        assert parse_json('notafile') is False

    def test_parse_invalid_json(self):
        assert parse_json('invalid.json') is False

    def test_parse(self):
        graph = parse_json('valid.json')
        assert graph is not False

        nodes = graph.get_nodes()
        #for node in nodes:
        assert nodes[0] == "SCL"
        assert nodes[1] == "LIM"

        edges = graph.get_edges()
        assert edges[0].get_source() == "SCL"
        assert edges[1].get_source() == "LIM"

    #def test_url(self):
    #    url = "http://www.gcmap.com/map?P=SCL-LIM%0D%0ALIM-SCL%0D%0A"
    #    assert url == generate_map_url(self.graph)

    def test_list(self):
        temp = sys.stdout
        sys.stdout = open('out/list_test.txt', 'w')
        list_locations(self.graph)
        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/list_test.txt', 'expected/list_expected.txt') is True

    def test_lookup(self):
        assert "Code: SCL" in lookup(self.graph, "SCL")

        assert "Population: 6000000" in lookup(self.graph, "SCL")

    def test_invalid_lookup(self):
        assert "not found" in lookup(self.graph, "NOTVALID")

    def test_longest(self):
        temp = sys.stdout
        sys.stdout = open('out/longest_test.txt', 'w')
        print(print_longest(self.graph))
        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/longest_test.txt', 'expected/longest_expected.txt') is True

    def test_shortest(self):
        temp = sys.stdout
        sys.stdout = open('out/shortest_test.txt', 'w')
        print(print_shortest(self.graph))
        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/shortest_test.txt', 'expected/shortest_expected.txt') is True

    def test_other_prints(self):
        temp = sys.stdout
        sys.stdout = open('out/other_test.txt', 'w')

        print(print_average(self.graph))
        print(print_smallest_city(self.graph))
        print(print_largest_city(self.graph))
        print(print_average_city(self.graph))

        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/other_test.txt', 'expected/other_expected.txt') is True

    def test_hubs(self):
        temp = sys.stdout
        sys.stdout = open('out/hubs_test.txt', 'w')
        print(print_hubs(self.graph))
        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/hubs_test.txt', 'expected/hubs_expected.txt') is True

    def test_continents(self):
        temp = sys.stdout
        sys.stdout = open('out/continents_test.txt', 'w')
        print(print_continents(self.graph))
        sys.stdout.close()
        sys.stdout = temp

        assert filecmp.cmp('out/continents_test.txt', 'expected/continents_expected.txt') is True


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