Skip to content

Commit

Permalink
List, add, and delete stars.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thingable committed Apr 9, 2018
1 parent f9ceb4e commit 1699057
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
17 changes: 17 additions & 0 deletions test/test_trello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ def test54_resource_unavailable(self):
self.assertRaises(ResourceUnavailable,
self._trello.get_card, '0')

def test_list_stars(self):
"""
Test trello client star list
"""
self.assertEqual(len(self._trello.list_stars()), int(os.environ["TRELLO_TEST_STAR_COUNT"]), "Number of stars does not match TRELLO_TEST_STAR_COUNT")

def test_add_delete_star(self):
"""
Test add and delete star to/from test board
"""
test_board_id = self._trello.search(os.environ["TRELLO_TEST_BOARD_NAME"])[0].id
new_star = self._trello.add_star(test_board_id)
star_list = self._trello.list_stars()
self.assertTrue(new_star in star_list, "Star id was not added in list of starred boards")
deleted_star = self._trello.delete_star(new_star)
star_list = self._trello.list_stars()
self.assertFalse(deleted_star in star_list, "Star id was not deleted from list of starred boards")

class TrelloClientTestCaseWithoutOAuth(unittest.TestCase):
"""
Expand Down
14 changes: 9 additions & 5 deletions trello/star.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, star_id, board_id, position):
super(Star, self).__init__()
self.id = star_id
self.board_id = board_id
self.position = pos
self.position = position

@classmethod
def from_json(cls, json_obj):
Expand All @@ -23,14 +23,18 @@ def from_json(cls, json_obj):
:board: the parent board the label is on
:json_obj: the label json object
"""
star = Star(id = json_obj['id'],
name = json_obj['idBoard'],
position = json_obj['pos'])
star = Star(star_id = json_obj['id'], board_id = json_obj['idBoard'], position = json_obj['pos'])
return star

@classmethod
def from_json_list(cls, json_objs):
return [cls.from_json(obj) for obj in json_objs]

def __repr__(self):
return force_str(u'<Star %s>' % self.star_id)
return force_str(u'<Star %s>' % self.id)

def __eq__(self, other):
return self.id == other.id

def __ne__(self, other):
return self.id != other.id
33 changes: 23 additions & 10 deletions trello/trelloclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from trello.webhook import WebHook
from trello.exceptions import *
from trello.label import Label
from trello.star import Star

try:
# PyOpenSSL works around some issues in python ssl modules
Expand Down Expand Up @@ -354,7 +355,7 @@ def search(self, query, partial_match=False, models=[],

return results

def list_stars():
def list_stars(self):
"""
Returns all boardStars for your Trello user
Expand All @@ -366,13 +367,25 @@ def list_stars():
- idBoard: ID of starred board
- pos: position of the board star
"""
json_obj = self.fetch_json('/members/me/boards/boardStars')
return [Star.from_json(self, json_obj=obj) for obj in json_obj]

def add_star(self, ):

return "Add star"

def delete_star():
json_obj = self.fetch_json('/members/me/boardStars')
return [Star.from_json(json_obj=obj) for obj in json_obj]

def add_star(self, board_id, position = "bottom"):
"""Create a star
:param board_iid: Id of the board to star
:param position: Optional position of the board star
:rtype: Star
"""
post_args = {'idBoard': board_id, 'pos': position}
obj = self.fetch_json('members/me/boardStars', http_method='POST',
post_args=post_args)
return Star.from_json(json_obj=obj)

return "Delete star"
def delete_star(self, star):
"""Deletes a star
:param board_iid: Id of the board to star
:param position: Optional position of the board star
:rtype: Star
"""
self.fetch_json(f'members/me/boardStars/{star.id}', http_method='DELETE')
return star

0 comments on commit 1699057

Please sign in to comment.