From 2a3afef135638a54ed97a15f7b99ffb947157be4 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Wed, 16 Jun 2021 17:08:12 +0200 Subject: [PATCH] code clean --- app_decoder.py | 4 +--- docker_files/init.sh | 4 ++-- test/test_front.py | 9 +++------ test/utils.py | 10 +++++++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app_decoder.py b/app_decoder.py index ecd34b5..5160105 100755 --- a/app_decoder.py +++ b/app_decoder.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import json -import logging import os import traceback from urllib import request @@ -105,14 +104,13 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code, msg += res2.text except: pass - logging.error(msg) + logger.error(msg) Exception(msg) # Psacc psacc = MyPSACC(None, client_id, client_secret, REMOTE_REFRESH_TOKEN, customer_id, BRAND[package_name]["realm"], country_code) psacc.connect(client_email, client_password) - psacc.save_config(name=config_prefix + "config.json") res = psacc.get_vehicles() print(f"\nYour vehicles: {res}") diff --git a/docker_files/init.sh b/docker_files/init.sh index ec680ac..0abb4cb 100644 --- a/docker_files/init.sh +++ b/docker_files/init.sh @@ -1,4 +1,4 @@ #!/bin/bash echo "Containerised psa_car_controller loading..." -cd $PSACC_CONFIG_DIR -python3 /psa_car_controller/server.py -p $PSACC_PORT -l 0.0.0.0 -b $PSACC_BASE_PATH $PSACC_OPTIONS +cd "$PSACC_CONFIG_DIR" +python3 /psa_car_controller/server.py -p "$PSACC_PORT" -l 0.0.0.0 -b "$PSACC_BASE_PATH" "$PSACC_OPTIONS" diff --git a/test/test_front.py b/test/test_front.py index 6767d1d..cc6e341 100644 --- a/test/test_front.py +++ b/test/test_front.py @@ -37,7 +37,7 @@ def openTab(driver, n): def getDriver(): chrome_options = Options() - if not os.environ.get("NO_HEADLESS", "0") == "1": + if os.environ.get("NO_HEADLESS", "0") != "1": chrome_options.add_argument("--headless") driver = webdriver.Chrome(options=chrome_options) driver.implicitly_wait(10) @@ -79,9 +79,6 @@ class ServerThread(threading.Thread): class FrontTest(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def test_trips_only(self): get_new_test_db() driver = getDriver() @@ -103,8 +100,8 @@ class FrontTest(unittest.TestCase): record_charging() flask_app.start() wait_for_start(driver, URL) - assert "-" != driver.find_element_by_id("avg_emission_kw") - assert "18.6" == driver.find_element_by_id("avg_chg_speed").text + assert driver.find_element_by_id("avg_emission_kw") != "-" + assert driver.find_element_by_id("avg_chg_speed").text == "18.6" openTab(driver, 2) assert "18.86 kWh" in driver.find_element_by_id("battery-table").text flask_app.stop() diff --git a/test/utils.py b/test/utils.py index 5dc2ab9..4a41a50 100644 --- a/test/utils.py +++ b/test/utils.py @@ -21,26 +21,30 @@ date4 = date3 + timedelta(minutes=1) vehicule_list = Cars() vehicule_list.extend( [Car("VR3UHZKX", "vid", "Peugeot"), Car("VXXXXX", "XXXX", "Peugeot", label="SUV 3008")]) -car=vehicule_list[0] +car = vehicule_list[0] DB_DIR = DATA_DIR + "tmp.db" + + def get_new_test_db(): try: os.remove(DATA_DIR + "tmp.db") - except: + except FileNotFoundError: pass Database.DEFAULT_DB_FILE = DB_DIR Database.db_initialized = False conn = Database.get_db() return conn + def record_position(): Database.record_position(None, car.vin, 11, latitude, longitude - 0.05, None, date0, 40, None, False) Database.record_position(None, car.vin, 20, latitude, longitude, 32, date1, 35, None, False) Database.record_position(None, car.vin, 30, latitude, longitude, 42, date2, 30, None, False) + def record_charging(): Charging.record_charging(car, "InProgress", date0, 50, latitude, longitude, "FR", "slow", 20, 60) Charging.record_charging(car, "InProgress", date1, 75, latitude, longitude, "FR", "slow", 20, 60) Charging.record_charging(car, "InProgress", date2, 85, latitude, longitude, "FR", "slow", 20, 60) Charging.record_charging(car, "InProgress", date3, 90, latitude, longitude, "FR", "slow", 20, 60) - Charging.record_charging(car, "Stopped", date4, 91, latitude, longitude, "FR", "slow", 20, 60) \ No newline at end of file + Charging.record_charging(car, "Stopped", date4, 91, latitude, longitude, "FR", "slow", 20, 60)