Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3 support #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/MongoDBLibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from mongo_connection_manager import MongoConnectionManager
from mongoquery import MongoQuery
from version import VERSION
from MongoDBLibrary.mongo_connection_manager import MongoConnectionManager
from MongoDBLibrary.mongoquery import MongoQuery
from MongoDBLibrary.version import VERSION


class MongoDBLibrary(MongoConnectionManager, MongoQuery):
Expand Down
12 changes: 6 additions & 6 deletions src/MongoDBLibrary/mongo_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def connect_to_mongodb(self, dbHost='localhost', dbPort=27017, dbMaxPoolSize=10,
Example usage:
| # To connect to foo.bar.org's MongoDB service on port 27017 |
| Connect To MongoDB | foo.bar.org | ${27017} |
| # Or for an authenticated connection, note addtion of "mongodb://" to host uri |
| Connect To MongoDB | mongodb://admin:[email protected] | ${27017} |
| # Or for an authenticated connection |
| Connect To MongoDB | admin:[email protected] | ${27017} |

"""
dbapiModuleName = 'pymongo'
Expand All @@ -37,9 +37,9 @@ def connect_to_mongodb(self, dbHost='localhost', dbPort=27017, dbMaxPoolSize=10,
#print "slave_okay is [ %s ]" % dbSlaveOkay
#print "document_class is [ %s ]" % dbDocClass
#print "tz_aware is [ %s ]" % dbTZAware
print "| Connect To MondoDB | dbHost | dbPort | dbMaxPoolSize | dbNetworktimeout | dbDocClass | dbTZAware |"
print "| Connect To MondoDB | %s | %s | %s | %s | %s | %s |" % (dbHost, dbPort, dbMaxPoolSize, dbNetworkTimeout,
dbDocClass, dbTZAware)
print ("| Connect To MondoDB | dbHost | dbPort | dbMaxPoolSize | dbNetworktimeout | dbDocClass | dbTZAware |")
print ("| Connect To MondoDB | %s | %s | %s | %s | %s | %s |" % (dbHost, dbPort, dbMaxPoolSize, dbNetworkTimeout,
dbDocClass, dbTZAware))

self._dbconnection = db_api_2.MongoClient(host=dbHost, port=dbPort, socketTimeoutMS=dbNetworkTimeout,
document_class=dbDocClass, tz_aware=dbTZAware,
Expand All @@ -52,5 +52,5 @@ def disconnect_from_mongodb(self):
For example:
| Disconnect From MongoDB | # disconnects from current connection to the MongoDB server |
"""
print "| Disconnect From MongoDB |"
print ("| Disconnect From MongoDB |")
self._dbconnection.close()
40 changes: 20 additions & 20 deletions src/MongoDBLibrary/mongoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_mongodb_databases(self):
| Should Contain | ${allDBs} | DBName |
"""
allDBs = self._dbconnection.database_names()
print "| @{allDBs} | Get Mongodb Databases |"
print ("| @{allDBs} | Get Mongodb Databases |")
return allDBs

def get_mongodb_collections(self, dbName):
Expand All @@ -38,7 +38,7 @@ def get_mongodb_collections(self, dbName):
except TypeError:
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
allCollections = db.collection_names()
print "| @{allCollections} | Get MongoDB Collections | %s |" % dbName
print ("| @{allCollections} | Get MongoDB Collections | %s |" % dbName)
return allCollections

def drop_mongodb_database(self, dbDelName):
Expand All @@ -52,7 +52,7 @@ def drop_mongodb_database(self, dbDelName):
| Should Not Contain | ${allDBs} | myDB |
"""
dbDelName = str(dbDelName)
print "| Drop MongoDB Database | %s |" % dbDelName
print ("| Drop MongoDB Database | %s |" % dbDelName)
try:
self._dbconnection.drop_database('%s' % dbDelName)
except TypeError:
Expand All @@ -74,7 +74,7 @@ def drop_mongodb_collection(self, dbName, dbCollName):
except TypeError:
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
db.drop_collection('%s' % dbCollName)
print "| Drop MongoDB Collection | %s | %s |" % (dbName, dbCollName)
print ("| Drop MongoDB Collection | %s | %s |" % (dbName, dbCollName))

def validate_mongodb_collection(self, dbName, dbCollName):
"""
Expand All @@ -92,7 +92,7 @@ def validate_mongodb_collection(self, dbName, dbCollName):
except TypeError:
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
allResults = db.validate_collection('%s' % dbCollName)
print "| ${allResults} | Validate MongoDB Collection | %s | %s |" % (dbName, dbCollName)
print ("| ${allResults} | Validate MongoDB Collection | %s | %s |" % (dbName, dbCollName))
return allResults

def get_mongodb_collection_count(self, dbName, dbCollName):
Expand All @@ -111,7 +111,7 @@ def get_mongodb_collection_count(self, dbName, dbCollName):
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
coll = db['%s' % dbCollName]
count = coll.count()
print "| ${allResults} | Get MongoDB Collection Count | %s | %s |" % (dbName, dbCollName)
print ("| ${allResults} | Get MongoDB Collection Count | %s | %s |" % (dbName, dbCollName))
return count

def save_mongodb_records(self, dbName, dbCollName, recordJSON):
Expand Down Expand Up @@ -143,7 +143,7 @@ def save_mongodb_records(self, dbName, dbCollName, recordJSON):
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
coll = db['%s' % dbCollName]
allResults = coll.save(recordJSON)
print "| ${allResults} | Save MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON)
print ("| ${allResults} | Save MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON))
return allResults

def update_many_mongodb_records(self, dbName, dbCollName, queryJSON, updateJSON, upsert=False):
Expand All @@ -169,9 +169,9 @@ def update_many_mongodb_records(self, dbName, dbCollName, queryJSON, updateJSON,
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
coll = db['%s' % collection_name]
allResults = coll.update_many(query_json, update_json, upsert=upsert)
print "Matched: %i documents" % allResults.matched_count
print "| ${allResults} | Update Many MongoDB Records | %s | %s | %s | %s |" % (
dbName, dbCollName, query_json, update_json)
print ("Matched: %i documents" % allResults.matched_count)
print ("| ${allResults} | Update Many MongoDB Records | %s | %s | %s | %s |" % (
dbName, dbCollName, query_json, update_json))
return allResults.modified_count

def retrieve_all_mongodb_records(self, dbName, dbCollName, returnDocuments=False):
Expand Down Expand Up @@ -199,7 +199,7 @@ def retrieve_some_mongodb_records(self, dbName, dbCollName, recordJSON, returnDo
| Log | ${allResults} |
| Should Contain X Times | ${allResults} | '${recordNo1}' | 1 |
"""
print "| ${allResults} | Retrieve Some MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON)
print ("| ${allResults} | Retrieve Some MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON))
return self._retrieve_mongodb_records(dbName, dbCollName, recordJSON, returnDocuments=returnDocuments)

def retrieve_and_update_one_mongodb_record(self, dbName, dbCollName, queryJSON, updateJSON,
Expand Down Expand Up @@ -228,12 +228,12 @@ def retrieve_and_update_one_mongodb_record(self, dbName, dbCollName, queryJSON,
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
coll = db['%s' % dbcollname]
all_results = coll.find_one_and_update(record_json, update_json, return_document=document_to_return)
print "| ${allResults} | Retrieve And Update One Mongodb Record | %s | %s | %s | %s | %s" % (
dbname,
dbcollname,
queryJSON,
updateJSON,
returnBeforeDocument)
print ("| ${allResults} | Retrieve And Update One Mongodb Record | %s | %s | %s | %s | %s" % (
dbname,
dbcollname,
queryJSON,
updateJSON,
returnBeforeDocument))
return all_results

def retrieve_mongodb_records_with_desired_fields(self, dbName, dbCollName, recordJSON, fields, return__id=True,
Expand Down Expand Up @@ -304,8 +304,8 @@ def retrieve_mongodb_records_with_desired_fields(self, dbName, dbCollName, recor
else:
data = []

print "| ${allResults} | retreive_mongodb_records_with_desired_fields | %s | %s | %s | %s | %s |" % (
dbName, dbCollName, recordJSON, fields, return__id)
print ("| ${allResults} | retreive_mongodb_records_with_desired_fields | %s | %s | %s | %s | %s |" % (
dbName, dbCollName, recordJSON, fields, return__id))
return self._retrieve_mongodb_records(dbName, dbCollName, recordJSON, data, returnDocuments)

def _retrieve_mongodb_records(self, dbName, dbCollName, recordJSON, fields=[], returnDocuments=False):
Expand Down Expand Up @@ -359,5 +359,5 @@ def remove_mongodb_records(self, dbName, dbCollName, recordJSON):
self._builtin.fail("Connection failed, please make sure you have run 'Connect To Mongodb' first.")
coll = db['%s' % dbCollName]
allResults = coll.remove(recordJSON)
print "| ${allResults} | Remove MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON)
print ("| ${allResults} | Remove MongoDB Records | %s | %s | %s |" % (dbName, dbCollName, recordJSON))
return allResults