Minor fixes to Mongo DB client
* Two method calls define dictionary as arg in param signature. Set arg to None, and check value in body. if arg is none, then set value to empty dictionary. * 'Filter' argument shadows actual python call. Changed variable name to minimize damage (best practices), but did not change signature in case keyword arg invocation exists somewhere in code base. * __init__() call did not call parent's init (BaseClient) * Fixed pep8 violations found by flake in data_interfaces.py Change-Id: Ifb1c58854e2da60c5725e09f0dba3440d723bf00
This commit is contained in:
parent
3079061ae0
commit
8c234e2f3f
@ -140,9 +140,10 @@ class ConfigParserDataSource(DataSource):
|
||||
super(ConfigParserDataSource, self).__init__()
|
||||
|
||||
cafe_env_var = {key: value for key, value in os.environ.iteritems()
|
||||
if key.startswith('CAFE_')}
|
||||
if key.startswith('CAFE_')}
|
||||
|
||||
self._data_source = configparser.SafeConfigParser(defaults=cafe_env_var)
|
||||
self._data_source = configparser.SafeConfigParser(
|
||||
defaults=cafe_env_var)
|
||||
self._section_name = section_name
|
||||
|
||||
# Check if the path exists
|
||||
|
@ -26,6 +26,7 @@ class BaseMongoClient(BaseClient):
|
||||
_log = cclogging.getLogger(__name__)
|
||||
|
||||
def __init__(self, hostname, db_name, username, password):
|
||||
super(BaseMongoClient, self).__init__()
|
||||
self.hostname = hostname
|
||||
self.db_name = db_name
|
||||
self.username = username
|
||||
@ -96,16 +97,18 @@ class BaseMongoClient(BaseClient):
|
||||
|
||||
return self.SUCCESS
|
||||
|
||||
def find_one(self, db_obj_name, filter=dict()):
|
||||
def find_one(self, db_obj_name, filter=None):
|
||||
result_filter = filter or dict()
|
||||
if not self.is_connected():
|
||||
return self.FAILED
|
||||
|
||||
db_obj = self.db[db_obj_name]
|
||||
return db_obj.find_one(filter)
|
||||
return db_obj.find_one(result_filter)
|
||||
|
||||
def delete(self, db_obj_name, filter=dict(), just_one=True):
|
||||
def delete(self, db_obj_name, filter=None, just_one=True):
|
||||
result_filter = filter or dict()
|
||||
if not self.is_connected():
|
||||
return self.FAILED
|
||||
|
||||
db_obj = self.db[db_obj_name]
|
||||
return db_obj.remove(filter, just_one)
|
||||
return db_obj.remove(result_filter, just_one)
|
||||
|
Loading…
x
Reference in New Issue
Block a user