Skip to content

Commit

Permalink
Third authentication: initialize TrelloClient correctly
Browse files Browse the repository at this point in the history
Fixes #225
When TrelloClient initalise itself, it should look if token and
token_secret are provided to enable OAuth, otherwise, fallback to 3rd
authentication

Signed-off-by: Romain Beuque <[email protected]>
  • Loading branch information
rbeuque74 committed Dec 31, 2017
1 parent 8e5b696 commit 11ea9ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion test/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from trello import TrelloClient, ResourceUnavailable


class TrelloBoardTestCase(unittest.TestCase):
class TrelloCardTestCase(unittest.TestCase):
"""
Tests for TrelloClient API. Note these test are in order to
preserve dependencies, as an API integration cannot be tested
Expand Down Expand Up @@ -137,5 +137,6 @@ def suite():
# return unittest.TestSuite(map(TrelloBoardTestCase, tests))
return unittest.TestLoader().loadTestsFromTestCase(TrelloBoardTestCase)


if __name__ == "__main__":
unittest.main()
29 changes: 26 additions & 3 deletions test/test_trello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,33 @@ def test54_resource_unavailable(self):
self._trello.get_card, '0')


class TrelloClientTestCaseWithoutOAuth(unittest.TestCase):
"""
Tests for TrelloClient API when OAuth not activated.
"""

def setUp(self):
self._trello = TrelloClient(os.environ['TRELLO_API_KEY'],
api_secret=os.environ['TRELLO_TOKEN'])

def test01_oauth_not_activated(self):
self.assertIsNone(self._trello.oauth)


def suite():
# tests = ['test01_list_boards', 'test10_board_attrs', 'test20_add_card']
# return unittest.TestSuite(map(TrelloClientTestCase, tests))
return unittest.TestLoader().loadTestsFromTestCase(TrelloClientTestCase)
test_classes_to_run = [TrelloClientTestCase,
TrelloClientTestCaseWithoutOAuth]

loader = unittest.TestLoader()

suites_list = []
for test_class in test_classes_to_run:
suite = loader.loadTestsFromTestCase(test_class)
suites_list.append(suite)

return unittest.TestSuite(suites_list)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion trello/trelloclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, api_key, api_secret=None, token=None, token_secret=None):
"""

# client key and secret for oauth1 session
if api_key or token:
if token or token_secret:
self.oauth = OAuth1(client_key=api_key, client_secret=api_secret,
resource_owner_key=token, resource_owner_secret=token_secret)
else:
Expand Down

0 comments on commit 11ea9ab

Please sign in to comment.