Skip to content

Commit

Permalink
improved offline tests still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinmurali committed Nov 3, 2016
1 parent e53d09e commit 785f7b3
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions test/offline_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def read_config(filename):
config.readfp(open(filename))
return config

config = None
gc = None


def setup_module(module):
global config, gc
try:
config = read_config(CONFIG_FILENAME)
gc = pygsheets.authorize(CREDS_FILENAME)
except IOError as e:
msg = "Can't find %s for reading test configuration. "
raise Exception(msg % e.filename)

config_title = config.get('Spreadsheet', 'title')
sheets = [x for x in gc._spreadsheeets if x["name"] == config_title]
for sheet in sheets:
gc.delete(sheet['name'])


class TestSpreadsheet(object):

Expand All @@ -39,18 +57,29 @@ def setup_class(cls):
spreadsheet_json["Sheets"].append(worksheet_json)

cls.config = read_config(CONFIG_FILENAME)
cls.gc = mock.create_autospec(pygsheets.Client)
# cls.gc = mock.create_autospec(pygsheets.Client)
# cls.gc.open_by_key.return_value = spreadsheet_json
# cls.gc._fetch_sheets = [{'testssheetid': 'testssheettitle'}]
# cls.spreadsheet = pygsheets.Spreadsheet(cls.gc)

cls.gc.service.spreadsheets().get = mock.create_autospec(cls.gc.service.spreadsheets().get)
cls.gc.open_by_key.return_value = spreadsheet_json
cls.gc._fetch_sheets = [{'testssheetid': 'testssheettitle'}]
cls.spreadsheet = pygsheets.Spreadsheet(cls.gc)

def test_open(self):
@mock.patch('service.spreadsheets().get')
def test_open(self, mock_get):

mock_response = mock.Mock()
mock_response.execute.return_value = self.spreadsheet
mock_get.return_value = mock_response

spreadsheet = self.gc.open('testssheettitle')

mock_get.assert_called_once_with(spreadsheetId=self.config.get('Spreadsheet', 'key'),
fields='properties,sheets/properties,spreadsheetId')
assert(isinstance(spreadsheet, pygsheets.Spreadsheet))

@classmethod
def teardown_class(cls):
pass

if __name__ == '__main__':
unittest.main()

0 comments on commit 785f7b3

Please sign in to comment.