diff --git a/src/MongoDBLibrary/__init__.py b/src/MongoDBLibrary/__init__.py index 369a2c5..bf73531 100644 --- a/src/MongoDBLibrary/__init__.py +++ b/src/MongoDBLibrary/__init__.py @@ -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): diff --git a/src/MongoDBLibrary/mongo_connection_manager.py b/src/MongoDBLibrary/mongo_connection_manager.py index ff5efcc..7a6aa9a 100644 --- a/src/MongoDBLibrary/mongo_connection_manager.py +++ b/src/MongoDBLibrary/mongo_connection_manager.py @@ -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:admin@foo.bar.org | ${27017} | + | # Or for an authenticated connection | + | Connect To MongoDB | admin:admin@foo.bar.org | ${27017} | """ dbapiModuleName = 'pymongo' @@ -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, @@ -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() diff --git a/src/MongoDBLibrary/mongoquery.py b/src/MongoDBLibrary/mongoquery.py index 33baed5..38820fe 100644 --- a/src/MongoDBLibrary/mongoquery.py +++ b/src/MongoDBLibrary/mongoquery.py @@ -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): @@ -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): @@ -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: @@ -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): """ @@ -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): @@ -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): @@ -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): @@ -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): @@ -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, @@ -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, @@ -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): @@ -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