summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/cmd/server.py
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2017-02-27 10:29:24 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-02-27 10:29:24 +0000
commit3e39454989eb51bb5754f11df101e2be734294c9 (patch)
treefd08062c5d458a70e51f1d29c9b2f9cd737b2e3b /utils/test/testapi/opnfv_testapi/cmd/server.py
parentc8d812d845c3db31dcab2c5083a3b45df9597ad3 (diff)
parent72d425437e176a966bfc4d43a116f8692ec859ba (diff)
Merge "make unittest cover server.py in TestAPI"
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/cmd/server.py')
-rw-r--r--utils/test/testapi/opnfv_testapi/cmd/server.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/utils/test/testapi/opnfv_testapi/cmd/server.py b/utils/test/testapi/opnfv_testapi/cmd/server.py
index 013ee6642..fa2b72250 100644
--- a/utils/test/testapi/opnfv_testapi/cmd/server.py
+++ b/utils/test/testapi/opnfv_testapi/cmd/server.py
@@ -30,6 +30,7 @@ TODOs :
"""
import argparse
+import sys
import motor
import tornado.ioloop
@@ -38,30 +39,34 @@ from opnfv_testapi.common import config
from opnfv_testapi.router import url_mappings
from opnfv_testapi.tornado_swagger import swagger
-# optionally get config file from command line
-parser = argparse.ArgumentParser()
-parser.add_argument("-c", "--config-file", dest='config_file',
- help="Config file location")
-args = parser.parse_args()
-CONF = config.APIConfig().parse(args.config_file)
+CONF = None
-# connecting to MongoDB server, and choosing database
-client = motor.MotorClient(CONF.mongo_url)
-db = client[CONF.mongo_dbname]
-swagger.docs(base_url=CONF.swagger_base_url)
+def parse_config(argv=[]):
+ global CONF
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-c", "--config-file", dest='config_file',
+ help="Config file location")
+ args = parser.parse_args(argv)
+ CONF = config.APIConfig().parse(args.config_file)
+
+
+def get_db():
+ return motor.MotorClient(CONF.mongo_url)[CONF.mongo_dbname]
def make_app():
+ swagger.docs(base_url=CONF.swagger_base_url)
return swagger.Application(
url_mappings.mappings,
- db=db,
+ db=get_db(),
debug=CONF.api_debug_on,
auth=CONF.api_authenticate_on
)
def main():
+ parse_config(sys.argv[1:])
application = make_app()
application.listen(CONF.api_port)
tornado.ioloop.IOLoop.current().start()