def test_close_lots_by_timeout(self): lot_2 = logic.reserve_lot(self.account_1.id, self.good_2, price=2) lot_2.state = relations.LOT_STATE.ACTIVE logic.save_lot(lot_2) lot_3 = logic.reserve_lot(self.account_1.id, self.good_3, price=3) self.assertFalse(lot_3.state.is_ACTIVE) lot_4 = logic.reserve_lot(self.account_1.id, self.good_4, price=4) lot_4.state = relations.LOT_STATE.ACTIVE logic.save_lot(lot_4) models.Lot.objects.filter( id__in=[self.lot_1.id, lot_3.id, lot_4.id]).update( created_at=datetime.datetime.now() - datetime.timedelta(days=conf.settings.LOT_LIVE_TIME + 1)) with mock.patch( 'the_tale.finances.market.workers.market_manager.Worker.cmd_logic_task' ) as cmd_logic_task: with self.check_delta( postponed_tasks_models.PostponedTask.objects.count, 2): tasks = logic.close_lots_by_timeout() self.assertEqual(cmd_logic_task.call_count, 2) self.assertEqual( set((tasks[0].internal_logic.lot_id, tasks[1].internal_logic.lot_id)), set((self.lot_1.id, lot_4.id)))
def test_close_lots_by_timeout(self): lot_2 = logic.reserve_lot(self.account_1.id, self.good_2, price=2) lot_2.state = relations.LOT_STATE.ACTIVE logic.save_lot(lot_2) lot_3 = logic.reserve_lot(self.account_1.id, self.good_3, price=3) self.assertFalse(lot_3.state.is_ACTIVE) lot_4 = logic.reserve_lot(self.account_1.id, self.good_4, price=4) lot_4.state = relations.LOT_STATE.ACTIVE logic.save_lot(lot_4) models.Lot.objects.filter(id__in=[self.lot_1.id, lot_3.id, lot_4.id]).update(created_at=datetime.datetime.now()-datetime.timedelta(days=conf.settings.LOT_LIVE_TIME+1)) with mock.patch('the_tale.finances.market.workers.market_manager.Worker.cmd_logic_task') as cmd_logic_task: with self.check_delta(postponed_tasks_models.PostponedTask.objects.count, 2): tasks = logic.close_lots_by_timeout() self.assertEqual(cmd_logic_task.call_count, 2) self.assertEqual(set((tasks[0].internal_logic.lot_id, tasks[1].internal_logic.lot_id)), set((self.lot_1.id, lot_4.id)))
def process_no_cmd(self): logic.close_lots_by_timeout()