Skip to content

Commit

Permalink
Merge pull request #451 from MyElectricalData/revert-449-only-unittests
Browse files Browse the repository at this point in the history
Revert "Ajout tests unitaires"
  • Loading branch information
m4dm4rtig4n authored Dec 22, 2023
2 parents e418f8b + 3733208 commit 662afe4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 147 deletions.
10 changes: 2 additions & 8 deletions app/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import logging
from math import floor
from os import environ, getenv, path
from os import environ, getenv

from art import decor, text2art

Expand All @@ -15,11 +15,6 @@
else:
APPLICATION_PATH_DATA = "/data"

if "CONFIG_PATH" in environ:
CONFIG_PATH = getenv("CONFIG_PATH")
else:
CONFIG_PATH = path.join(APPLICATION_PATH_DATA, "config.yaml")

paypal_footer = """
<div style="text-align: center" id="paypal" class="paypal_link">
<form action="https://www.paypal.com/donate" method="post" target="_top" style="height: 55px;" id="paypal_form">
Expand Down Expand Up @@ -135,8 +130,7 @@ def finish():


def get_version():
version_file = path.join(APPLICATION_PATH, "VERSION")
f = open(version_file, "r")
f = open("/app/VERSION", "r")
version = f.read()
f.close()
return version.strip()
Expand Down
13 changes: 6 additions & 7 deletions app/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
import yaml

from config import LOG_FORMAT, LOG_FORMAT_DATE
from dependencies import APPLICATION_PATH_DATA, CONFIG_PATH, str2bool
from dependencies import APPLICATION_PATH_DATA, str2bool
from models.config import Config
from models.database import Database
from models.influxdb import InfluxDB
from models.mqtt import Mqtt

# LOGGING CONFIGURATION
config = {}

if path.exists(CONFIG_PATH):
with open(CONFIG_PATH) as file:
if path.exists("/data/config.yaml"):
with open(f'/data/config.yaml') as file:
config = yaml.load(file, Loader=yaml.FullLoader)

if "DEBUG" in environ and str2bool(getenv("DEBUG")):
Expand All @@ -44,8 +43,8 @@
level=logging_level
)

if not path.exists(CONFIG_PATH):
logging.critical(f"Config file is not found ({CONFIG_PATH})")
if not path.exists("/data/config.yaml"):
logging.critical("Config file is not found (/data/config.yaml)")
exit()


Expand All @@ -69,7 +68,7 @@ def filter(self, record: logging.LogRecord) -> bool:
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')

CONFIG = Config(
path=CONFIG_PATH
path=APPLICATION_PATH_DATA
)
CONFIG.load()
CONFIG.display()
Expand Down
12 changes: 6 additions & 6 deletions app/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import yaml

from dependencies import title, separator, CONFIG_PATH
from dependencies import title, separator


class Config:

def __init__(self, path=CONFIG_PATH):
self.path = os.path.dirname(path) # Folder containing the config file
def __init__(self, path="/data"):
self.path = path
self.db = None
self.file = os.path.basename(path) # Name of the config file
self.file = "config.yaml"
self.path_file = f"{self.path}/{self.file}"
self.config = {}
self.default_port = 5000
Expand Down Expand Up @@ -128,14 +128,14 @@ def set_db(self, db):
def load(self):
config_file = f'{self.path_file}'
if os.path.exists(config_file):
with open(config_file) as file:
with open(f'{self.path}/config.yaml') as file:
self.config = yaml.load(file, Loader=yaml.FullLoader)

else:
f = open(config_file, "a")
f.write(yaml.dump(self.default))
f.close()
with open(config_file) as file:
with open(f'{self.path}/config.yaml') as file:
self.config = yaml.load(file, Loader=yaml.FullLoader)

if self.config is None:
Expand Down
20 changes: 4 additions & 16 deletions app/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlalchemy import (create_engine, delete, inspect, update, select, func, desc, asc)
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.pool import NullPool

from config import MAX_IMPORT_TRY
from db_schema import (
Config,
Expand All @@ -25,17 +26,14 @@
Ecowatt,
Statistique
)
from dependencies import str2bool, title, get_version, title_warning, APPLICATION_PATH_DATA, APPLICATION_PATH

from alembic.config import Config as AlembicConfig
from alembic import command
from dependencies import str2bool, title, get_version, title_warning

# available_database = ["sqlite", "postgresql", "mysql+pymysql"]
available_database = ["sqlite", "postgresql"]


class Database:
def __init__(self, config, path=APPLICATION_PATH_DATA):
def __init__(self, config, path="/data"):
self.config = config
self.path = path

Expand All @@ -50,17 +48,7 @@ def __init__(self, config, path=APPLICATION_PATH_DATA):
else:
logging.critical(f"Database {self.storage_type} not supported (only SQLite & PostgresSQL)")

# Use alembic commands rather than dropping into shell for running migrations
alembic_dir = os.path.join(APPLICATION_PATH, "alembic")
alembic_ini = os.path.join(APPLICATION_PATH, "alembic.ini")
alembic_cfg = AlembicConfig(alembic_ini)
alembic_cfg.set_main_option('script_location', alembic_dir)

# Define DB_URL envvar rather than using set_main_option so that command line
# migrations are still possible
os.environ["DB_URL"] = self.uri

command.upgrade(alembic_cfg, "head")
os.system(f"cd /app; DB_URL='{self.uri}' alembic upgrade head ")

self.engine = create_engine(
self.uri, echo=False,
Expand Down
9 changes: 4 additions & 5 deletions app/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ def __init__(self, usage_point_id=None):
def boot(self):
if ("DEV" in environ and getenv("DEV")) or ("DEBUG" in environ and getenv("DEBUG")):
logging.warning("=> Import job disable")
return False
else:
return self.job_import_data()["status"]
self.job_import_data()

def job_import_data(self, wait=True, target=None) -> dict:
def job_import_data(self, wait=True, target=None):
if self.db.lock_status():
return {
"status": False,
Expand Down Expand Up @@ -160,11 +159,11 @@ def header_generate(self, token=True):
output['Authorization'] = self.usage_point_config.token
return output

def get_gateway_status(self) -> dict:
def get_gateway_status(self):
detail = "Récupération du statut de la passerelle :"
try:
title(detail)
return Status(headers=self.header_generate(token=False)).ping()
Status(headers=self.header_generate(token=False)).ping()
except Exception as e:
traceback.print_exc()
logging.error(f"Erreur lors de la {detail.lower()}")
Expand Down
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

8 changes: 0 additions & 8 deletions tests/TESTING.md

This file was deleted.

95 changes: 0 additions & 95 deletions tests/test_jobs.py

This file was deleted.

0 comments on commit 662afe4

Please sign in to comment.