Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- from apiclient.discovery import build
- from apiclient.http import HttpMock
- import original_file
- from apiclient.discovery import build
- class TestAdmin(unittest.TestCase):
- def setUp(self):
- server_response = 'Blah Blah Blah' # sample server response
- with open('http_response.json','w') as response_file:
- json.dump(server_response, response_file)
- def test_admin(self):
- http = HttpMock('http_response.json', {'status': '200'})
- api_key = 'api key created on google cloud'
- service_object = build('admin', 'directory_v1', http=http, developerKey=api_key)
- # The call to build should be made to a method
- # in the original class that implements the build service
- request = service_object.users().list(customer='my_customer', maxResults=1, orderBy='email',query='/')
- http = HttpMock('allusers.json', {'status': '200'})
- response = request.execute(http=http)
- self.assertEquals(response, server_response)
- def tearDown(self):
- # delete the temporary file created
- try:
- os.remove(self.user_response)
- except OSError:
- pass
- if __name__ == '__main__':
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement