class RouteDataTest(TestCase): def setUp(self): self.data = RouteData() self.db = self.data.db def test_version(self): self.assertEqual(self.data.version, '20110905') def test_get_country(self): self.assertRaises(CountryError, self.data.get_countrynum, 'URW') self.assertEqual(self.data.get_countrynum('JP'), '392') self.assertEqual(self.data.get_countrynum('DE'), '276') self.assertEqual(self.data.get_countrynum('de'), '276') def test_read_depots(self): c = self.db.cursor() c.execute("""SELECT * FROM depots WHERE DepotNumber=?""", ('0015', )) rows = c.fetchall() self.assertEqual(1, len(rows)) self.assertEqual( ('0015', '', '', 'Betriebsgesellschaft DPD GmbH', '', 'Otto-Hahn-Strasse 5', '', '59423', 'Unna', 'DE', '+49-(0) 23 03-8 88-0', '+49-(0) 23 03-8 88-31', '', ''), rows[0]) def test_expand_depots(self): c = self.db.cursor() c.execute("""SELECT id FROM routes WHERE DestinationCountry='DE' AND BeginPostCode='42477'""" ) rows = c.fetchall() # Interestingly we sometimes get two routes # self.assertEqual(1, len(rows)) route = rows[0][0] c.execute("SELECT depot FROM routedepots WHERE route=?", (route, )) rows = c.fetchall() self.assertEqual(1, len(rows)) def test_get_service(self): self.assertEqual(self.data.get_service('180'), ('180', 'AM1-NO', '', '022,160', '')) self.assertRaises(ServiceError, self.data.get_service, '100000') def test_get_servicetext(self): text = self.data.get_servicetext('185') self.assertEqual('DPD 10:00 Unfrei / ex works', text) def test_translate_location(self): self.assertEqual('1', self.data.translate_location('Dublin', 'IE')) self.assertRaises(TranslationError, self.data.translate_location, 'Cahir', 'IE')
class RouteDataTest(TestCase): def setUp(self): self.data = RouteData() self.db = self.data.db def test_version(self): self.assertEqual(self.data.version, '20100503') def test_get_country(self): self.assertRaises(CountryError, self.data.get_countrynum, 'URW') self.assertEqual(self.data.get_countrynum('JP'), '392') self.assertEqual(self.data.get_countrynum('DE'), '276') self.assertEqual(self.data.get_countrynum('de'), '276') def test_read_depots(self): c = self.db.cursor() c.execute("""SELECT * FROM depots WHERE DepotNumber=?""", ('0015', )) rows = c.fetchall() self.assertEqual(1, len(rows)) self.assertEqual(('0015', '', '', 'Betriebsgesellschaft DPD Deutscher', '', 'Otto-Hahn-Strasse 5', '', '59423', 'Unna', 'DE', '+49-(0) 23 03-8 88-0', '+49-(0) 23 03-8 88-31', '', ''), rows[0]) def test_expand_depots(self): c = self.db.cursor() c.execute("""SELECT id FROM routes WHERE DestinationCountry='DE' AND BeginPostCode='42477'""") rows = c.fetchall() # Interestingly we sometimes get two routes # self.assertEqual(1, len(rows)) route = rows[0][0] c.execute("SELECT depot FROM routedepots WHERE route=?", (route, )) rows = c.fetchall() self.assertEqual(1, len(rows)) def test_get_service(self): self.assertEqual(self.data.get_service('180'), ('180', 'AM1-NO', '', '022,160', '')) self.assertRaises(ServiceError, self.data.get_service, '100000') def test_get_servicetext(self): text = self.data.get_servicetext('185') self.assertEqual('DPD 10:00 Unfrei / ex works', text) def test_translate_location(self): self.assertEqual('1', self.data.translate_location('Dublin', 'IE')) self.assertRaises(TranslationError, self.data.translate_location, 'Cahir', 'IE')
def setUp(self): self.data = RouteData() self.db = self.data.db
def setUp(self): self.data = RouteData() self.router = Router(self.data)
'o_sort': '78', 'serviceinfo': '', 'barcode_id': '37', 'grouping_priority': '', 'country': 'CH', 'countrynum': '756', 'routingtable_version': '20110905', 'iata_code': '', 'd_sort': '', 'postcode': '8440', 'd_depot': '0617', 'service_text': 'D' }) def test_cache(self): self.assertEqual(vars(get_route('LI', '8440')), vars(get_route_without_cache('LI', '8440'))) if __name__ == '__main__': start = time.time() router = Router(RouteData()) stamp = time.time() router.route(Destination('AT', '4240', 'Freistadt Österreich')).routingdata() end = time.time() # print ("took %.3fs to find a single route (including %.3fs initialisation overhead)" # % (end-start, stamp-start)) unittest.main()