I defined a class that as following:
class Parameter(object):
def __init__(self ):
self.parser = ArgumentParser()
self.parser.add_argument("-db", type = str , action= "store", dest = "database", required=True)
self.parser.add_argument("-coll", type=str, action="store", dest="collection", required=True)
self.parser.add_argument("-sys", type=bool, action="store", dest="system", default="TRUE")
self.args = self.parser.parse_args()
def checkArgs(self, connect):
right = True
with MongoConnection(connect) as conMongo:
all_dbs = conMongo.conMongo.database_names()
if self.args.database not in all_dbs:
right = False
raise ValueError("\nThe given database name does not exists.\n" % (self.args.database))
return right
if __name__ == '__main__':
connection = 'server connection information'
params = Parameter()
try:
params.checkArgs(connection)
except ValueError as e:
print(e)
How can I write a unit test for this Class that checks if the given db name by the user actually exists in the database server?
Aucun commentaire:
Enregistrer un commentaire