class WagonTestCase(unittest.TestCase): wagon = Wagon('1234', '1') helper = Helper() @classmethod def setUpClass(cls): cls.api_thread = api.Api(config.HOST, cls.helper.get_port()) cls.api_thread.start() api.db.WagonDB.add_wagon(Wagon('HALLO', 0, 0, 0)) api.db.RegisterDB.register('HALLO', 1) time.sleep(1) @classmethod def tearDownClass(cls): cls.helper.shutdown_api() def test_get_wagon_id(self): id = '1234' assert_equal(self.wagon.get_id(), id) def test_get_last_camera(self): camera = '1' assert_equal(self.wagon.get_last_camera(), camera) def test_get_longitude(self): longitude = 0 assert_equal(self.wagon.get_longitude(), longitude) def test_get_latitude(self): latitude = 0 assert_equal(self.wagon.get_latitude(), latitude)
def register(wagon_id, camera_id): current_camera = WagonDB.get_by_id(wagon_id)[0].get_last_camera() if current_camera is not None and int(current_camera) is int( camera_id): return True else: w = Wagon(wagon_id, camera_id, datetime.datetime.now()) h = History(wagon_id, camera_id, datetime.datetime.now()) if WagonDB.update_last_camera_id(w) and HistoryDB.add_item(h): return True else: return False
def setUpClass(cls): cls.api_thread = api.Api(config.HOST, cls.helper.get_port()) cls.api_thread.start() api.db.WagonDB.add_wagon(Wagon('HALLO', 0, 0, 0)) api.db.RegisterDB.register('HALLO', 1) time.sleep(1)
def wagon_delete(wagon_id): w = Wagon(wagon_id) if db.WagonDB.delete_wagon(w): return jsonify({'message': 'success'}) else: return jsonify({'message': 'failed to delete wagon'})
def wagon_add(wagon_id): w = Wagon(wagon_id) if db.WagonDB.add_wagon(w): return jsonify({'message': 'success'}) else: return jsonify({'message': 'failed to add wagon'})
def wagon_pin(wagon_id, long, lat): w = Wagon(wagon_id, longitude=long, latitude=lat) if db.WagonDB.update_or_add_wagon_coordinates(w): return jsonify({'message': 'success'}) else: return jsonify({'message': 'failed to pin wagon'})
def __create_objects(query): return_list = [] for wagon in [i for i in query.cursor.fetchall()]: return_list.append(Wagon.from_json(wagon)) return return_list