def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.logic_storage.load_account_data(self.account_1)

        self.price_1 = 666

        self.task = postponed_tasks.CreateLotTask(account_id=self.account_1.id,
                                                  good_type=goods_types.test_hero_good.uid,
                                                  good_uid=self.good_1_uid,
                                                  price=self.price_1)

        self.main_task = mock.Mock(comment=None, id=777)
    def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.logic_storage.load_account_data(self.account_1)

        self.price_1 = 666

        self.task = postponed_tasks.CreateLotTask(
            account_id=self.account_1.id,
            good_type=goods_types.test_hero_good.uid,
            good_uid=self.good_1_uid,
            price=self.price_1)

        self.main_task = mock.Mock(comment=None, id=777)
Beispiel #3
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        self.good_2 = goods_types.test_hero_good.create_good('good-2')
        self.good_3 = goods_types.test_hero_good.create_good('good-3')
        self.good_4 = goods_types.test_hero_good.create_good('good-4')

        self.goods_1.add_good(self.good_1)
        self.goods_1.add_good(self.good_2)
        self.goods_1.add_good(self.good_3)
        self.goods_1.add_good(self.good_4)
        logic.save_goods(self.goods_1)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id, self.good_1, price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)
    def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        goods_types.test_hero_good._clear()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.hero_1 = self.logic_storage.load_account_data(self.account_1)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id, self.good_1, price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.task = postponed_tasks.CloseLotByTimoutTask(lot_id=self.lot_1.id)

        self.main_task = mock.Mock(comment=None, id=777)
    def test_no_good(self):
        self.goods_1.remove_good(self.good_1_uid)
        logic.save_goods(self.goods_1)

        self.assertEqual(self.task.process(self.main_task), POSTPONED_TASK_LOGIC_RESULT.ERROR)
        self.assertTrue(self.task.state.is_NO_GOOD)
        self.assertTrue(self.task.step.is_UNPROCESSED)
Beispiel #6
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        self.good_2 = goods_types.test_hero_good.create_good('good-2')
        self.good_3 = goods_types.test_hero_good.create_good('good-3')
        self.good_4 = goods_types.test_hero_good.create_good('good-4')

        self.goods_1.add_good(self.good_1)
        self.goods_1.add_good(self.good_2)
        self.goods_1.add_good(self.good_3)
        self.goods_1.add_good(self.good_4)
        logic.save_goods(self.goods_1)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id, self.good_1, price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)
Beispiel #7
0
    def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        goods_types.test_hero_good._clear()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.hero_1 = self.logic_storage.load_account_data(self.account_1)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id,
                                       self.good_1,
                                       price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.task = postponed_tasks.CloseLotByTimoutTask(lot_id=self.lot_1.id)

        self.main_task = mock.Mock(comment=None, id=777)
Beispiel #8
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        self.check_html_ok(self.request_ajax_html(self.requested_url), texts=[('pgf-error-good.wrong_value', 1)])
    def test_no_good(self):
        self.goods_1.remove_good(self.good_1_uid)
        logic.save_goods(self.goods_1)

        self.assertEqual(self.task.process(self.main_task),
                         POSTPONED_TASK_LOGIC_RESULT.ERROR)
        self.assertTrue(self.task.state.is_NO_GOOD)
        self.assertTrue(self.task.step.is_UNPROCESSED)
Beispiel #10
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        self.check_html_ok(self.request_ajax_html(self.requested_url),
                           texts=[('pgf-error-good.wrong_value', 1)])
Beispiel #11
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        with self.check_not_changed(postponed_tasks_models.PostponedTask.objects.count):
            self.check_ajax_error(self.post_ajax_json(self.requested_url, {'price': 600}), 'good.wrong_value')
    def test_has_lot__other_good(self):
        good_2 = goods_types.test_hero_good.create_good('good-2')
        self.goods_1.add_good(good_2)
        logic.save_goods(self.goods_1)

        logic.reserve_lot(self.account_1.id, self.goods_1.get_good('good-2'), price=777)

        self.assertEqual(self.task.process(self.main_task), POSTPONED_TASK_LOGIC_RESULT.CONTINUE)
        self.assertTrue(self.task.state.is_UNPROCESSED)
        self.assertTrue(self.task.step.is_RESERVED)
Beispiel #13
0
    def setUp(self):
        super(CreateRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.requested_url = url('market:create', good=self.good_1.uid)
Beispiel #14
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        with self.check_not_changed(
                postponed_tasks_models.PostponedTask.objects.count):
            self.check_ajax_error(
                self.post_ajax_json(self.requested_url, {'price': 600}),
                'good.wrong_value')
Beispiel #15
0
    def setUp(self):
        super(CreateRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.requested_url = url('market:create', good=self.good_1.uid)
Beispiel #16
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        self.check_html_ok(self.request_html(self.requested_url),
                           texts=[('pgf-no-goods-message', 1),
                                  (self.good_1.name, 0), (self.good_2.name, 0),
                                  (self.good_3.name, 0),
                                  (self.good_4.name, 0)])
Beispiel #17
0
    def test_no_items(self):
        self.request_login(self.account_1.email)

        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        self.check_html_ok(self.request_html(self.requested_url), texts=[('pgf-no-goods-message', 1),
                                                                         (self.good_1.name, 0),
                                                                         (self.good_2.name, 0),
                                                                         (self.good_3.name, 0),
                                                                         (self.good_4.name, 0)])
    def test_has_lot__other_account(self):
        account_2 = self.accounts_factory.create_account()
        good_2 = goods_types.test_hero_good.create_good(self.good_1_uid)
        goods_2 = logic.load_goods(account_2.id)
        goods_2.add_good(good_2)
        logic.save_goods(goods_2)

        logic.reserve_lot(account_2.id, goods_2.get_good(self.good_1_uid), price=777)

        self.assertEqual(self.task.process(self.main_task), POSTPONED_TASK_LOGIC_RESULT.CONTINUE)
        self.assertTrue(self.task.state.is_UNPROCESSED)
        self.assertTrue(self.task.step.is_RESERVED)
Beispiel #19
0
    def test_sync_goods(self):
        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        goods_types.test_hero_good.all_goods_for_sync.extend([self.good_2, self.good_4])

        logic.sync_goods(self.account_1.id, None)

        goods_1 = logic.load_goods(self.account_1.id)

        self.assertTrue(goods_1.has_good(self.good_2.uid))
        self.assertFalse(goods_1.has_good(self.good_3.uid))
        self.assertTrue(goods_1.has_good(self.good_4.uid))
Beispiel #20
0
    def test_sync_goods(self):
        self.goods_1.clear()
        logic.save_goods(self.goods_1)

        goods_types.test_hero_good.all_goods_for_sync.extend([self.good_2, self.good_4])

        logic.sync_goods(self.account_1.id, None)

        goods_1 = logic.load_goods(self.account_1.id)

        self.assertTrue(goods_1.has_good(self.good_2.uid))
        self.assertFalse(goods_1.has_good(self.good_3.uid))
        self.assertTrue(goods_1.has_good(self.good_4.uid))
    def test_has_lot__other_good(self):
        good_2 = goods_types.test_hero_good.create_good('good-2')
        self.goods_1.add_good(good_2)
        logic.save_goods(self.goods_1)

        logic.reserve_lot(self.account_1.id,
                          self.goods_1.get_good('good-2'),
                          price=777)

        self.assertEqual(self.task.process(self.main_task),
                         POSTPONED_TASK_LOGIC_RESULT.CONTINUE)
        self.assertTrue(self.task.state.is_UNPROCESSED)
        self.assertTrue(self.task.step.is_RESERVED)
Beispiel #22
0
    def setUp(self):
        super(MarketManagerTests, self).setUp()

        create_test_map()

        self.worker = amqp_environment.environment.workers.market_manager
        self.worker.initialize()

        self.account_1 = self.accounts_factory.create_account()

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        logic.save_goods(self.goods_1)
    def setUp(self):
        super(MarketManagerTests, self).setUp()

        create_test_map()

        self.worker = amqp_environment.environment.workers.market_manager
        self.worker.initialize()

        self.account_1 = self.accounts_factory.create_account()

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        logic.save_goods(self.goods_1)
Beispiel #24
0
    def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.goods_2 = logic.load_goods(self.account_2.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.hero_1 = self.logic_storage.load_account_data(self.account_1)
        self.hero_2 = self.logic_storage.load_account_data(self.account_2)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id,
                                       self.good_1,
                                       price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.invoice = bank_prototypes.InvoicePrototype.create(
            recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
            recipient_id=self.account_1.id,
            sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
            sender_id=self.account_2.id,
            currency=bank_relations.CURRENCY_TYPE.PREMIUM,
            amount=self.price,
            description_for_sender='transaction-description-for_sender',
            description_for_recipient='transaction-description-for-recipient',
            operation_uid='transaction-operation-ui')

        self.transaction = bank_transaction.Transaction(self.invoice.id)

        self.task = postponed_tasks.BuyLotTask(seller_id=self.account_1.id,
                                               buyer_id=self.account_2.id,
                                               lot_id=self.lot_1.id,
                                               transaction=self.transaction)

        self.main_task = mock.Mock(comment=None, id=777)
    def test_has_lot__other_account(self):
        account_2 = self.accounts_factory.create_account()
        good_2 = goods_types.test_hero_good.create_good(self.good_1_uid)
        goods_2 = logic.load_goods(account_2.id)
        goods_2.add_good(good_2)
        logic.save_goods(goods_2)

        logic.reserve_lot(account_2.id,
                          goods_2.get_good(self.good_1_uid),
                          price=777)

        self.assertEqual(self.task.process(self.main_task),
                         POSTPONED_TASK_LOGIC_RESULT.CONTINUE)
        self.assertTrue(self.task.state.is_UNPROCESSED)
        self.assertTrue(self.task.step.is_RESERVED)
Beispiel #26
0
    def setUp(self):
        super(PurchaseRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.lot_1 = logic.reserve_lot(self.account_1.id, self.goods_1.get_good(self.good_1.uid), price=777)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.requested_url = url('market:purchase', self.lot_1.id)
Beispiel #27
0
    def setUp(self):
        super(TaskTests, self).setUp()

        create_test_map()

        self.good_1_uid = 'good-1'

        self.account_1 = self.accounts_factory.create_account()
        self.goods_1 = logic.load_goods(self.account_1.id)

        self.account_2 = self.accounts_factory.create_account()
        self.goods_2 = logic.load_goods(self.account_2.id)

        self.good_1 = goods_types.test_hero_good.create_good(self.good_1_uid)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.logic_storage = logic_storage.LogicStorage()
        self.hero_1 = self.logic_storage.load_account_data(self.account_1)
        self.hero_2 = self.logic_storage.load_account_data(self.account_2)

        self.price = 666

        self.lot_1 = logic.reserve_lot(self.account_1.id, self.good_1, price=self.price)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.invoice = bank_prototypes.InvoicePrototype.create(recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                                                               recipient_id=self.account_1.id,
                                                               sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                                                               sender_id=self.account_2.id,
                                                               currency=bank_relations.CURRENCY_TYPE.PREMIUM,
                                                               amount=self.price,
                                                               description_for_sender='transaction-description-for_sender',
                                                               description_for_recipient='transaction-description-for-recipient',
                                                               operation_uid='transaction-operation-ui')


        self.transaction = bank_transaction.Transaction(self.invoice.id)

        self.task = postponed_tasks.BuyLotTask(seller_id=self.account_1.id,
                                               buyer_id=self.account_2.id,
                                               lot_id=self.lot_1.id,
                                               transaction=self.transaction)

        self.main_task = mock.Mock(comment=None, id=777)
Beispiel #28
0
    def setUp(self):
        super(NewRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        self.good_2 = goods_types.test_hero_good.create_good('good-2')
        self.good_3 = goods_types.test_hero_good.create_good('good-3')
        self.good_4 = goods_types.test_hero_good.create_good('good-4')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        self.goods_1.add_good(self.good_2)
        self.goods_1.add_good(self.good_3)
        self.goods_1.add_good(self.good_4)
        logic.save_goods(self.goods_1)

        self.requested_url = url('market:new')
Beispiel #29
0
    def setUp(self):
        super(PurchaseRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        logic.save_goods(self.goods_1)

        self.lot_1 = logic.reserve_lot(self.account_1.id,
                                       self.goods_1.get_good(self.good_1.uid),
                                       price=777)
        self.lot_1.state = relations.LOT_STATE.ACTIVE
        logic.save_lot(self.lot_1)

        self.requested_url = url('market:purchase', self.lot_1.id)
Beispiel #30
0
    def setUp(self):
        super(NewRequestsTests, self).setUp()

        self.good_1 = goods_types.test_hero_good.create_good('good-1')
        self.good_2 = goods_types.test_hero_good.create_good('good-2')
        self.good_3 = goods_types.test_hero_good.create_good('good-3')
        self.good_4 = goods_types.test_hero_good.create_good('good-4')

        self.goods_1 = logic.load_goods(self.account_1.id)

        self.goods_1.add_good(self.good_1)
        self.goods_1.add_good(self.good_2)
        self.goods_1.add_good(self.good_3)
        self.goods_1.add_good(self.good_4)
        logic.save_goods(self.goods_1)

        self.requested_url = url('market:new')
Beispiel #31
0
    def process(self, main_task, storage=None): # pylint: disable=R0911

        good_type = goods_types.get_type(self.good_type)

        if self.step.is_UNPROCESSED:

            account = account_prototypes.AccountPrototype.get_by_id(self.account_id)

            if account.is_ban_game:
                main_task.comment = 'account is banned'
                self.state = self.STATE.BANNED
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            goods = logic.load_goods(self.account_id)

            if not goods.has_good(self.good_uid):
                main_task.comment = 'account has no good %s' % self.good_uid
                self.state = self.STATE.NO_GOOD
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if logic.has_lot(self.account_id, self.good_uid):
                main_task.comment = 'account %d has lot for <%s> %s' % (self.account_id, self.good_type, self.good_uid)
                self.state = self.STATE.ALREADY_RESERVED
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            lot = logic.reserve_lot(self.account_id, goods.get_good(self.good_uid), price=self.price)

            self.lot_id = lot.id

            main_task.extend_postsave_actions((lambda: environment.workers.supervisor.cmd_logic_task(self.account_id, main_task.id),))

            self.step = self.STEP.RESERVED
            return POSTPONED_TASK_LOGIC_RESULT.CONTINUE


        if self.step.is_RESERVED:
            hero = storage.accounts_to_heroes[self.account_id]

            if not good_type.has_good(hero, self.good_uid):
                main_task.comment = 'hero has no good %s' % self.good_uid
                self.state = self.STATE.NO_GOOD
                self.step = self.STEP.ROLLBACK
                main_task.extend_postsave_actions((lambda: environment.workers.market_manager.cmd_logic_task(self.account_id, main_task.id),))
                return POSTPONED_TASK_LOGIC_RESULT.CONTINUE

            good_type.extract_good(hero, self.good_uid)

            storage.save_bundle_data(hero.actions.current_action.bundle_id)

            main_task.extend_postsave_actions((lambda: environment.workers.market_manager.cmd_logic_task(self.account_id, main_task.id),))

            self.step = self.STEP.GOTTEN
            return POSTPONED_TASK_LOGIC_RESULT.CONTINUE


        if self.step.is_ROLLBACK:
            goods = logic.load_goods(self.account_id)

            lot = logic.load_lot(self.lot_id)
            lot.state = relations.LOT_STATE.CLOSED_BY_ERROR
            logic.save_lot(lot)

            self.step = self.STEP.ROLLBACKED
            self.state = self.STATE.PROCESSED
            return POSTPONED_TASK_LOGIC_RESULT.SUCCESS


        if self.step.is_GOTTEN:
            goods = logic.load_goods(self.account_id)

            lot = logic.load_lot(self.lot_id)
            lot.state = relations.LOT_STATE.ACTIVE
            logic.save_lot(lot)

            goods.remove_good(self.good_uid)
            logic.save_goods(goods)
            self.step = self.STEP.ACTIVATED
            self.state = self.STATE.PROCESSED
            return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
Beispiel #32
0
 def process_remove_item(self, account_id, good_data):
     good = objects.Good.deserialize(good_data)
     goods = logic.load_goods(account_id=account_id)
     goods.remove_good(good.uid)
     logic.save_goods(goods)
Beispiel #33
0
    def process(self, main_task, storage=None):  # pylint: disable=R0911

        good_type = goods_types.get_type(self.good_type)

        if self.step.is_UNPROCESSED:

            account = account_prototypes.AccountPrototype.get_by_id(
                self.account_id)

            if account.is_ban_game:
                main_task.comment = 'account is banned'
                self.state = self.STATE.BANNED
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            goods = logic.load_goods(self.account_id)

            if not goods.has_good(self.good_uid):
                main_task.comment = 'account has no good %s' % self.good_uid
                self.state = self.STATE.NO_GOOD
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if logic.has_lot(self.account_id, self.good_uid):
                main_task.comment = 'account %d has lot for <%s> %s' % (
                    self.account_id, self.good_type, self.good_uid)
                self.state = self.STATE.ALREADY_RESERVED
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            lot = logic.reserve_lot(self.account_id,
                                    goods.get_good(self.good_uid),
                                    price=self.price)

            self.lot_id = lot.id

            main_task.extend_postsave_actions(
                (lambda: environment.workers.supervisor.cmd_logic_task(
                    self.account_id, main_task.id), ))

            self.step = self.STEP.RESERVED
            return POSTPONED_TASK_LOGIC_RESULT.CONTINUE

        if self.step.is_RESERVED:
            hero = storage.accounts_to_heroes[self.account_id]

            if not good_type.has_good(hero, self.good_uid):
                main_task.comment = 'hero has no good %s' % self.good_uid
                self.state = self.STATE.NO_GOOD
                self.step = self.STEP.ROLLBACK
                main_task.extend_postsave_actions(
                    (lambda: environment.workers.market_manager.cmd_logic_task(
                        self.account_id, main_task.id), ))
                return POSTPONED_TASK_LOGIC_RESULT.CONTINUE

            good_type.extract_good(hero, self.good_uid)

            storage.save_bundle_data(hero.actions.current_action.bundle_id)

            main_task.extend_postsave_actions(
                (lambda: environment.workers.market_manager.cmd_logic_task(
                    self.account_id, main_task.id), ))

            self.step = self.STEP.GOTTEN
            return POSTPONED_TASK_LOGIC_RESULT.CONTINUE

        if self.step.is_ROLLBACK:
            goods = logic.load_goods(self.account_id)

            lot = logic.load_lot(self.lot_id)
            lot.state = relations.LOT_STATE.CLOSED_BY_ERROR
            logic.save_lot(lot)

            self.step = self.STEP.ROLLBACKED
            self.state = self.STATE.PROCESSED
            return POSTPONED_TASK_LOGIC_RESULT.SUCCESS

        if self.step.is_GOTTEN:
            goods = logic.load_goods(self.account_id)

            lot = logic.load_lot(self.lot_id)
            lot.state = relations.LOT_STATE.ACTIVE
            logic.save_lot(lot)

            goods.remove_good(self.good_uid)
            logic.save_goods(goods)
            self.step = self.STEP.ACTIVATED
            self.state = self.STATE.PROCESSED
            return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
Beispiel #34
0
 def process_remove_item(self, account_id, good_data):
     good = objects.Good.deserialize(good_data)
     goods = logic.load_goods(account_id=account_id)
     goods.remove_good(good.uid)
     logic.save_goods(goods)