Skip to content

Commit

Permalink
Added **params to add_participant
Browse files Browse the repository at this point in the history
More tests for organizations/subdomains
  • Loading branch information
fp12 committed May 20, 2017
1 parent 1628a65 commit d535c77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions challonge/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ async def search_participant(self, name, force_update=False):
return p
return None

async def add_participant(self, display_name: str = None, username: str = None, email: str = None, seed: int = 0, misc: str = None):
async def add_participant(self, display_name: str = None, username: str = None, email: str = None, seed: int = 0, misc: str = None, **params):
""" add a participant to the tournament
|methcoro|
Expand All @@ -579,6 +579,7 @@ async def add_participant(self, display_name: str = None, username: str = None,
email: Providing this will first search for a matching Challonge account. If one is found, this will have the same effect as the "challonge_username" attribute. If one is not found, the "new-user-email" attribute will be set, and the user will be invited via email to create an account.
seed: The participant's new seed. Must be between 1 and the current number of participants (including the new record). Overwriting an existing seed will automatically bump other participants as you would expect.
misc: Max: 255 characters. Multi-purpose field that is only visible via the API and handy for site integration (e.g. key to your users table)
params: optional params (see http://api.challonge.com/v1/documents/participants/create)
Returns:
Participant: newly created participant
Expand All @@ -591,10 +592,10 @@ async def add_participant(self, display_name: str = None, username: str = None,
ValueError,
'One of display_name or username must not be None')

params = {
params.update({
'name': display_name or '',
'challonge_username': username or '',
}
})
if email is not None:
params.update({'email': email})
if seed != 0:
Expand Down
19 changes: 15 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,27 @@ def test_b_get_tournaments(self):
random_name = get_random_name()
t1 = yield from new_user.create_tournament(random_name, random_name)

t2 = yield from new_user.get_tournament(t1.id)
self.assertEqual(t1, t2)
t1_by_id = yield from new_user.get_tournament(t1.id)
self.assertEqual(t1, t1_by_id)

t3 = yield from new_user.get_tournament(t1.id, force_update=True)
self.assertEqual(t1, t3)
t1_by_url = yield from new_user.get_tournament(url=t1.url)
self.assertEqual(t1, t1_by_url)

t1_forced = yield from new_user.get_tournament(t1.id, force_update=True)
self.assertEqual(t1, t1_forced)

random_name = get_random_name()
t2 = yield from new_user.create_tournament(random_name, random_name, subdomain=organization)
self.assertEqual(t2.subdomain, organization)

t2_by_url = yield from new_user.get_tournament(url=t2.url, subdomain=organization)
self.assertEqual(t2, t2_by_url)

with self.assertRaises(challonge.APIException):
yield from new_user.get_tournament(-1)

yield from new_user.destroy_tournament(t1)
yield from new_user.destroy_tournament(t2)


# @unittest.skip('')
Expand Down

0 comments on commit d535c77

Please sign in to comment.