Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_add_csv_data_00(self, mocker):
"""Ensure the data is appended to the worksheet."""
fake_fields = self.fake.pylist(10, True, str)
fake_data = []
for _ in range(self.fake.random_digit()):
fake_entry = {}
for field in fake_fields:
fake_entry[field] = self.fake.word()
fake_data.append(fake_entry)
g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), [])
g.spreadsheet = Spreadsheet(None, None)
g.worksheet = mocker.MagicMock()
g.worksheet.append_row = mocker.MagicMock()
g.add_csv_data(fake_fields, fake_data)
assert not g.worksheet.append_row.call_count == len(fake_data)
def test_share_00(self, mocker):
"""Ensure the document is shared with valid contributors."""
contributors = ['alice@gmail.com:user:writer', 'alice@gmail.com:user:reader']
g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), contributors)
g.spreadsheet = Spreadsheet(None, None)
g.spreadsheet.share = mocker.MagicMock()
g.share()
assert g.spreadsheet.share.call_count == len(contributors)
def test_share_01(self, mocker):
"""Ensure the document is not shared with invalid contributors."""
contributors = ['alice@gmail.com']
g = GSheets(self.fake.file_path(depth=1, category=None, extension='json'), contributors)
g.spreadsheet = Spreadsheet(None, None)
g.spreadsheet.share = mocker.MagicMock()
g.share()
assert not g.spreadsheet.share.called
Returns
-------
dict
Response body
"""
if params is None:
params = {}
params.update(ranges=ranges)
url = SPREADSHEET_VALUES_BATCH_URL % (self.id)
r = self.client.request("get", url, params=params)
return r.json()
Spreadsheet.values_get_batch = values_get_batch
def open_by_key(self, key):
"""Opens a spreadsheet specified by `key`.
:param key: A key of a spreadsheet as it appears in a URL in a browser.
:type key: str
:returns: a :class:`~gspread.models.Spreadsheet` instance.
>>> c = gspread.authorize(credentials)
>>> c.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')
"""
return Spreadsheet(self, {'id': key})
:raises gspread.SpreadsheetNotFound: if no spreadsheet with
specified `title` is found.
>>> c = gspread.authorize(credentials)
>>> c.open('My fancy spreadsheet')
"""
try:
properties = finditem(
lambda x: x["name"] == title, self.list_spreadsheet_files(title)
)
# Drive uses different terminology
properties["title"] = properties["name"]
return Spreadsheet(self, properties)
except StopIteration:
raise SpreadsheetNotFound
def openall(self, title=None):
"""Opens all available spreadsheets.
:param title: (optional) If specified can be used to filter
spreadsheets by title.
:type title: str
:returns: a list of :class:`~gspread.models.Spreadsheet` instances.
"""
spreadsheet_files = self.list_spreadsheet_files()
return [
Spreadsheet(self, dict(title=x['name'], **x))
for x in spreadsheet_files
]