Skip to content

Commit

Permalink
Merge pull request #11023 from amaltaro/fix-11022
Browse files Browse the repository at this point in the history
Allow MongoDB to be instantiated without mongomock library
  • Loading branch information
amaltaro authored Mar 4, 2022
2 parents ac83e5f + c6f72ac commit 96af8ec
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/python/WMCore/Database/MongoDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@

# futures
from __future__ import division, print_function

from builtins import str, object

try:
import mongomock
except ImportError:
# this library should only be required by unit tests
mongomock = None

from pymongo import MongoClient, errors, IndexModel
import mongomock


class MongoDB(object):
"""
A simple wrapper class for creating a connection to a MongoDB instance
"""
def __init__(self,
database=None,
server=None,
port=None,
replicaset=None,
create=False,
collections=None,
testIndexes=False,
logger=None,
mockMongoDB=False,
**kwargs):
def __init__(self, database=None, server=None, port=None, replicaset=None,
create=False, collections=None, testIndexes=False,
logger=None, mockMongoDB=False, **kwargs):
"""
:databases: A database Name to connect to
:server: The server url (see https://docs.mongodb.com/manual/reference/connection-string/)
Expand All @@ -44,6 +40,10 @@ def __init__(self,
self.port = port # 8230
self.logger = logger
self.mockMongoDB = mockMongoDB
if mockMongoDB and mongomock is None:
msg = "You are trying to mock MongoDB, but you do not have mongomock in the python path."
self.logger.critical(msg)
raise ImportError(msg)
try:
if mockMongoDB:
self.client = mongomock.MongoClient()
Expand Down

0 comments on commit 96af8ec

Please sign in to comment.