def getSpreadsheet(self, key="TESTKEY", title="my_title"): """Helper method to get a Spreadsheet object by faking an API response. """ self.get.return_value.status_code = 200 self.get.return_value.content = (get_spreadsheet_element( key=key, title="my_title")) return Spreadsheet(self.token, key)
def getSpreadsheet(self, key="TESTKEY", title="my_title"): """Helper method to get a Spreadsheet object by faking an API response. """ self.get.return_value.status_code = 200 self.get.return_value.content = ( get_spreadsheet_element(key=key, title="my_title")) return Spreadsheet(self.token, key)
def test_initialize(self): # we should be able to intialize a Spreadsheet with a variety # of different URLs key = "TESTKEY" test_keys = [ key, # just using key "https://docs.google.com/spreadsheets/d/{}/edit#gid=0" .format(key), # normal url "http://docs.google.com/spreadsheets/d/{}/edit#gid=0" .format(key), # not https "https://docs.google.com/spreadsheets/d/{}" .format(key), # no trailing slash "https://www.docs.google.com/spreadsheets/d/{}" .format(key), # includes www "www.docs.google.com/spreadsheets/d/{}" .format(key), # includes www, no http "docs.google.com/spreadsheets/d/{}/" .format(key), # no http ] # check that we call the right URL feed_url = ("https://spreadsheets.google.com/feeds/spreadsheets/" "private/full/{}") self.get.return_value.status_code = 200 self.get.return_value.content = get_spreadsheet_element(key=key) for k in test_keys: s = Spreadsheet(self.token, key) self.checkGetCall(url=feed_url.format(key)) self.assertEqual(s.getKey(), key) # a bad key gets an error self.get.return_value.status_code = 500 bad_key = "BAD_KEY" with self.assertRaises(PGSheetsHTTPException): Spreadsheet(self.token, bad_key) self.checkGetCall(url=feed_url.format(bad_key)) self.assertFalse(self.post.called)
def test_initialize(self): # we should be able to intialize a Spreadsheet with a variety # of different URLs key = "TESTKEY" test_keys = [ key, # just using key "https://docs.google.com/spreadsheets/d/{}/edit#gid=0".format( key), # normal url "http://docs.google.com/spreadsheets/d/{}/edit#gid=0".format( key), # not https "https://docs.google.com/spreadsheets/d/{}".format( key), # no trailing slash "https://www.docs.google.com/spreadsheets/d/{}".format( key), # includes www "www.docs.google.com/spreadsheets/d/{}".format( key), # includes www, no http "docs.google.com/spreadsheets/d/{}/".format(key), # no http ] # check that we call the right URL feed_url = ("https://spreadsheets.google.com/feeds/spreadsheets/" "private/full/{}") self.get.return_value.status_code = 200 self.get.return_value.content = get_spreadsheet_element(key=key) for k in test_keys: s = Spreadsheet(self.token, key) self.checkGetCall(url=feed_url.format(key)) self.assertEqual(s.getKey(), key) # a bad key gets an error self.get.return_value.status_code = 500 bad_key = "BAD_KEY" with self.assertRaises(PGSheetsHTTPException): Spreadsheet(self.token, bad_key) self.checkGetCall(url=feed_url.format(bad_key)) self.assertFalse(self.post.called)