i have a function x in main.applications.handlers package
from main.config import get_db
def x(company_name):
db = get_db('my_db')
apps = []
for x in company_db.applications.find():
print(x)
apps.append(x)
return apps
now i want to write unittest for this method .
from unittest.mock import Mock,patch, MagicMock
@mock.patch('main.applications.handlers.get_db')
def test_show_applications_handler(self, mocked_db):
mocked_db.applications.find = MagicMock(return_value=[1,2,3])
apps = x('test_company') # apps should have [1,2,3] but its []
print(apps)
but company_db.applications.find() inside main.applications.handlers is not returning anything .it should return [1,2,3]
what could be wrong with this code?
apps = x('test_company')withfind?<MagicMock name='get_db().applications.find()' id='140565332675720'>when i doprint (company_db.applications.find())insidexmocked_db.return_value.applications.return_value.find.return_value = [1,2,3]but same resultcompany_dba typo? I can't see where that is defined. Presumably it should bedb?