Commit 6beae18d authored by Chris Wacek's avatar Chris Wacek
Browse files

Added testcases to start to address #7924.

This bug is really strange. It only occurs when running through
Apache. The testcases pass, and the server performs correctly
when running under Foreman.
parent 4a998817
Loading
Loading
Loading
Loading

testing/__init__.py

0 → 100644
+0 −0

Empty file added.

testing/app_tests.py

0 → 100644
+53 −0
Original line number Original line Diff line number Diff line
import unittest
import json
from app import app

class TestCase(unittest.TestCase):
  def setUp(self):
    app.config['TESTING'] = True
    app.config["TESTING_DATAFILE"] = "testing/testdata.json"
    self.app = app.test_client()

  def tearDown(self):
    pass

  def test_empty_query(self):
    response = self.app.get("/result.json")
    expected = json.loads(open("testing/expectations/noparam.expected").read())
    received = json.loads(response.data)
    self.assertItemsEqual(received,expected)


  def test_select_nonexistent_AS(self):
    received= json.loads(self.app.get("/result.json?ases=AS3320").data)
    expected = json.loads(
"""
{"total": {"fp": "", "index": null, "as_no": "", "nick": "", "cc": "", "p_exit": 0.0, "adv_bw": 0.0, "guard": "", "link": true, "p_guard": 0.0, "p_middle": 0.0, "exit": "", "as_info": "", "cw": 0.0, "as_name": ""}, "results": [], "excluded": null}
"""
    )
    self.assertItemsEqual(received,expected)

  def test_select_AS_by_number(self):
    received = json.loads(self.app.get("/result.json?ases=7922").data)
    expected = json.loads(
      """
      {"total": {"fp": "", "index": null, "as_no": "", "nick": "(total in selection)", "cc": "", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "", "link": true, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "", "as_info": "", "cw": 0.0017691999999999999, "as_name": ""}, "results": [{"fp": "CE9CC720B9300FC7E041CCC2B749F283AB5EE1C2", "index": 1, "as_no": "AS7922", "nick": "Tornearse", "cc": "US", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "Exit", "as_info": "AS7922 Comcast Cable Communications, Inc.", "cw": 0.0017691999999999999, "as_name": "Comcast Cable Communications, Inc."}], "excluded": null}
      """)
    self.assertItemsEqual(received,expected)

  def test_select_AS_with_label(self):
    received = json.loads(self.app.get("/result.json?ases=AS7922").data)
    expected = json.loads(
      """
      {"total": {"fp": "", "index": null, "as_no": "", "nick": "(total in selection)", "cc": "", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "", "link": true, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "", "as_info": "", "cw": 0.0017691999999999999, "as_name": ""}, "results": [{"fp": "CE9CC720B9300FC7E041CCC2B749F283AB5EE1C2", "index": 1, "as_no": "AS7922", "nick": "Tornearse", "cc": "US", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "Exit", "as_info": "AS7922 Comcast Cable Communications, Inc.", "cw": 0.0017691999999999999, "as_name": "Comcast Cable Communications, Inc."}], "excluded": null}
      """)
    self.assertItemsEqual(received,expected)

  def test_limit_dataset_size(self):
    received = json.loads(self.app.get("/result.json?top=5").data)
    self.assertEqual(len(received['results']),5)
    expected = json.loads(open("testing/expectations/top5.expected").read())
    self.assertItemsEqual(received,expected)

if __name__ == '__main':
  unittest.main()
+2 −0
Original line number Original line Diff line number Diff line
A set of datafiles used by the unit tests in the parent directory to validate
responses
+1 −0
Original line number Original line Diff line number Diff line
{"total": {"fp": "", "index": null, "as_no": "", "nick": "(total in selection)", "cc": "", "p_exit": 0.4316067, "adv_bw": 0.506811, "guard": "", "link": true, "p_guard": 0.28806119999999996, "p_middle": 0.7357851999999999, "exit": "", "as_info": "", "cw": 0.4851612000000001, "as_name": ""}, "results": [{"fp": "C3D1F08204E2BF81C6A426F312AE3A2212C78929", "index": 1, "as_no": "AS2914", "nick": "AkamaiTor2", "cc": "US", "p_exit": 0.3723334, "adv_bw": 0.324054, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.7142592, "exit": "Exit", "as_info": "AS2914 NTT America, Inc.", "cw": 0.362209, "as_name": "NTT America, Inc."}, {"fp": "9DD5F90D641D835C4FCA7153148B156E6FD49CEE", "index": 2, "as_no": "AS24940", "nick": "darwinfish", "cc": "DE", "p_exit": 0.0, "adv_bw": 0.11225429999999999, "guard": "Guard", "link": null, "p_guard": 0.27480109999999996, "p_middle": 0.0, "exit": "-", "as_info": "AS24940 Hetzner Online AG RZ", "cw": 0.0915991, "as_name": "Hetzner Online AG RZ"}, {"fp": "B9CEB5B18C76976F7703C67258D73FD8AB1F5DE6", "index": 3, "as_no": "AS8737", "nick": "rappie", "cc": "NL", "p_exit": 0.0490314, "adv_bw": 0.045077099999999995, "guard": "Guard", "link": null, "p_guard": 0.0116007, "p_middle": 0.0116008, "exit": "Exit", "as_info": "AS8737 KPN Internet Solutions", "cw": 0.0240775, "as_name": "KPN Internet Solutions"}, {"fp": "88F340708E4A44A5207B2133EA3A997D843EE04A", "index": 4, "as_no": "AS30186", "nick": "Greenwald", "cc": "CA", "p_exit": 0.007013599999999999, "adv_bw": 0.0056127, "guard": "Guard", "link": null, "p_guard": 0.0016594000000000001, "p_middle": 0.0016594000000000001, "exit": "Exit", "as_info": "AS30186 Toqen LLC", "cw": 0.0034441, "as_name": "Toqen LLC"}, {"fp": "CE9CC720B9300FC7E041CCC2B749F283AB5EE1C2", "index": 5, "as_no": "AS7922", "nick": "Tornearse", "cc": "US", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "Exit", "as_info": "AS7922 Comcast Cable Communications, Inc.", "cw": 0.0017691999999999999, "as_name": "Comcast Cable Communications, Inc."}, {"fp": "AB41EECA8422F0953BDE0D86AE089CB8D194A369", "index": 6, "as_no": "??", "nick": "Communist", "cc": "RU", "p_exit": 0.0014097, "adv_bw": 0.0113377, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0027042999999999998, "exit": "Exit", "as_info": "?? ??", "cw": 0.0013714, "as_name": "??"}, {"fp": "CD99F2579AEDB38E9A28C448340D502DE4050433", "index": 7, "as_no": "AS21844", "nick": "pillowfight", "cc": "US", "p_exit": 0.0, "adv_bw": 0.0014032, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.000848, "exit": "-", "as_info": "AS21844 ThePlanet.com Internet Services, Inc.", "cw": 0.00028260000000000004, "as_name": "ThePlanet.com Internet Services, Inc."}, {"fp": "015636CF409A1C32A578C0D50E4AC659ABA9E8A3", "index": 8, "as_no": "AS7385", "nick": "nigeria", "cc": "US", "p_exit": 0.0, "adv_bw": 0.0005613, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0006280999999999999, "exit": "-", "as_info": "AS7385 Integra Telecom, Inc.", "cw": 0.00020940000000000002, "as_name": "Integra Telecom, Inc."}, {"fp": "B4D40C3FBCBF65D680D8F99F4F9BAB325D47E7F9", "index": 9, "as_no": "AS16276", "nick": "Unnamed", "cc": "??", "p_exit": 0.0, "adv_bw": 0.0011225, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0005967, "exit": "-", "as_info": "AS16276 OVH Systems", "cw": 0.00019889999999999998, "as_name": "OVH Systems"}], "excluded": null}
+1 −0
Original line number Original line Diff line number Diff line
{"total": {"fp": "", "index": null, "as_no": "", "nick": "(total in selection)", "cc": "", "p_exit": 0.4316067, "adv_bw": 0.506811, "guard": "", "link": true, "p_guard": 0.28806119999999996, "p_middle": 0.7357851999999999, "exit": "", "as_info": "", "cw": 0.4851612000000001, "as_name": ""}, "results": [{"fp": "C3D1F08204E2BF81C6A426F312AE3A2212C78929", "index": 1, "as_no": "AS2914", "nick": "AkamaiTor2", "cc": "US", "p_exit": 0.3723334, "adv_bw": 0.324054, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.7142592, "exit": "Exit", "as_info": "AS2914 NTT America, Inc.", "cw": 0.362209, "as_name": "NTT America, Inc."}, {"fp": "9DD5F90D641D835C4FCA7153148B156E6FD49CEE", "index": 2, "as_no": "AS24940", "nick": "darwinfish", "cc": "DE", "p_exit": 0.0, "adv_bw": 0.11225429999999999, "guard": "Guard", "link": null, "p_guard": 0.27480109999999996, "p_middle": 0.0, "exit": "-", "as_info": "AS24940 Hetzner Online AG RZ", "cw": 0.0915991, "as_name": "Hetzner Online AG RZ"}, {"fp": "B9CEB5B18C76976F7703C67258D73FD8AB1F5DE6", "index": 3, "as_no": "AS8737", "nick": "rappie", "cc": "NL", "p_exit": 0.0490314, "adv_bw": 0.045077099999999995, "guard": "Guard", "link": null, "p_guard": 0.0116007, "p_middle": 0.0116008, "exit": "Exit", "as_info": "AS8737 KPN Internet Solutions", "cw": 0.0240775, "as_name": "KPN Internet Solutions"}, {"fp": "88F340708E4A44A5207B2133EA3A997D843EE04A", "index": 4, "as_no": "AS30186", "nick": "Greenwald", "cc": "CA", "p_exit": 0.007013599999999999, "adv_bw": 0.0056127, "guard": "Guard", "link": null, "p_guard": 0.0016594000000000001, "p_middle": 0.0016594000000000001, "exit": "Exit", "as_info": "AS30186 Toqen LLC", "cw": 0.0034441, "as_name": "Toqen LLC"}, {"fp": "CE9CC720B9300FC7E041CCC2B749F283AB5EE1C2", "index": 5, "as_no": "AS7922", "nick": "Tornearse", "cc": "US", "p_exit": 0.0018185999999999999, "adv_bw": 0.005388199999999999, "guard": "-", "link": null, "p_guard": 0.0, "p_middle": 0.0034887, "exit": "Exit", "as_info": "AS7922 Comcast Cable Communications, Inc.", "cw": 0.0017691999999999999, "as_name": "Comcast Cable Communications, Inc."}], "excluded": {"fp": "", "index": null, "as_no": "", "nick": "(4 other relays)", "cc": "", "p_exit": 0.0014097, "adv_bw": 0.0144247, "guard": "", "link": true, "p_guard": 0.0, "p_middle": 0.004777099999999999, "exit": "", "as_info": "", "cw": 0.0020623, "as_name": ""}}
Loading