Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import unittest
  2. from apiclient.discovery import build
  3. from apiclient.http import HttpMock
  4. import original_file
  5. from apiclient.discovery import build
  6.  
  7. class TestAdmin(unittest.TestCase):
  8. def setUp(self):
  9. server_response = 'Blah Blah Blah' # sample server response
  10. with open('http_response.json','w') as response_file:
  11. json.dump(server_response, response_file)
  12.  
  13. def test_admin(self):
  14. http = HttpMock('http_response.json', {'status': '200'})
  15. api_key = 'api key created on google cloud'
  16. service_object = build('admin', 'directory_v1', http=http, developerKey=api_key)
  17.  
  18. # The call to build should be made to a method
  19. # in the original class that implements the build service
  20.  
  21. request = service_object.users().list(customer='my_customer', maxResults=1, orderBy='email',query='/')
  22. http = HttpMock('allusers.json', {'status': '200'})
  23. response = request.execute(http=http)
  24. self.assertEquals(response, server_response)
  25.  
  26. def tearDown(self):
  27. # delete the temporary file created
  28. try:
  29. os.remove(self.user_response)
  30. except OSError:
  31. pass
  32.  
  33. if __name__ == '__main__':
  34. unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement