|
|
@ -24,63 +24,5 @@ class RoutesCase(unittest.TestCase): |
|
|
|
db.drop_all() |
|
|
|
db.drop_all() |
|
|
|
self.app_context.pop() |
|
|
|
self.app_context.pop() |
|
|
|
|
|
|
|
|
|
|
|
def test_is_game_owner(self): |
|
|
|
|
|
|
|
g1 = Game(name='TestGame') |
|
|
|
|
|
|
|
p1 = Player(name='Henk') |
|
|
|
|
|
|
|
p2 = Player(name='Alfred') |
|
|
|
|
|
|
|
g1.game_players.append(GamePlayer(player=p1, role=Role.owner)) |
|
|
|
|
|
|
|
g1.game_players.append(GamePlayer(player=p2, role=Role.bunny)) |
|
|
|
|
|
|
|
db.session.add(g1) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
self.assertTrue(routes.is_game_owner(g1, p1)) |
|
|
|
|
|
|
|
self.assertFalse(routes.is_game_owner(g1, p2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_player_game_owner(self): |
|
|
|
|
|
|
|
g1 = Game(name='TestGame') |
|
|
|
|
|
|
|
g2 = Game(name='AnotherGame') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p1 = Player(name='Henk') |
|
|
|
|
|
|
|
p2 = Player(name='Alfred') |
|
|
|
|
|
|
|
p3 = Player(name='Sasha') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.game_players.append(GamePlayer(player=p1, role=Role.owner)) |
|
|
|
|
|
|
|
g1.game_players.append(GamePlayer(player=p2, role=Role.bunny)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g2.game_players.append(GamePlayer(player=p1, role=Role.hunter)) |
|
|
|
|
|
|
|
g2.game_players.append(GamePlayer(player=p3, role=Role.bunny)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.add(g1) |
|
|
|
|
|
|
|
db.session.add(g2) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertTrue(routes.is_player_game_owner(subject_player=p2, owner=p1), "owner owns subject_player's game") |
|
|
|
|
|
|
|
self.assertFalse(routes.is_player_game_owner(subject_player=p3, owner=p1), "owner doesn't own subject_player's game") |
|
|
|
|
|
|
|
self.assertTrue(routes.is_player_game_owner(subject_player=p1, owner=p1), "owner owns it own's game") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_objective_owner(self): |
|
|
|
|
|
|
|
g1 = Game(name='TestGame') |
|
|
|
|
|
|
|
g2 = Game(name='AnotherGame') |
|
|
|
|
|
|
|
p1 = Player(name='Henk') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.game_players.append(GamePlayer(player=p1, role=Role.owner)) |
|
|
|
|
|
|
|
g2.game_players.append(GamePlayer(player=p1, role=Role.bunny)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
o1 = Objective(name='o1') |
|
|
|
|
|
|
|
o1.set_hash() |
|
|
|
|
|
|
|
o2 = Objective(name='o2') |
|
|
|
|
|
|
|
o2.set_hash() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g1.objectives.append(o1) |
|
|
|
|
|
|
|
g2.objectives.append(o2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.add(g1) |
|
|
|
|
|
|
|
db.session.add(g2) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertTrue(routes.is_objective_owner(o1, p1)) |
|
|
|
|
|
|
|
self.assertFalse(routes.is_objective_owner(o2, p1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
unittest.main(verbosity=2) |
|
|
|
unittest.main(verbosity=2) |
|
|
|