def test_move(self):
# add game and check it
game = Game.create(white='123', black='456', state='Ke1,ke8')
self.assertTrue(abs((game.date_created - game.date_state).total_seconds()) < 1)
self.assertEqual(game.next_color, WHITE)
self.assertEqual(Game.select().count(), 1)
self.assertEqual(Move.select().count(), 0)
self.assertFalse(game.ended)
# wait a second
time.sleep(1)
# add move and check
game.add_move('K', 'e1-e2', 'Ke2,ke8')
self.assertEqual(Move.select().count(), 1)
# reload game
game = Game.get(pk=game.pk)
self.assertEqual(game.next_color, BLACK)
self.assertEqual(game.state, 'Ke2,ke8')
self.assertTrue((game.date_state - game.date_created).total_seconds() > 1)
self.assertAlmostEqual(game.moves.get().time_move, 1, places=1)
self.assertFalse(game.ended)
# add move with ending game
game.add_move('k', 'e8-e7', 'Ke2,ke7', True)
self.assertTrue(game.ended)
self.assertEqual(game.winner, BLACK)
评论列表
文章目录