Пример #1
0
def purchase_lot(buyer_id, lot):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    invoice = bank_prototypes.InvoicePrototype.create(
        recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
        recipient_id=lot.seller_id,
        sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
        sender_id=buyer_id,
        currency=bank_relations.CURRENCY_TYPE.PREMIUM,
        amount=lot.price,
        description_for_sender=u'Покупка «%s»' % lot.name,
        description_for_recipient=u'Продажа «%s»' % lot.name,
        operation_uid=u'market-buy-lot-%s' % lot.type)

    transaction = bank_transaction.Transaction(invoice.id)

    logic_task = postponed_tasks.BuyLotTask(seller_id=lot.seller_id,
                                            buyer_id=buyer_id,
                                            lot_id=lot.id,
                                            transaction=transaction)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.refrigerator.cmd_wait_task(task.id)

    return task
Пример #2
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)