I have a script called commons.py which contains some most commonly used functions.
In my main script, I am creating a mongo connection object:
db_ob = commons.db_connection()
db_connection returns a MongoReplicaSetClient connection object.
how to write test cases for my below function??
def check_entries():
try:
db_ob = commons.db_connection()
except:
print('Unable to connect to db!!')
return False
db_name = 'my_db_name'
collection_name = 'my_collection_name'
db_data = db_ob[db_name][collection_name].find()
if db_data.count() == 0:
print('No entries found in the collection!')
return False
return True
I can mock my db_connection function but I am having problem mocking the .count() and .find() functions.
Aucun commentaire:
Enregistrer un commentaire