diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2016-06-01 15:36:17 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2016-06-01 16:21:46 +0800 |
commit | a55651eb098da2e1aa90c93294a59857711b48c1 (patch) | |
tree | 654e3adace1e4ae1690d9612c5d7b1704a607a5e /utils/test/result_collection_api/common | |
parent | e0d66ea067ea59724c1dc300abe8052d4dcf88d1 (diff) |
project-ize testAPI
JIRA: FUNCTEST-284
Change-Id: I219e934bb11f50de84df2aa0345ecc7885223491
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/result_collection_api/common')
-rw-r--r-- | utils/test/result_collection_api/common/__init__.py | 8 | ||||
-rw-r--r-- | utils/test/result_collection_api/common/config.py | 91 | ||||
-rw-r--r-- | utils/test/result_collection_api/common/constants.py | 15 |
3 files changed, 0 insertions, 114 deletions
diff --git a/utils/test/result_collection_api/common/__init__.py b/utils/test/result_collection_api/common/__init__.py deleted file mode 100644 index 05c0c9392..000000000 --- a/utils/test/result_collection_api/common/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -############################################################################## -# Copyright (c) 2015 Orange -# guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## diff --git a/utils/test/result_collection_api/common/config.py b/utils/test/result_collection_api/common/config.py deleted file mode 100644 index 369bdd248..000000000 --- a/utils/test/result_collection_api/common/config.py +++ /dev/null @@ -1,91 +0,0 @@ -############################################################################## -# Copyright (c) 2015 Orange -# guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# feng.xiaowei@zte.com.cn remove prepare_put_request 5-30-2016 -############################################################################## - - -from ConfigParser import SafeConfigParser, NoOptionError - - -class ParseError(Exception): - """ - Custom exception class for config file - """ - - def __init__(self, message): - self.msg = message - - def __str__(self): - return 'error parsing config file : %s' % self.msg - - -class APIConfig: - """ - The purpose of this class is to load values correctly from the config file. - Each key is declared as an attribute in __init__() and linked in parse() - """ - - def __init__(self): - self._default_config_location = "config.ini" - self.mongo_url = None - self.mongo_dbname = None - self.api_port = None - self.api_debug_on = None - self._parser = None - - def _get_parameter(self, section, param): - try: - return self._parser.get(section, param) - except NoOptionError: - raise ParseError("[%s.%s] parameter not found" % (section, param)) - - def _get_int_parameter(self, section, param): - try: - return int(self._get_parameter(section, param)) - except ValueError: - raise ParseError("[%s.%s] not an int" % (section, param)) - - def _get_bool_parameter(self, section, param): - result = self._get_parameter(section, param) - if str(result).lower() == 'true': - return True - if str(result).lower() == 'false': - return False - - raise ParseError( - "[%s.%s : %s] not a boolean" % (section, param, result)) - - @staticmethod - def parse(config_location=None): - obj = APIConfig() - - if config_location is None: - config_location = obj._default_config_location - - obj._parser = SafeConfigParser() - obj._parser.read(config_location) - if not obj._parser: - raise ParseError("%s not found" % config_location) - - # Linking attributes to keys from file with their sections - obj.mongo_url = obj._get_parameter("mongo", "url") - obj.mongo_dbname = obj._get_parameter("mongo", "dbname") - - obj.api_port = obj._get_int_parameter("api", "port") - obj.api_debug_on = obj._get_bool_parameter("api", "debug") - - return obj - - def __str__(self): - return "mongo_url = %s \n" \ - "mongo_dbname = %s \n" \ - "api_port = %s \n" \ - "api_debug_on = %s \n" % (self.mongo_url, - self.mongo_dbname, - self.api_port, - self.api_debug_on) diff --git a/utils/test/result_collection_api/common/constants.py b/utils/test/result_collection_api/common/constants.py deleted file mode 100644 index 4d39a142d..000000000 --- a/utils/test/result_collection_api/common/constants.py +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################## -# Copyright (c) 2015 Orange -# guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -DEFAULT_REPRESENTATION = "application/json" -HTTP_BAD_REQUEST = 400 -HTTP_FORBIDDEN = 403 -HTTP_NOT_FOUND = 404 -HTTP_OK = 200 |