# Path: helpers/google_api.py
# class GoogleAPIException(Exception):
# def oauth2_flow(**kwargs):
# def http_from_oauth2(auth_json):
# def user_info(auth_json):
# def drive_service():
# def list_drive_files(auth_json, query="", page_token=None):
# def get_worksheets(auth_json, spreadsheet_key):
# def get_cell_data(auth_json, spreadsheet_key, worksheet_key, limit=None):
# def create_spreadsheet(auth_json, title=""):
# def create_worksheet(auth_json, spreadsheet_key):
# def save_data(auth_json, spreadsheet_key, worksheet_key, data=[[]]):
# def _key(heading):
# def _val(val):    #::::....|...                       ___(_)
# 
# Path: tests/utils.py
# class MockHttp(object):
#     def __init__(self, cache=None, timeout=None, proxy_info=None, ca_certs=None, disable_ssl_certificate_validation=False):
#         pass
# 
#     def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
# 
#         # Response for oAuth2 Handshake
#         if 'https://accounts.google.com/o/oauth2/token' in uri:
#             return httplib2.Response({'status': '200'}), load_data('oauth2_token.json')
# 
#         # Response for user info API
#         if 'https://www.googleapis.com/oauth2/v2/userinfo' in uri:
#             return httplib2.Response({'status': '200'}), load_data('user_info.json')
# 
#         # Response for Drive API discovery
#         if 'https://www.googleapis.com/discovery/v1/apis/drive/v2/rest' in uri:
#             return httplib2.Response({'status': '200'}), load_data('discovery_drive.json')
# 
#         # Response for files list
#         if 'https://www.googleapis.com/drive/v2/files' in uri:
#             return httplib2.Response({'status': '200'}), load_data('list_files.json')
# 
#         # Response for worksheets list
#         if 'https://spreadsheets.google.com/feeds/worksheets/dummy_key/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets.xml')
# 
#         # Response for worksheets list not found
#         if 'https://spreadsheets.google.com/feeds/worksheets/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_not_found.xml')
# 
#         # Response for worksheets list with bad format
#         if 'https://spreadsheets.google.com/feeds/worksheets/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_bad_format.xml')
# 
#         # Response for worksheet cells
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/dummy_id/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells.xml')
# 
#         # Response for worksheet cells not found
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_not_found.xml')
# 
#         # Response for worksheet cells with bad format
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_bad_format.xml')
# 
#         logging.error("No MockHTTP response for request to '%s'" % uri)
#         return httplib2.Response({}), ''


import os
import unittest
from helpers import google_api
from oauth2client.client import OAuth2WebServerFlow
from tests.utils import MockHttp
        self.assertTrue('email'         in data['author'])

    def test_get_worksheets_not_found(self):
        google_api.httplib2.Http = MockHttp
        with self.assertRaises(google_api.GoogleAPIException):
            google_api.get_worksheets(USER_AUTH_JSON, 'not_found')

    def test_get_worksheets_bad_format(self):
        google_api.httplib2.Http = MockHttp
        with self.assertRaises(google_api.GoogleAPIException):
            google_api.get_worksheets(USER_AUTH_JSON, 'bad_format')  

    def test_get_cell_data(self):
        google_api.httplib2.Http = MockHttp
        self.assertIn('get_cell_data', dir(google_api))

        data = google_api.get_cell_data(USER_AUTH_JSON, 'dummy_key', 'dummy_id')
        self.assertIsInstance(data, dict)
        self.assertTrue('key'           in data)
        self.assertTrue('id'            in data)
        self.assertTrue('title'         in data)
        self.assertTrue('updated'       in data)
        self.assertTrue('total_results' in data)
        self.assertTrue('start_index'   in data)
        self.assertTrue('data_rows'     in data)
        self.assertTrue('author'        in data)
        self.assertTrue('name'          in data['author'])
        self.assertTrue('email'         in data['author'])

    def test_get_cell_data_not_found(self):

# Path: helpers/google_api.py
# class GoogleAPIException(Exception):
# def oauth2_flow(**kwargs):
# def http_from_oauth2(auth_json):
# def user_info(auth_json):
# def drive_service():
# def list_drive_files(auth_json, query="", page_token=None):
# def get_worksheets(auth_json, spreadsheet_key):
# def get_cell_data(auth_json, spreadsheet_key, worksheet_key, limit=None):
# def create_spreadsheet(auth_json, title=""):
# def create_worksheet(auth_json, spreadsheet_key):
# def save_data(auth_json, spreadsheet_key, worksheet_key, data=[[]]):
# def _key(heading):
# def _val(val):    #::::....|...                       ___(_)
# 
# Path: tests/utils.py
# class MockHttp(object):
#     def __init__(self, cache=None, timeout=None, proxy_info=None, ca_certs=None, disable_ssl_certificate_validation=False):
#         pass
# 
#     def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
# 
#         # Response for oAuth2 Handshake
#         if 'https://accounts.google.com/o/oauth2/token' in uri:
#             return httplib2.Response({'status': '200'}), load_data('oauth2_token.json')
# 
#         # Response for user info API
#         if 'https://www.googleapis.com/oauth2/v2/userinfo' in uri:
#             return httplib2.Response({'status': '200'}), load_data('user_info.json')
# 
#         # Response for Drive API discovery
#         if 'https://www.googleapis.com/discovery/v1/apis/drive/v2/rest' in uri:
#             return httplib2.Response({'status': '200'}), load_data('discovery_drive.json')
# 
#         # Response for files list
#         if 'https://www.googleapis.com/drive/v2/files' in uri:
#             return httplib2.Response({'status': '200'}), load_data('list_files.json')
# 
#         # Response for worksheets list
#         if 'https://spreadsheets.google.com/feeds/worksheets/dummy_key/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets.xml')
# 
#         # Response for worksheets list not found
#         if 'https://spreadsheets.google.com/feeds/worksheets/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_not_found.xml')
# 
#         # Response for worksheets list with bad format
#         if 'https://spreadsheets.google.com/feeds/worksheets/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_bad_format.xml')
# 
#         # Response for worksheet cells
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/dummy_id/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells.xml')
# 
#         # Response for worksheet cells not found
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_not_found.xml')
# 
#         # Response for worksheet cells with bad format
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_bad_format.xml')
# 
#         logging.error("No MockHTTP response for request to '%s'" % uri)
#         return httplib2.Response({}), ''


# Path: tests/test_helpers/test_google_api.py
import os
import unittest
from helpers import google_api
from oauth2client.client import OAuth2WebServerFlow
from tests.utils import MockHttp

        self.assertTrue('email'         in data['author'])

    def test_get_worksheets_not_found(self):
        google_api.httplib2.Http = MockHttp
        with self.assertRaises(google_api.GoogleAPIException):
            google_api.get_worksheets(USER_AUTH_JSON, 'not_found')

    def test_get_worksheets_bad_format(self):
        google_api.httplib2.Http = MockHttp
        with self.assertRaises(google_api.GoogleAPIException):
            google_api.get_worksheets(USER_AUTH_JSON, 'bad_format')  

    def test_get_cell_data(self):
        google_api.httplib2.Http = MockHttp
        self.assertIn('get_cell_data', dir(google_api))

        data = google_api.get_cell_data(USER_AUTH_JSON, 'dummy_key', 'dummy_id')
        self.assertIsInstance(data, dict)
        self.assertTrue('key'           in data)
        self.assertTrue('id'            in data)
        self.assertTrue('title'         in data)
        self.assertTrue('updated'       in data)
        self.assertTrue('total_results' in data)
        self.assertTrue('start_index'   in data)
        self.assertTrue('data_rows'     in data)
        self.assertTrue('author'        in data)
        self.assertTrue('name'          in data['author'])
        self.assertTrue('email'         in data['author'])

    def test_get_cell_data_not_found(self):

        google_api.httplib2.Http = MockHttp