correct API

This commit is contained in:
Guille Gutierrez 2023-07-28 08:26:02 -04:00
parent ec90dd1e0d
commit 52bb8afa13
5 changed files with 32 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import platform
from pathlib import Path
from hub.persistence.db_control import DBControl
from hub.persistence.repository import Repository
class Config:
@ -21,7 +22,12 @@ class Config:
database_name = 'montreal_retrofit_test'
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
@property
def database(self):
return self._database
@property
def repository(self):
return self._repository

View File

@ -39,16 +39,14 @@ class SessionStart(Resource, Config):
'application_id': user_info.application_id,
'application_uuid': application_uuid,
'ip': ip,
'cities': []
'scenarios': []
}
cities = self.database.cities_by_user_and_application(user_info.id, user_info.application_id)
for city in cities:
session['cities'].append({
"name": city.name,
"geometric_level_of_detail": city.level_of_detail
})
if city.scenario not in session['scenarios']:
session['scenarios'].append(city.scenario)
sessions[session_id] = session
response = Response(json.dumps({'cities': session['cities'], 'result': 'OK'}), status=200)
response = Response(json.dumps({'scenarios': session['scenarios'], 'result': 'OK'}), status=200)
response.headers['session_id'] = session_id
response.headers['token'] = token
return response

View File

@ -288,9 +288,9 @@ components:
result:
type: string
example: 'succeed'
cities:
scenarios:
type: array
example: [{'name': 'city 1', 'geometric_level_of_detail': '1'}, {'name': 'city 2', 'geometric_level_of_detail': '1'}]
example: ["current status", "skin retrofit", "system retrofit and pv", "skin and system retrofit with pv" ]
retrofit-results:
type: object
properties:

View File

@ -24,9 +24,11 @@ def expired_sessions_collector(session_timeout_duration):
while True:
if bool(sessions):
for _session in list(sessions):
_expire = datetime.datetime.strptime(sessions[session]['expire'], '%Y-%m-%d %H:%M:%S.%f')
print(_session)
_expire = datetime.datetime.strptime(_session['expire'], '%Y-%m-%d %H:%M:%S.%f')
if _expire < datetime.datetime.now():
print("session with session_id: ", session, "expired.")
print("session for user: ", _session['username'], "expired.")
del sessions[session]
time.sleep(60 * int(session_timeout_duration))

16
hub_api/tests/test_api.py Normal file
View File

@ -0,0 +1,16 @@
from unittest import TestCase
from hub_api.config import Config
from hub.persistence.models import City, Application, CityObject, SimulationResults, User
class TestApi(TestCase):
def test_create_database(self):
config = Config()
Application.__table__.create(bind=config.repository.engine, checkfirst=True)
User.__table__.create(bind=config.repository.engine, checkfirst=True)
City.__table__.create(bind=config.repository.engine, checkfirst=True)
CityObject.__table__.create(bind=config.repository.engine, checkfirst=True)
SimulationResults.__table__.create(bind=config.repository.engine, checkfirst=True)
config.database.create_user('Administrator', )
self.assertTrue(True)