コード例 #1
0
    def _test_process__transaction_frozen(self):
        self.assertEqual([], tt_api.info())
        self.assertIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
        self.assertNotIn(self.card.uid,
                         cards_tt_api.load_cards(self.seller_account.id))

        buy_invoice = bank_prototypes.InvoicePrototype._db_get_object(0)

        self.assertEqual(buy_invoice.amount, self.amount)
        self.assertEqual(buy_invoice.recipient_type,
                         bank_relations.ENTITY_TYPE.GAME_ACCOUNT)
        self.assertEqual(buy_invoice.recipient_id, self.seller_account.id)
        self.assertEqual(buy_invoice.sender_type,
                         bank_relations.ENTITY_TYPE.GAME_ACCOUNT)
        self.assertEqual(buy_invoice.sender_id, self.account.id)

        comission_invoice = bank_prototypes.InvoicePrototype._db_get_object(1)

        self.assertEqual(comission_invoice.amount,
                         -logic.get_commission(self.amount))
        self.assertEqual(comission_invoice.recipient_type,
                         bank_relations.ENTITY_TYPE.GAME_ACCOUNT)
        self.assertEqual(comission_invoice.recipient_id,
                         self.seller_account.id)
        self.assertEqual(comission_invoice.sender_type,
                         bank_relations.ENTITY_TYPE.GAME_LOGIC)
        self.assertEqual(comission_invoice.sender_id, 0)

        self.assertEqual(pm_tt_api.new_messages_number(self.lot.owner_id), 1)
コード例 #2
0
ファイル: test_logic.py プロジェクト: serhii73/the-tale
    def test_give_cards(self):
        with self.check_not_changed(
                lambda: len(cards_tt_api.load_cards(self.account_1.id))):
            with self.check_delta(
                    lambda: len(cards_tt_api.load_cards(self.account_2.id)),
                    1):
                with self.check_not_changed(lambda: len(
                        cards_tt_api.load_cards(self.account_3.id))):
                    with self.check_not_changed(lambda: len(
                            cards_tt_api.load_cards(self.account_4.id))):
                        logic.give_reward_for_template(self.template_2)

        card = list(cards_tt_api.load_cards(self.account_2.id).values())[0]

        self.assertTrue(card.available_for_auction)
コード例 #3
0
    def test_wrong_price(self):
        response = self.post_ajax_json(logic.cancel_sell_lot_url(), {'item_type': self.card.item_full_type,
                                                                     'price': 'wrong_price'})
        self.check_ajax_error(response, 'price.wrong_format')

        self.assertEqual(tt_api.info(), [self.item_info])
        self.assertNotIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
コード例 #4
0
    def test_unlogined(self):
        self.request_logout()
        response = self.post_ajax_json(logic.cancel_sell_lot_url(), {'item_type': self.card.item_full_type, 'price': 100})
        self.check_ajax_error(response, 'common.login_required')

        self.assertEqual(tt_api.info(), [self.item_info])
        self.assertNotIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
コード例 #5
0
    def test_refuse_third_party(self):
        self.request_third_party_token(account=self.account)
        response = self.post_ajax_json(logic.cancel_sell_lot_url(), {'item_type': self.card.item_full_type, 'price': 100})
        self.check_ajax_error(response, 'third_party.access_restricted')

        self.assertEqual(tt_api.info(), [self.item_info])
        self.assertNotIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
コード例 #6
0
    def test_for_fast_account(self):
        self.account.is_fast = True
        self.account.save()
        response = self.post_ajax_json(logic.cancel_sell_lot_url(), {'item_type': self.card.item_full_type, 'price': 100})
        self.check_ajax_error(response, 'common.fast_account')

        self.assertEqual(tt_api.info(), [self.item_info])
        self.assertNotIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
コード例 #7
0
ファイル: test_requests.py プロジェクト: serhii73/the-tale
    def test_no_type(self):
        response = self.post_ajax_json(logic.cancel_sell_lot_url(),
                                       {'price': 666})
        self.check_ajax_error(response, 'item_type.not_specified')

        self.assertEqual(tt_api.info(), [self.item_info])
        self.assertNotIn(self.card.uid,
                         cards_tt_api.load_cards(self.account.id))
コード例 #8
0
ファイル: test_requests.py プロジェクト: serhii73/the-tale
    def test_success(self):
        response = self.post_ajax_json(logic.cancel_sell_lot_url(), {
            'item_type': self.card.item_full_type,
            'price': 100
        })
        self.check_ajax_ok(response)

        self.assertEqual(tt_api.info(), [])
        self.assertIn(self.card.uid, cards_tt_api.load_cards(self.account.id))
コード例 #9
0
    def test_process__transaction_frozen__no_lots(self):
        self.invoice.reload()
        self.invoice.state = bank_relations.INVOICE_STATE.FROZEN
        self.invoice.save()

        self.task.state = self.task.RELATION.TRANSACTION_FROZEN

        tt_api.close_lot(item_type=self.lot.full_type,
                         price=self.lot.price,
                         buyer_id=777)

        self.assertEqual([], tt_api.info())
        self.assertNotIn(self.card.uid,
                         cards_tt_api.load_cards(self.account.id))
        self.assertNotIn(self.card.uid,
                         cards_tt_api.load_cards(self.seller_account.id))

        with self.check_no_messages(recipient_id=self.lot.owner_id):
            with mock.patch(
                    'the_tale.accounts.prototypes.AccountPrototype.cmd_update_hero'
            ) as cmd_update_hero:
                with mock.patch(
                        'the_tale.finances.bank.transaction.Transaction.cancel'
                ) as transaction_cancel:
                    self.assertEqual(
                        self.task.process(main_task=mock.Mock(),
                                          storage=self.storage),
                        postponed_tasks_prototypes.POSTPONED_TASK_LOGIC_RESULT.
                        ERROR)

        self.assertEqual(cmd_update_hero.call_count,
                         self.cmd_update_with_account_data__call_count)
        self.assertEqual(transaction_cancel.call_count, 1)

        self.assertEqual(bank_prototypes.InvoicePrototype._db_count(), 1)

        self.assertEqual(
            self.task.error_message,
            'Не удалось купить карту: только что её купил другой игрок.')
        self.assertTrue(self.task.state.is_CANCELED)

        self.bank_account.reload()
        self.assertEqual(self.bank_account.amount, self.initial_amount)
コード例 #10
0
ファイル: test_logic.py プロジェクト: serhii73/the-tale
    def test_already_given(self):
        with self.check_not_changed(
                lambda: len(cards_tt_api.load_cards(self.account_1.id))):
            with self.check_delta(
                    lambda: len(cards_tt_api.load_cards(self.account_2.id)),
                    1):
                with self.check_not_changed(lambda: len(
                        cards_tt_api.load_cards(self.account_3.id))):
                    with self.check_not_changed(lambda: len(
                            cards_tt_api.load_cards(self.account_4.id))):
                        logic.give_reward_for_template(self.template_2)

        with self.check_not_changed(
                lambda: len(cards_tt_api.load_cards(self.account_1.id))):
            with self.check_not_changed(
                    lambda: len(cards_tt_api.load_cards(self.account_2.id))):
                with self.check_not_changed(lambda: len(
                        cards_tt_api.load_cards(self.account_3.id))):
                    with self.check_not_changed(lambda: len(
                            cards_tt_api.load_cards(self.account_4.id))):
                        logic.give_reward_for_template(self.template_2)
コード例 #11
0
 def _test_process__transaction_requested__invoice_frozen(self):
     self.assertEqual(self.market_basic_information, tt_api.info())
     self.assertNotIn(self.card.uid,
                      cards_tt_api.load_cards(self.account.id))
     self.assertNotIn(self.card.uid,
                      cards_tt_api.load_cards(self.seller_account.id))
コード例 #12
0
 def _test_process__wrong_state(self):
     self.assertNotIn(self.card.uid,
                      cards_tt_api.load_cards(self.account.id))
     self.assertNotIn(self.card.uid,
                      cards_tt_api.load_cards(self.seller_account.id))