Esempio n. 1
0
 def test_add_stops_table_adds_table(self, mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     c = handler.conn.cursor()
     c.execute("SELECT NAME FROM sqlite_master WHERE "
               "TYPE='table' and NAME='stops'")
     self.assertTrue(c.fetchone(), "stops table not created")
 def test_add_stops_table_adds_table(self,
                                     mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     c = handler.conn.cursor()
     c.execute("SELECT NAME FROM sqlite_master WHERE "
               "TYPE='table' and NAME='stops'")
     self.assertTrue(c.fetchone(), "stops table not created")
Esempio n. 3
0
 def test_get_all_stops_returns_list_of_MapLocations(self, mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     handler.add_stop(MapLocation(latitude=5, longitude=6))
     handler.add_stop(MapLocation(latitude=3, longitude=-5))
     stops = handler.get_all_stops()
     self.assertEqual((5, 6), (stops[0].latitude, stops[0].longitude))
     self.assertEqual((3, -5), (stops[1].latitude, stops[1].longitude))
Esempio n. 4
0
 def test_add_stop_uses_MapLocation_id_if_nonzero(self, mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     stop_location = MapLocation(latitude=0.48, longitude=179, id=888)
     handler.add_stop(stop_location)
     c = handler.conn.cursor()
     c.execute("SELECT * FROM stops")
     self.assertEqual(888, c.fetchone()[0])
 def test_get_all_stops_returns_list_of_MapLocations(self,
                                                     mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     handler.add_stop(MapLocation(latitude=5, longitude=6))
     handler.add_stop(MapLocation(latitude=3, longitude=-5))
     stops = handler.get_all_stops()
     self.assertEqual((5, 6), (stops[0].latitude, stops[0].longitude))
     self.assertEqual((3, -5), (stops[1].latitude, stops[1].longitude))
 def test_add_stop_uses_MapLocation_id_if_nonzero(self,
                                                  mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     stop_location = MapLocation(latitude=0.48, longitude=179, id=888)
     handler.add_stop(stop_location)
     c = handler.conn.cursor()
     c.execute("SELECT * FROM stops")
     self.assertEqual(888, c.fetchone()[0])
Esempio n. 7
0
 def test_add_stop_adds_to_stops_table(self, mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     map_location = MapLocation(latitude=-0.55, longitude=80)
     handler.add_stop(location=map_location)
     c = handler.conn.cursor()
     c.execute("SELECT latitude, longitude FROM stops")
     row = c.fetchone()
     self.assertEqual((-.55, 80), row)
 def test_add_stop_adds_to_stops_table(self,
                                       mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_stops_table()
     map_location = MapLocation(latitude=-0.55, longitude=80)
     handler.add_stop(location=map_location)
     c = handler.conn.cursor()
     c.execute("SELECT latitude, longitude FROM stops")
     row = c.fetchone()
     self.assertEqual((-.55, 80), row)
 def test_construct_db_calls_add_stop_table(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     mock_add_addresses = Mock()
     handler._add_addresses_table = mock_add_addresses
     mock_add_stops = Mock()
     handler._add_stops_table = mock_add_stops
     handler.initialize_db()
     self.assertTrue(mock_add_stops.called,
                     "initialize_db did not call _add_stops_table")
Esempio n. 10
0
 def test_construct_db_calls_add_stop_table(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     mock_add_addresses = Mock()
     handler._add_addresses_table = mock_add_addresses
     mock_add_stops = Mock()
     handler._add_stops_table = mock_add_stops
     handler.initialize_db()
     self.assertTrue(mock_add_stops.called,
                     "initialize_db did not call _add_stops_table")