Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
veriosn bunmb to 1.1.1, some bug fixes
  • Loading branch information
nithinmurali committed Apr 14, 2017
2 parents d99563a + 7aeded9 commit d2d4348
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pygsheets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

__version__ = '1.0.0'
__version__ = '1.1.1'
__author__ = 'Nithin Murali'


Expand Down
8 changes: 7 additions & 1 deletion pygsheets/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def color(self, value):
value = list(value) + [1.0]*(4-len(value))
else:
value = (value, 1.0, 1.0, 1.0)
for c in value:
if c < 0 or c > 1:
raise InvalidArgumentValue("Color should be in range 0-1")
self._color = tuple(value)
self.update()

Expand All @@ -161,8 +164,11 @@ def set_text_format(self, attribute, value):
:param value: corresponding value for the attribute
:return: :class: Cell
"""
if attribute not in ["foregroundColor" "fontFamily", "fontSize", "bold", "italic",
"strikethrough", "underline"]:
raise InvalidArgumentValue("not a valid argument, please see the docs")
self.text_format[attribute] = value
self.fetch()
self.update()
return self

def unlink(self):
Expand Down
22 changes: 13 additions & 9 deletions pygsheets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,30 @@ def create(self, title):
self._spreadsheeets.append({'name': title, "id": result['spreadsheetId']})
return Spreadsheet(self, jsonsheet=result)

def delete(self, title=None, id=None):
def delete(self, title=None, spreadsheet_id=None):
"""Deletes, a spreadsheet by title or id.
:param title: title of a spreadsheet.
:param id: id of a spreadsheet this takes precedence if both given.
:param spreadsheet_id: id of a spreadsheet this takes precedence if both given.
:raise pygsheets.SpreadsheetNotFound: if no spreadsheet is found.
"""
if not id and not title:
if not spreadsheet_id and not title:
raise SpreadsheetNotFound
if id:
if len([x for x in self._spreadsheeets if x["id"] == id]) == 0:
raise SpreadsheetNotFound

try:
if spreadsheet_id and not title:
title = [x["name"] for x in self._spreadsheeets if x["id"] == spreadsheet_id][0]
except IndexError:
raise SpreadsheetNotFound

try:
if title and not id:
id = [x["id"] for x in self._spreadsheeets if x["name"] == title][0]
if title and not spreadsheet_id:
spreadsheet_id = [x["id"] for x in self._spreadsheeets if x["name"] == title][0]
except IndexError:
raise SpreadsheetNotFound

self._execute_request(None, self.driveService.files().delete(fileId=id), False)
self._execute_request(None, self.driveService.files().delete(fileId=spreadsheet_id), False)
self._spreadsheeets.remove([x for x in self._spreadsheeets if x["name"] == title][0])

def export(self, spreadsheet_id, fformat):
Expand Down
8 changes: 8 additions & 0 deletions test/online_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_delete(self):
with pytest.raises(IndexError):
dummy = [x for x in gc._spreadsheeets if x["name"] == config_title][0]

@pytest.mark.order4
def test_create_delete_by_id(self):
config_title = config.get('Spreadsheet', 'title')
spreadsheet = gc.create(title=config_title)
gc.delete(spreadsheet_id=spreadsheet.id)
with pytest.raises(IndexError):
dummy = [x for x in gc._spreadsheeets if x["id"] == spreadsheet.id][0]


# @pytest.mark.skip()
class TestClient(object):
Expand Down

0 comments on commit d2d4348

Please sign in to comment.