Skip to content

Commit

Permalink
Added Tournament.get_match
Browse files Browse the repository at this point in the history
  • Loading branch information
fp12 committed Jan 11, 2017
1 parent a0c0fd8 commit 3219eef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
28 changes: 25 additions & 3 deletions challonge/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, connection, json_def, **kwargs):

self.matches = None
self._create_match = lambda m: self._create_holder(Match, m)
self._find_match = lambda m_id: self._find_holder(self.matches, m_id)

self._refresh_from_json(json_def)

Expand Down Expand Up @@ -557,7 +558,7 @@ async def get_participant(self, p_id: int, force_update=False) -> Participant:
found_p = self._find_participant(p_id)
if force_update or found_p is None:
await self.get_participants()
found_p = self._find_participant(p_id)
found_p = self._find_participant(p_id)
return found_p

async def get_participants(self, force_update=False) -> list:
Expand Down Expand Up @@ -680,6 +681,28 @@ async def remove_participant(self, p: Participant):
if p in self.participants:
self.participants.remove(p)

async def get_match(self, m_id, force_update=False) -> Match:
""" get a single match by id
|methcoro|
Args:
m_id: match id
force_update (default=False): True to force an update to the Challonge API
Returns:
Match
Raises:
APIException
"""
found_m = self._find_match(m_id)
if force_update or found_m is None:
await self.get_matches()
found_m = self._find_match(m_id)
return found_m

async def get_matches(self, force_update=False) -> list:
""" get all matches (once the tournament is started)
Expand All @@ -696,10 +719,9 @@ async def get_matches(self, force_update=False) -> list:
"""
if force_update or self.matches is None:
params = {'include_attachments': 1}
res = await self.connection('GET',
'tournaments/{}/matches'.format(self._id),
**params)
include_attachments=1)
self._refresh_matches_from_json(res)
return self.matches or []

Expand Down
6 changes: 5 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def test_a_url(self):
yield from t.allow_attachments()
yield from t.add_participants('p1', 'p2', 'p3', 'p4')
yield from t.start()
m = yield from t.get_matches(force_update=True)
m = yield from t.get_matches()

a1 = yield from m[0].attach_url('https://github.com/fp12/achallonge')
self.assertEqual(a1.url, 'https://github.com/fp12/achallonge')
Expand All @@ -533,6 +533,10 @@ def test_a_url(self):
yield from m[0].destroy_attachment(a2)
self.assertEqual(len(m[0].attachments), 1)

m0 = yield from t.get_match(m[0].id, force_update=True)
self.assertEqual(m[0], m0)
self.assertEqual(len(m0.attachments), 1)

yield from self.user.destroy_tournament(t)

# @unittest.skip('')
Expand Down

0 comments on commit 3219eef

Please sign in to comment.