-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the top four of the final ranking
- Loading branch information
Osvaldo Matos-Junior
committed
Jul 13, 2014
1 parent
37014b1
commit 7be8802
Showing
7 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{% extends 'admin/master.html' %} | ||
|
||
{% block head %} | ||
{{super()}} | ||
<style> | ||
.champions_content { | ||
width: 500px; | ||
} | ||
|
||
.flag { | ||
margin: -5px 12px 0; | ||
} | ||
|
||
.table > tbody > tr > th { | ||
border-top: none; | ||
text-align: center; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<h4>Quais seleções foram as quatro primeiras colocadas da Copa do Mundo 2014?</h4> | ||
<div class="champions_content"> | ||
<form action="{{url_for('.save')}}" method="post"> | ||
<table class="table"> | ||
<tr> | ||
<th> </th> | ||
<th>1º</th> | ||
<th>2º</th> | ||
<th>3º</th> | ||
<th>4º</th> | ||
</tr> | ||
{% for team in teams %} | ||
<tr> | ||
<td><img class="flag" src="{{url_for('static', filename='images/flags/%s.png'%team.alias)}}" width="30" height="30" alt="{{team.name}}" />{{team.name}} ({{team.alias}})</td> | ||
<td><input type="radio" name="first" value="{{team.id}}" {{'checked="checked"' if team == first}}/> | ||
<td><input type="radio" name="second" value="{{team.id}}" {{'checked="checked"' if team == second}}/> | ||
<td><input type="radio" name="third" value="{{team.id}}" {{'checked="checked"' if team == third}}/> | ||
<td><input type="radio" name="fourth" value="{{team.id}}" {{'checked="checked"' if team == fourth}}/> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
<button type="submit" class="btn btn-default pull-right">Salvar</button> | ||
</form> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block tail_js %} | ||
{{super()}} | ||
<script> | ||
$(function(){ | ||
$('input:radio').on('click', function() { | ||
$(this).closest('tr').find('input:radio').each(function() { | ||
this.checked = false; | ||
}); | ||
this.checked = true; | ||
}); | ||
}); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
|
||
from flask.ext.testing import TestCase | ||
|
||
from bolao.models import Team, User, Game, Scorer, BetScorer, BetGame | ||
from bolao.models import Team, User, Game, Scorer, BetScorer, BetGame, BetChampions | ||
from bolao.main import app_factory | ||
from bolao.tasks import (update_scores_by_game, update_ranking, update_ranking_criterias, | ||
update_scorer) | ||
update_scorer, update_champions) | ||
from bolao.database import db | ||
|
||
|
||
|
@@ -456,3 +456,102 @@ def test_no_changes(self): | |
update_scorer(self.fred) | ||
self.assertEqual(20, bet.score) | ||
self.assertEqual(20, self.user.score_total) | ||
|
||
|
||
class UpdateChampionsTest(TestCase): | ||
|
||
def create_app(self): | ||
app = app_factory('Testing') | ||
return app | ||
|
||
def setUp(self): | ||
db.create_all() | ||
|
||
user = User(name="Test", email="[email protected]", active=True) | ||
db.session.add(user) | ||
|
||
bra = Team(name='Brasil', alias='BRA') | ||
arg = Team(name='Argentina', alias='ARG') | ||
uru = Team(name='Uruguai', alias='URU') | ||
ale = Team(name='Alemanha', alias='ALE') | ||
usa = Team(name='Estados Unidos', alias='USA') | ||
db.session.add(bra) | ||
db.session.add(arg) | ||
db.session.add(uru) | ||
db.session.add(ale) | ||
db.session.add(usa) | ||
|
||
db.session.commit() | ||
|
||
self.user = user | ||
self.bra = bra | ||
self.arg = arg | ||
self.uru = uru | ||
self.ale = ale | ||
self.usa = usa | ||
|
||
def tearDown(self): | ||
db.session.remove() | ||
db.drop_all() | ||
|
||
def test_exact_positions(self): | ||
|
||
bet = BetChampions(first=self.bra, second=self.arg, third=self.ale, fourth=self.uru, user=self.user) | ||
db.session.add(bet) | ||
db.session.commit() | ||
|
||
update_champions(self.bra, self.arg, self.ale, self.uru) | ||
|
||
self.assertEqual(40, bet.score) | ||
self.assertEqual(40, self.user.score_total) | ||
|
||
def test_only_positions(self): | ||
|
||
bet = BetChampions(first=self.bra, second=self.arg, third=self.ale, fourth=self.uru, user=self.user) | ||
db.session.add(bet) | ||
db.session.commit() | ||
|
||
update_champions(self.uru, self.ale, self.arg, self.bra) | ||
|
||
self.assertEqual(20, bet.score) | ||
self.assertEqual(20, self.user.score_total) | ||
|
||
def test_mixed_positions(self): | ||
|
||
bet = BetChampions(first=self.ale, second=self.arg, third=self.bra, fourth=self.uru, user=self.user) | ||
db.session.add(bet) | ||
db.session.commit() | ||
|
||
update_champions(self.bra, self.usa, self.arg, self.uru) | ||
|
||
self.assertEqual(20, bet.score) | ||
self.assertEqual(20, self.user.score_total) | ||
|
||
def test_any_position(self): | ||
|
||
t1 = Team(name="T1", alias="T1") | ||
t2 = Team(name="T2", alias="T2") | ||
t3 = Team(name="T3", alias="T3") | ||
t4 = Team(name="T4", alias="T4") | ||
|
||
db.session.add(t1) | ||
db.session.add(t2) | ||
db.session.add(t3) | ||
db.session.add(t4) | ||
|
||
bet = BetChampions(first=self.bra, second=self.arg, third=self.ale, fourth=self.uru, user=self.user) | ||
db.session.add(bet) | ||
db.session.commit() | ||
|
||
update_champions(t1, t2, t3, t4) | ||
|
||
self.assertEqual(0, bet.score) | ||
|
||
|
||
def test_raises_with_none(self): | ||
bet = BetChampions(first=self.bra, second=self.arg, third=self.ale, fourth=self.uru, user=self.user) | ||
db.session.add(bet) | ||
db.session.commit() | ||
|
||
self.assertRaises(AssertionError, update_champions, None, None, None, None) | ||
|