correct API
This commit is contained in:
parent
ec90dd1e0d
commit
52bb8afa13
@ -8,6 +8,7 @@ import platform
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from hub.persistence.db_control import DBControl
|
from hub.persistence.db_control import DBControl
|
||||||
|
from hub.persistence.repository import Repository
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -21,7 +22,12 @@ class Config:
|
|||||||
database_name = 'montreal_retrofit_test'
|
database_name = 'montreal_retrofit_test'
|
||||||
|
|
||||||
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
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
|
@property
|
||||||
def database(self):
|
def database(self):
|
||||||
return self._database
|
return self._database
|
||||||
|
|
||||||
|
@property
|
||||||
|
def repository(self):
|
||||||
|
return self._repository
|
||||||
|
@ -39,16 +39,14 @@ class SessionStart(Resource, Config):
|
|||||||
'application_id': user_info.application_id,
|
'application_id': user_info.application_id,
|
||||||
'application_uuid': application_uuid,
|
'application_uuid': application_uuid,
|
||||||
'ip': ip,
|
'ip': ip,
|
||||||
'cities': []
|
'scenarios': []
|
||||||
}
|
}
|
||||||
cities = self.database.cities_by_user_and_application(user_info.id, user_info.application_id)
|
cities = self.database.cities_by_user_and_application(user_info.id, user_info.application_id)
|
||||||
for city in cities:
|
for city in cities:
|
||||||
session['cities'].append({
|
if city.scenario not in session['scenarios']:
|
||||||
"name": city.name,
|
session['scenarios'].append(city.scenario)
|
||||||
"geometric_level_of_detail": city.level_of_detail
|
|
||||||
})
|
|
||||||
sessions[session_id] = session
|
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['session_id'] = session_id
|
||||||
response.headers['token'] = token
|
response.headers['token'] = token
|
||||||
return response
|
return response
|
||||||
|
@ -288,9 +288,9 @@ components:
|
|||||||
result:
|
result:
|
||||||
type: string
|
type: string
|
||||||
example: 'succeed'
|
example: 'succeed'
|
||||||
cities:
|
scenarios:
|
||||||
type: array
|
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:
|
retrofit-results:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -24,9 +24,11 @@ def expired_sessions_collector(session_timeout_duration):
|
|||||||
while True:
|
while True:
|
||||||
if bool(sessions):
|
if bool(sessions):
|
||||||
for _session in list(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():
|
if _expire < datetime.datetime.now():
|
||||||
print("session with session_id: ", session, "expired.")
|
print("session for user: ", _session['username'], "expired.")
|
||||||
|
|
||||||
del sessions[session]
|
del sessions[session]
|
||||||
time.sleep(60 * int(session_timeout_duration))
|
time.sleep(60 * int(session_timeout_duration))
|
||||||
|
|
||||||
|
16
hub_api/tests/test_api.py
Normal file
16
hub_api/tests/test_api.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user