Exemplo n.º 1
0
    def test_purchase_lot(self):

        with mock.patch(
                'the_tale.common.postponed_tasks.workers.refrigerator.Worker.cmd_wait_task'
        ) as cmd_wait_task:
            with self.check_delta(
                    postponed_tasks_models.PostponedTask.objects.count, 1):
                with self.check_delta(bank_models.Invoice.objects.count, 1):
                    task = logic.purchase_lot(buyer_id=self.account_2.id,
                                              lot=self.lot_1)

        invoice = bank_prototypes.InvoicePrototype._db_latest()

        self.assertTrue(invoice.state.is_REQUESTED)
        self.assertTrue(invoice.recipient_type.is_GAME_ACCOUNT)
        self.assertTrue(invoice.sender_type.is_GAME_ACCOUNT)
        self.assertTrue(invoice.currency.is_PREMIUM)
        self.assertEqual(invoice.recipient_id, self.account_1.id)
        self.assertEqual(invoice.sender_id, self.account_2.id)
        self.assertEqual(invoice.amount, self.lot_1.price)

        self.assertEqual(task.internal_logic.seller_id, self.account_1.id)
        self.assertEqual(task.internal_logic.buyer_id, self.account_2.id)
        self.assertEqual(task.internal_logic.lot_id, self.lot_1.id)
        self.assertEqual(task.internal_logic.transaction.serialize(),
                         bank_transaction.Transaction(invoice.id).serialize())

        self.assertEqual(cmd_wait_task.call_args_list, [mock.call(task.id)])
Exemplo n.º 2
0
def purchase(context):

    if not context.lot.state.is_ACTIVE:
        raise dext_utils_exceptions.ViewError(code='wrong_lot_state', message='Вы не можете приобрести этот лот')

    if context.lot.seller_id == context.account.id:
        raise dext_utils_exceptions.ViewError(code='can_not_purchase_own_lot', message='Нельзя приобрести свой лот')

    if context.account.bank_account.amount < context.lot.price:
        raise dext_utils_exceptions.ViewError(code='no_money', message='Не хватает средств для приобретения лота')

    task = logic.purchase_lot(context.account.id, context.lot)
    return dext_views.AjaxProcessing(status_url=task.status_url)
Exemplo n.º 3
0
def purchase(context):

    if not context.lot.state.is_ACTIVE:
        raise dext_utils_exceptions.ViewError(
            code='wrong_lot_state', message='Вы не можете приобрести этот лот')

    if context.lot.seller_id == context.account.id:
        raise dext_utils_exceptions.ViewError(
            code='can_not_purchase_own_lot',
            message='Нельзя приобрести свой лот')

    if context.account.bank_account.amount < context.lot.price:
        raise dext_utils_exceptions.ViewError(
            code='no_money',
            message='Не хватает средств для приобретения лота')

    task = logic.purchase_lot(context.account.id, context.lot)
    return dext_views.AjaxProcessing(status_url=task.status_url)
Exemplo n.º 4
0
    def test_purchase_lot(self):

        with mock.patch('the_tale.common.postponed_tasks.workers.refrigerator.Worker.cmd_wait_task') as cmd_wait_task:
            with self.check_delta(postponed_tasks_models.PostponedTask.objects.count, 1):
                with self.check_delta(bank_models.Invoice.objects.count, 1):
                    task = logic.purchase_lot(buyer_id=self.account_2.id, lot=self.lot_1)

        invoice = bank_prototypes.InvoicePrototype._db_latest()

        self.assertTrue(invoice.state.is_REQUESTED)
        self.assertTrue(invoice.recipient_type.is_GAME_ACCOUNT)
        self.assertTrue(invoice.sender_type.is_GAME_ACCOUNT)
        self.assertTrue(invoice.currency.is_PREMIUM)
        self.assertEqual(invoice.recipient_id, self.account_1.id)
        self.assertEqual(invoice.sender_id, self.account_2.id)
        self.assertEqual(invoice.amount, self.lot_1.price)

        self.assertEqual(task.internal_logic.seller_id, self.account_1.id)
        self.assertEqual(task.internal_logic.buyer_id, self.account_2.id)
        self.assertEqual(task.internal_logic.lot_id, self.lot_1.id)
        self.assertEqual(task.internal_logic.transaction.serialize(), bank_transaction.Transaction(invoice.id).serialize())

        self.assertEqual(cmd_wait_task.call_args_list, [mock.call(task.id)])