Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
344b685094 | ||
|
1df005ea8a | ||
|
0908e64782 | ||
b9dcb2127e | |||
|
1ddc26f04f | ||
|
f9f508567d |
|
@ -20,11 +20,6 @@ class Configuration:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, db_name: str, dotenv_path: str, app_env='TEST'):
|
def __init__(self, db_name: str, dotenv_path: str, app_env='TEST'):
|
||||||
"""
|
|
||||||
:param db_name: database name
|
|
||||||
:param app_env: application environment, test or production
|
|
||||||
:param dotenv_path: the absolute path to dotenv file
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
# load environmental variables
|
# load environmental variables
|
||||||
if not Path(dotenv_path).exists():
|
if not Path(dotenv_path).exists():
|
||||||
|
|
|
@ -236,6 +236,13 @@ class DBControl:
|
||||||
def delete_application(self, application_uuid):
|
def delete_application(self, application_uuid):
|
||||||
"""
|
"""
|
||||||
Deletes a single application from the database
|
Deletes a single application from the database
|
||||||
:param application_uuid: the id of the application to get
|
:param application_uuid: the id of the application to delete
|
||||||
"""
|
"""
|
||||||
self._application.delete(application_uuid)
|
self._application.delete(application_uuid)
|
||||||
|
|
||||||
|
def get_city(self, city_id):
|
||||||
|
"""
|
||||||
|
Get a single city by id
|
||||||
|
:param city_id: the id of the city to get
|
||||||
|
"""
|
||||||
|
return self._city.get_by_id(city_id)
|
||||||
|
|
|
@ -23,14 +23,6 @@ class DBSetup:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, db_name, app_env, dotenv_path, admin_password, application_uuid):
|
def __init__(self, db_name, app_env, dotenv_path, admin_password, application_uuid):
|
||||||
"""
|
|
||||||
Creates database tables a default admin user and a default admin app with the given password and uuid
|
|
||||||
:param db_name: database name
|
|
||||||
:param app_env: application environment type [TEST|PROD]
|
|
||||||
:param dotenv_path: .env file path
|
|
||||||
:param admin_password: administrator password for the application uuid
|
|
||||||
:application_uuid: application uuid
|
|
||||||
"""
|
|
||||||
repository = Repository(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
|
repository = Repository(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
|
||||||
|
|
||||||
# Create the tables using the models
|
# Create the tables using the models
|
||||||
|
|
|
@ -16,7 +16,7 @@ from cerc_persistence.configuration import Models
|
||||||
|
|
||||||
class Application(Models):
|
class Application(Models):
|
||||||
"""
|
"""
|
||||||
A model representation of an application
|
Application(Models) class
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'application'
|
__tablename__ = 'application'
|
||||||
id = Column(Integer, Sequence('application_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('application_id_seq'), primary_key=True)
|
||||||
|
|
|
@ -14,7 +14,8 @@ from cerc_persistence.configuration import Models
|
||||||
|
|
||||||
|
|
||||||
class City(Models):
|
class City(Models):
|
||||||
"""A model representation of a city
|
"""
|
||||||
|
City(Models) class
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'city'
|
__tablename__ = 'city'
|
||||||
id = Column(Integer, Sequence('city_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('city_id_seq'), primary_key=True)
|
||||||
|
|
|
@ -17,7 +17,7 @@ from cerc_persistence.configuration import Models
|
||||||
|
|
||||||
class CityObject(Models):
|
class CityObject(Models):
|
||||||
"""
|
"""
|
||||||
A model representation of an application
|
CityObject(Models) class
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'city_object'
|
__tablename__ = 'city_object'
|
||||||
id = Column(Integer, Sequence('city_object_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('city_object_id_seq'), primary_key=True)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from cerc_persistence.configuration import Models
|
||||||
|
|
||||||
class SimulationResults(Models):
|
class SimulationResults(Models):
|
||||||
"""
|
"""
|
||||||
A model representation of an application
|
SimulationResults(Models) class
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'simulation_results'
|
__tablename__ = 'simulation_results'
|
||||||
id = Column(Integer, Sequence('simulation_results_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('simulation_results_id_seq'), primary_key=True)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class UserRoles(enum.Enum):
|
||||||
|
|
||||||
class User(Models):
|
class User(Models):
|
||||||
"""
|
"""
|
||||||
A model representation of a city
|
User(Models) class
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'user'
|
__tablename__ = 'user'
|
||||||
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
|
||||||
|
|
|
@ -18,7 +18,7 @@ from cerc_persistence.models import Application as Model
|
||||||
|
|
||||||
class Application(Repository):
|
class Application(Repository):
|
||||||
"""
|
"""
|
||||||
Application repository
|
Application(Repository) class
|
||||||
"""
|
"""
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
@ -26,9 +26,6 @@ class Application(Repository):
|
||||||
super().__init__(db_name, dotenv_path, app_env)
|
super().__init__(db_name, dotenv_path, app_env)
|
||||||
|
|
||||||
def __new__(cls, db_name, dotenv_path, app_env):
|
def __new__(cls, db_name, dotenv_path, app_env):
|
||||||
"""
|
|
||||||
Implemented for a singleton pattern
|
|
||||||
"""
|
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super(Application, cls).__new__(cls)
|
cls._instance = super(Application, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
|
@ -20,7 +20,7 @@ from cerc_persistence.models import CityObject
|
||||||
|
|
||||||
class City(Repository):
|
class City(Repository):
|
||||||
"""
|
"""
|
||||||
City repository
|
City(Repository) class
|
||||||
"""
|
"""
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ class City(Repository):
|
||||||
super().__init__(db_name, dotenv_path, app_env)
|
super().__init__(db_name, dotenv_path, app_env)
|
||||||
|
|
||||||
def __new__(cls, db_name, dotenv_path, app_env):
|
def __new__(cls, db_name, dotenv_path, app_env):
|
||||||
"""
|
|
||||||
Implemented for a singleton pattern
|
|
||||||
"""
|
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super(City, cls).__new__(cls)
|
cls._instance = super(City, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
@ -136,3 +133,7 @@ class City(Repository):
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logging.error('Error while fetching city by name %s', err)
|
logging.error('Error while fetching city by name %s', err)
|
||||||
raise SQLAlchemyError from err
|
raise SQLAlchemyError from err
|
||||||
|
|
||||||
|
def get_by_id(self, city_id) -> Model:
|
||||||
|
with Session(self.engine) as session:
|
||||||
|
return session.execute(select(Model).where(Model.id == city_id)).first()[0]
|
|
@ -19,7 +19,7 @@ from cerc_persistence.repository import Repository
|
||||||
|
|
||||||
class CityObject(Repository):
|
class CityObject(Repository):
|
||||||
"""
|
"""
|
||||||
City object repository
|
CityObject(Repository) class
|
||||||
"""
|
"""
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
@ -27,9 +27,6 @@ class CityObject(Repository):
|
||||||
super().__init__(db_name, dotenv_path, app_env)
|
super().__init__(db_name, dotenv_path, app_env)
|
||||||
|
|
||||||
def __new__(cls, db_name, dotenv_path, app_env):
|
def __new__(cls, db_name, dotenv_path, app_env):
|
||||||
"""
|
|
||||||
Implemented for a singleton pattern
|
|
||||||
"""
|
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super(CityObject, cls).__new__(cls)
|
cls._instance = super(CityObject, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
|
@ -20,7 +20,7 @@ from cerc_persistence.models import SimulationResults as Model
|
||||||
|
|
||||||
class SimulationResults(Repository):
|
class SimulationResults(Repository):
|
||||||
"""
|
"""
|
||||||
Simulation results repository
|
SimulationResults(Repository) class
|
||||||
"""
|
"""
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ class SimulationResults(Repository):
|
||||||
super().__init__(db_name, dotenv_path, app_env)
|
super().__init__(db_name, dotenv_path, app_env)
|
||||||
|
|
||||||
def __new__(cls, db_name, dotenv_path, app_env):
|
def __new__(cls, db_name, dotenv_path, app_env):
|
||||||
"""
|
|
||||||
Implemented for a singleton pattern
|
|
||||||
"""
|
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super(SimulationResults, cls).__new__(cls)
|
cls._instance = super(SimulationResults, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
|
@ -18,7 +18,7 @@ from cerc_persistence.models import User as Model, Application as ApplicationMod
|
||||||
|
|
||||||
class User(Repository):
|
class User(Repository):
|
||||||
"""
|
"""
|
||||||
User class
|
User(Repository) class
|
||||||
"""
|
"""
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
@ -26,9 +26,6 @@ class User(Repository):
|
||||||
super().__init__(db_name, dotenv_path, app_env)
|
super().__init__(db_name, dotenv_path, app_env)
|
||||||
|
|
||||||
def __new__(cls, db_name, dotenv_path, app_env):
|
def __new__(cls, db_name, dotenv_path, app_env):
|
||||||
"""
|
|
||||||
Implemented for a singleton pattern
|
|
||||||
"""
|
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
cls._instance = super(User, cls).__new__(cls)
|
cls._instance = super(User, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""
|
"""
|
||||||
CERC Persistence version number
|
CERC Persistence version number
|
||||||
"""
|
"""
|
||||||
__version__ = '1.0.0.1'
|
__version__ = '1.0.0.2'
|
||||||
|
|
|
@ -5,18 +5,9 @@ Copyright © 2022 Concordia CERC group
|
||||||
Project Coder Ruben Sanchez ruben.sanchez@mail.concordia.ca
|
Project Coder Ruben Sanchez ruben.sanchez@mail.concordia.ca
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import distutils.spawn
|
|
||||||
import os
|
|
||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy_utils import database_exists, create_database, drop_database
|
|
||||||
|
|
||||||
from cerc_persistence.db_control import DBControl
|
|
||||||
from cerc_persistence.repository import Repository
|
|
||||||
from cerc_persistence.models import City, Application, CityObject, SimulationResults, User
|
|
||||||
from unittests.control import Control
|
from unittests.control import Control
|
||||||
|
|
||||||
control = Control()
|
control = Control()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user