python - unit testing with mock for google apps api - Admin Directory API -
i followed tutorial here , can retrive emails domain application.
now want write unit tests mock application, dont know start.
i have read here unit testing mock , google api admin directory api comes own mock library. dont understand how use correctly.
my application test_email_user.py contains import real application email_user.py what?
i have fake google api directory responses real application, how?
greetings, sam
i'm not familiar google client api own mock library mention mock library:
import mock class directoryhelper(): ... #real method calls api def get_users(self): user_list = [] request = self.service.users().list( customer=self.customer_id, maxresults=500, orderby='email', fields="nextpagetoken,users(id,orgunitpath,primaryemail,name(givenname,familyname),agreedtoterms,suspended)" ) while request: logging.debug('retrieving page of users directory...') report_document = request.execute() if 'users' in report_document: user in report_document['users']: user_list.append(user) request = self.service.users().list_next( request, report_document ) return user_list #mock method simulate api call def get_mock_users(self): return [ { "id": "12345", "primaryemail": "mock@domain.com", "name": { "givenname": u"mock", "familyname": u"user" }, "agreedtoterms": true, "suspended": false, "orgunitpath": "/" } ] @mock.patch.object(directoryhelper, 'get_users', get_mock_users) def test_sync_apps_users(self): directory_helper = directoryhelper() self.assertequals(1, len(directory_helper.get_users()), 'mock contain 1 user')
Comments
Post a Comment