-
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.
Deny bet for games after the threshold.
- Loading branch information
Osvaldo Matos-Junior
committed
May 29, 2014
1 parent
902f917
commit ee6c9bb
Showing
6 changed files
with
69 additions
and
14 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import datetime | ||
from datetime import datetime, timedelta | ||
|
||
from flask import url_for | ||
from flask.ext.testing import TestCase as FlaskTestCase | ||
|
@@ -38,7 +38,7 @@ def create_app(self): | |
|
||
def setUp(self): | ||
db.create_all() | ||
self.user = User(name="Test", email="[email protected]") | ||
self.user = User(name="Test", email="[email protected]", active=True) | ||
db.session.add(self.user) | ||
db.session.commit() | ||
|
||
|
@@ -50,7 +50,7 @@ def test_games(self): | |
|
||
bra = Team(name="Brasil", alias="BRA") | ||
usa = Team(name="United States", alias="USA") | ||
now = datetime.datetime.utcnow() | ||
now = datetime.now() + timedelta(days=1) | ||
game = Game(team1=bra, team2=usa, time=now) | ||
db.session.add(bra) | ||
db.session.add(usa) | ||
|
@@ -64,15 +64,50 @@ def test_games(self): | |
self.assert200(response) | ||
self.assertIn('BRA', response.data) | ||
self.assertIn('USA', response.data) | ||
self.assertIn('apostar', response.data) | ||
# self.assert_template_used('games.html') | ||
|
||
def test_view_games_after_limit(self): | ||
bra = Team(name="Brasil", alias="BRA") | ||
usa = Team(name="United States", alias="USA") | ||
now = datetime.now() + timedelta(days=-1) | ||
game = Game(team1=bra, team2=usa, time=now) | ||
db.session.add(bra) | ||
db.session.add(usa) | ||
db.session.add(game) | ||
db.session.commit() | ||
|
||
with self.client.session_transaction() as sess: | ||
sess['user_id'] = self.user.id | ||
|
||
response = self.client.get(url_for('.games')) | ||
self.assertIn('expirou', response.data) | ||
|
||
def test_bet_game_view_after_limit(self): | ||
bra = Team(name="Brasil", alias="BRA") | ||
usa = Team(name="United States", alias="USA") | ||
now = datetime.now() + timedelta(days=-1) | ||
game = Game(team1=bra, team2=usa, time=now) | ||
db.session.add(bra) | ||
db.session.add(usa) | ||
db.session.add(game) | ||
db.session.commit() | ||
|
||
with self.client.session_transaction() as sess: | ||
sess['user_id'] = self.user.id | ||
|
||
response = self.client.get(url_for('.bet_game_view', game_id=game.id)) | ||
self.assertRedirects(response, url_for('.games')) | ||
expected_message = u"O prazo para apostar em <strong>%s</strong> expirou." % game | ||
self.assert_flashes(expected_message, category='warning') | ||
|
||
def test_bet_games_with_inactive_user(self): | ||
|
||
from bolao.views import INACTIVE_USER_MESSAGE | ||
|
||
bra = Team(name="Brasil", alias="BRA") | ||
usa = Team(name="United States", alias="USA") | ||
now = datetime.datetime.utcnow() | ||
now = datetime.now() | ||
game = Game(team1=bra, team2=usa, time=now) | ||
db.session.add(bra) | ||
db.session.add(usa) | ||
|
@@ -104,14 +139,14 @@ def tearDown(self): | |
db.drop_all() | ||
|
||
def test_view_champions_limit(self): | ||
self.app.config['BOLAO_BET_CHAMPIONS_LIMIT'] = datetime.datetime(1990, 1, 1) | ||
self.app.config['BOLAO_BET_CHAMPIONS_LIMIT'] = datetime(1990, 1, 1) | ||
response = self.client.get('/campeoes') | ||
self.assertRedirects(response, url_for('bolao.index')) | ||
self.assert_flashes("O prazo para escolher as primeiras colocadas expirou.", category='warning') | ||
|
||
def test_bet_champions_limit(self): | ||
data = {} | ||
self.app.config['BOLAO_BET_CHAMPIONS_LIMIT'] = datetime.datetime(1990, 1, 1) | ||
self.app.config['BOLAO_BET_CHAMPIONS_LIMIT'] = datetime(1990, 1, 1) | ||
response = self.client.post('/campeoes', data=data) | ||
self.assertRedirects(response, url_for('bolao.index')) | ||
self.assert_flashes("O prazo para escolher as primeiras colocadas expirou.", category='warning') | ||
|
@@ -145,14 +180,14 @@ def tearDown(self): | |
db.drop_all() | ||
|
||
def test_view_scorer_limit(self): | ||
self.app.config['BOLAO_BET_SCORER_LIMIT'] = datetime.datetime(1990, 1, 1) | ||
self.app.config['BOLAO_BET_SCORER_LIMIT'] = datetime(1990, 1, 1) | ||
response = self.client.get('/artilheiros') | ||
self.assertRedirects(response, url_for('bolao.index')) | ||
self.assert_flashes("O prazo para escolher os artilheiros expirou.", category='warning') | ||
|
||
def test_bet_scorer_limit(self): | ||
data = {} | ||
self.app.config['BOLAO_BET_SCORER_LIMIT'] = datetime.datetime(1990, 1, 1) | ||
self.app.config['BOLAO_BET_SCORER_LIMIT'] = datetime(1990, 1, 1) | ||
response = self.client.post('/artilheiros', data=data) | ||
self.assertRedirects(response, url_for('bolao.index')) | ||
self.assert_flashes("O prazo para escolher os artilheiros expirou.", category='warning') | ||
|