Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievement test #815

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions wouso/games/challenge/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def read(self, request):
user_from=unicode(c.user_from.user),
user_from_id=c.user_from.user.id,
user_to=unicode(c.user_to.user),
user_to_id=c.user_to.user.id) for c in ChallengeGame.get_active(challuser)]
user_to_id=c.user_to.user.id)
for c in ChallengeGame.get_active(challuser)]


class ChallengeGetRandom(BaseHandler):
Expand Down Expand Up @@ -78,7 +79,10 @@ def read(self, request, challenge_id, action='play'):
challenge.set_start(player)

if challenge.is_expired_for_user(player):
return {'success': False, 'error': 'Challenge expired for this user'}
return {
'success': False,
'error': 'Challenge expired for this user'
}

return {'success': True,
'status': challenge.status,
Expand All @@ -87,28 +91,42 @@ def read(self, request, challenge_id, action='play'):
'date': challenge.date,
'seconds': challenge.time_for_user(challuser),
'questions': dict(
[(q.id, {'text': q, 'answers': dict([(a.id, a) for a in q.answers])}) for q in
challenge.questions.all()]),
}
[
(q.id, {
'text': q,
'answers': dict([(a.id, a) for a in q.answers])
})for q in challenge.questions.all()
]),
}

if action == 'refuse':
if challenge.user_to.user == challuser and challenge.is_launched():
challenge.refuse()
return {'success': True}
else:
return {'success': False, 'error': 'Cannot refuse this challenge'}
return {
'success': False,
'error': 'Cannot refuse this challenge'
}
if action == 'cancel':
if challenge.user_from.user == challuser and challenge.is_launched():
challenge.cancel()
return {'success': True}
if challenge.user_from.user == challuser and\
challenge.is_launched():
challenge.cancel()
return {'success': True}
else:
return {'success': False, 'error': 'Cannot cancel this challenge'}
return {
'success': False,
'error': 'Cannot cancel this challenge'
}
if action == 'accept':
if challenge.user_to.user == challuser and challenge.is_launched():
challenge.accept()
return {'success': True}
else:
return {'success': False, 'error': 'Cannot accept this challenge'}
return {
'success': False,
'error': 'Cannot accept this challenge'
}

return {'success': False, 'error': 'Unknown action'}

Expand All @@ -134,7 +152,11 @@ def create(self, request, challenge_id):
responses = {}
try:
for q in challenge.questions.all():
responses[q.id] = [int(a) if a else '' for a in data.get(str(q.id), '').split(',')]
responses[q.id] = [
int(a)
if a
else ''
for a in data.get(str(q.id), '').split(',')]
except (IndexError, ValueError):
return {'success': False, 'error': 'Unable to parse answers'}

Expand Down
7 changes: 7 additions & 0 deletions wouso/interface/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ def test_profile_page(self):
self._client_superuser()
response = self.client.get(reverse('player_profile', kwargs=dict(id=admin.id)))
self.assertEqual(response.status_code, 200)

def test_achievements_link(self):
player = self._get_player()
self.client.login(username=player.user.username, password='test')
response = self.client.get('/hub/')

self.assertTrue('Achievements' in response.content)