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)
def get(self, user): args = parser.parse_args() initial_date = date.fromisoformat(args.initial_date) end_date = date.fromisoformat(args.end_date) data = Move.select().where( Move.submit_date.between(initial_date, end_date), Move.user == user) out = data.select(fn.SUM( Move.value).alias("total")).where(Move.type == 1) entry = data.select(fn.SUM( Move.value).alias("total")).where(Move.type == 0) out = out[0].total if out is None: out = 0 entry = entry[0].total if entry is None: entry = 0 return json_response( { "entry_sum": entry, "out_sum": out, "profit": (entry - out) }, 200)