|
|
@ -1,4 +1,5 @@ |
|
|
|
import unittest |
|
|
|
import unittest |
|
|
|
|
|
|
|
from datetime import datetime |
|
|
|
from app import create_app, db |
|
|
|
from app import create_app, db |
|
|
|
from app.models import User, Game, Role, GamePlayer |
|
|
|
from app.models import User, Game, Role, GamePlayer |
|
|
|
from config import Config |
|
|
|
from config import Config |
|
|
@ -36,5 +37,62 @@ class GameCase(unittest.TestCase): |
|
|
|
self.assertTrue(g1.owned_by(u1)) |
|
|
|
self.assertTrue(g1.owned_by(u1)) |
|
|
|
self.assertFalse(g1.owned_by(u2)) |
|
|
|
self.assertFalse(g1.owned_by(u2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete(self): |
|
|
|
|
|
|
|
g1 = Game(name='TestGame') |
|
|
|
|
|
|
|
u1 = User(name='Henk') |
|
|
|
|
|
|
|
u2 = User(name='Karel') |
|
|
|
|
|
|
|
p1 = GamePlayer(user=u1, role=Role.bunny) |
|
|
|
|
|
|
|
p2 = GamePlayer(user=u2, role=Role.bunny) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.players.append(p1) |
|
|
|
|
|
|
|
g1.players.append(p2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.add(g1) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u2.last_login = datetime.now() |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertNotEqual(User.query.filter_by(name='Henk').first(), None) |
|
|
|
|
|
|
|
self.assertNotEqual(User.query.filter_by(name='Karel').first(), None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.delete() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(User.query.filter_by(name='Henk').first(), None) |
|
|
|
|
|
|
|
self.assertNotEqual(User.query.filter_by(name='Karel').first(), None) |
|
|
|
|
|
|
|
self.assertEqual(Game.query.filter_by(name='TestGame').first(), None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_remove_player(self): |
|
|
|
|
|
|
|
g1 = Game(name='TestGame') |
|
|
|
|
|
|
|
g2 = Game(name='TestGame2') |
|
|
|
|
|
|
|
u1 = User(name='Henk') |
|
|
|
|
|
|
|
u2 = User(name='Karel') |
|
|
|
|
|
|
|
p1_1 = GamePlayer(user=u1, role=Role.owner) |
|
|
|
|
|
|
|
p1_2 = GamePlayer(user=u2, role=Role.bunny) |
|
|
|
|
|
|
|
p2_1 = GamePlayer(user=u1, role=Role.owner) |
|
|
|
|
|
|
|
p2_2 = GamePlayer(user=u2, role=Role.owner) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.players.append(p1_1) |
|
|
|
|
|
|
|
g1.players.append(p1_2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2.players.append(p2_1) |
|
|
|
|
|
|
|
g2.players.append(p2_2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.add(g1) |
|
|
|
|
|
|
|
db.session.add(g2) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertTrue(g1.remove_player(u1)) |
|
|
|
|
|
|
|
self.assertFalse(g1.remove_player(u2)) |
|
|
|
|
|
|
|
self.assertFalse(g2.remove_player(u1)) |
|
|
|
|
|
|
|
self.assertTrue(g2.remove_player(u2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertTrue(p1_1 in g1.players) |
|
|
|
|
|
|
|
self.assertTrue(p1_2 not in g1.players) |
|
|
|
|
|
|
|
self.assertTrue(p2_1 not in g2.players) |
|
|
|
|
|
|
|
self.assertTrue(p2_2 in g2.players) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
unittest.main(verbosity=2) |
|
|
|
unittest.main(verbosity=2) |
|
|
|