Correct unit tests
This commit is contained in:
parent
f91c10cc70
commit
83dda1e6e0
|
@ -1,4 +1,4 @@
|
||||||
"""
|
"""
|
||||||
CERC Persistence version number
|
CERC Persistence version number
|
||||||
"""
|
"""
|
||||||
__version__ = '0.1.0.2'
|
__version__ = '0.1.0.3'
|
||||||
|
|
|
@ -7,21 +7,15 @@ Project Coder Peter Yefi peteryefi@gmail.com
|
||||||
import distutils.spawn
|
import distutils.spawn
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import psycopg2
|
|
||||||
import sqlalchemy.exc
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy.exc import ProgrammingError
|
|
||||||
from sqlalchemy_utils import database_exists, create_database, drop_database
|
|
||||||
|
|
||||||
|
|
||||||
import hub.helpers.constants as cte
|
import hub.helpers.constants as cte
|
||||||
|
import sqlalchemy.exc
|
||||||
|
from sqlalchemy_utils import database_exists, create_database, drop_database
|
||||||
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||||
from hub.exports.exports_factory import ExportsFactory
|
from hub.exports.exports_factory import ExportsFactory
|
||||||
from hub.helpers.data.montreal_function_to_hub_function import MontrealFunctionToHubFunction
|
from hub.helpers.data.montreal_function_to_hub_function import MontrealFunctionToHubFunction
|
||||||
|
@ -31,6 +25,8 @@ from hub.imports.geometry_factory import GeometryFactory
|
||||||
from hub.imports.results_factory import ResultFactory
|
from hub.imports.results_factory import ResultFactory
|
||||||
from hub.imports.usage_factory import UsageFactory
|
from hub.imports.usage_factory import UsageFactory
|
||||||
from hub.imports.weather_factory import WeatherFactory
|
from hub.imports.weather_factory import WeatherFactory
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
from cerc_persistence.db_control import DBControl
|
from cerc_persistence.db_control import DBControl
|
||||||
from cerc_persistence.models import City, Application, CityObject, SimulationResults
|
from cerc_persistence.models import City, Application, CityObject, SimulationResults
|
||||||
from cerc_persistence.models import User, UserRoles
|
from cerc_persistence.models import User, UserRoles
|
||||||
|
@ -55,7 +51,7 @@ class Control:
|
||||||
self._skip_reason = f'.env file missing at {dotenv_path}'
|
self._skip_reason = f'.env file missing at {dotenv_path}'
|
||||||
return
|
return
|
||||||
dotenv_path = str(dotenv_path)
|
dotenv_path = str(dotenv_path)
|
||||||
repository = Repository(db_name='test_db', app_env='TEST', dotenv_path=dotenv_path)
|
repository = Repository(db_name='persistence_test_db', app_env='TEST', dotenv_path=dotenv_path)
|
||||||
engine = create_engine(repository.configuration.connection_string)
|
engine = create_engine(repository.configuration.connection_string)
|
||||||
if database_exists(engine.url):
|
if database_exists(engine.url):
|
||||||
drop_database(engine.url)
|
drop_database(engine.url)
|
||||||
|
|
|
@ -6,17 +6,17 @@ Project Coder Ruben Sanchez ruben.sanchez@mail.concordia.ca
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import distutils.spawn
|
import distutils.spawn
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import sqlalchemy.exc
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.exc import ProgrammingError
|
from sqlalchemy_utils import database_exists, create_database, drop_database
|
||||||
|
|
||||||
from cerc_persistence.db_control import DBControl
|
from cerc_persistence.db_control import DBControl
|
||||||
from cerc_persistence.repository import Repository
|
from cerc_persistence.repository import Repository
|
||||||
|
from cerc_persistence.models import City, Application, CityObject, SimulationResults, User
|
||||||
|
|
||||||
|
|
||||||
class Control:
|
class Control:
|
||||||
|
@ -37,18 +37,16 @@ class Control:
|
||||||
self._skip_reason = f'.env file missing at {dotenv_path}'
|
self._skip_reason = f'.env file missing at {dotenv_path}'
|
||||||
return
|
return
|
||||||
dotenv_path = str(dotenv_path)
|
dotenv_path = str(dotenv_path)
|
||||||
repository = Repository(db_name='montreal_retrofit_test', app_env='TEST', dotenv_path=dotenv_path)
|
repository = Repository(db_name='persistence_test_db', app_env='TEST', dotenv_path=dotenv_path)
|
||||||
engine = create_engine(repository.configuration.connection_string)
|
engine = create_engine(repository.configuration.connection_string)
|
||||||
try:
|
if database_exists(engine.url):
|
||||||
# delete test database if it exists
|
drop_database(engine.url)
|
||||||
connection = engine.connect()
|
create_database(engine.url)
|
||||||
connection.close()
|
Application.__table__.create(bind=engine, checkfirst=True)
|
||||||
except ProgrammingError:
|
User.__table__.create(bind=engine, checkfirst=True)
|
||||||
logging.info('Database does not exist. Nothing to delete')
|
City.__table__.create(bind=engine, checkfirst=True)
|
||||||
except sqlalchemy.exc.OperationalError as operational_error:
|
CityObject.__table__.create(bind=engine, checkfirst=True)
|
||||||
self._skip_test = True
|
SimulationResults.__table__.create(bind=engine, checkfirst=True)
|
||||||
self._skip_reason = f'{operational_error}'
|
|
||||||
return
|
|
||||||
|
|
||||||
self._database = DBControl(
|
self._database = DBControl(
|
||||||
db_name=repository.configuration.db_name,
|
db_name=repository.configuration.db_name,
|
||||||
|
@ -125,4 +123,7 @@ class TestDBFactory(TestCase):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
results = control.database.results(control.user_id, control.application_id, request_values)
|
results = control.database.results(control.user_id, control.application_id, request_values)
|
||||||
print(results)
|
scenarios = ['current status', 'skin retrofit', 'system retrofit and pv', 'skin and system retrofit with pv']
|
||||||
|
for key, value in results.items():
|
||||||
|
self.assertTrue(key in scenarios, 'Wrong key value')
|
||||||
|
self.assertEqual(len(value), 0, 'wrong number of results')
|
Loading…
Reference in New Issue
Block a user