def test_process__processed(self): self.assertEqual(BankInvoicePrototype._db_count(), 0) invoice = self.create_invoice(worker_call_count=1) self.assertEqual(invoice.bank_invoice_id, None) invoice.process() invoice.reload() self.assertEqual(BankInvoicePrototype._db_count(), 1) self.assertTrue(invoice.state.is_PROCESSED) bank_invoice = BankInvoicePrototype._db_get_object(0) self.assertEqual(bank_invoice.id, invoice.bank_invoice_id) self.assertTrue(bank_invoice.recipient_type.is_GAME_ACCOUNT) self.assertEqual(bank_invoice.recipient_id, self.fabric.account_id) self.assertTrue(bank_invoice.sender_type.is_XSOLLA) self.assertEqual(bank_invoice.sender_id, 0) self.assertTrue(bank_invoice.state.is_FORCED) self.assertTrue(bank_invoice.currency.is_PREMIUM) self.assertTrue(bank_invoice.amount, int(self.fabric.payment_sum)) self.assertEqual(bank_invoice.operation_uid, 'bank-xsolla')
def test_process__test(self): self.assertEqual(BankInvoicePrototype._db_count(), 0) invoice = self.create_invoice(worker_call_count=1, test='1') invoice.process() invoice.reload() self.assertEqual(BankInvoicePrototype._db_count(), 0) self.assertTrue(invoice.state.is_SKIPPED_BECOUSE_TEST)
def test_unlogined(self): self.request_logout() self.check_ajax_error( self.post_ajax_json( url('shop:give-money', account=self.account.id), self.post_data()), 'common.login_required') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_from_errors(self): self.check_ajax_error( self.client.post(url('shop:give-money', account=self.account.id), { 'amount': 'x', 'description': 'bla-bla' }), 'form_errors') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_process__wait_confirmation__transaction_confirmed__with_referal( self): self.invoice.state = INVOICE_STATE.CONFIRMED self.invoice.save() result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account._model.referral_of_id = account_id self.account.save() self.task.state = self.task.RELATION.WAIT_TRANSACTION_CONFIRMATION self.assertEqual(self.task.process(main_task=mock.Mock()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(InvoicePrototype._db_count(), 2) referral_invoice = InvoicePrototype._db_get_object(1) self.assertTrue(referral_invoice.amount > 0) self.assertTrue(referral_invoice.amount < self.amount) self.assertEqual(referral_invoice.recipient_id, account_id) self.assertTrue(referral_invoice.state.is_FORCED) self.assertTrue(self.task.state.is_SUCCESSED)
def test_for_fast_account(self): self.account.is_fast = True self.account.save() self.check_ajax_error( self.client.post(url('shop:give-money', account=self.account.id), self.post_data()), 'fast_account') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_process__wait_confirmation__transaction_confirmed__with_referal(self): self.invoice.reload() self.invoice.state = INVOICE_STATE.CONFIRMED self.invoice.save() account_2 = self.accounts_factory.create_account() self.account._model.referral_of_id = account_2.id self.account.save() self.task.state = self.task.RELATION.WAIT_TRANSACTION_CONFIRMATION self.assertEqual(self.task.process(main_task=mock.Mock()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(InvoicePrototype._db_count(), (2 if self.with_referrals else 1)) if self.with_referrals: referral_invoice = InvoicePrototype._db_get_object(1) self.assertTrue(referral_invoice.amount > 0) self.assertTrue(referral_invoice.amount < self.amount) self.assertEqual(referral_invoice.recipient_id, account_2.id) self.assertTrue(referral_invoice.state.is_FORCED) self.assertTrue(self.task.state.is_SUCCESSED)
def test_success(self): self.assertEqual(BankInvoicePrototype._db_count(), 0) response = self.post_ajax_json(url('shop:give-money', account=self.account.id), self.post_data(amount=5)) self.assertEqual(BankInvoicePrototype._db_count(), 1) invoice = BankInvoicePrototype._db_get_object(0) self.assertTrue(invoice.recipient_type.is_GAME_ACCOUNT) self.assertEqual(invoice.recipient_id, self.account.id) self.assertTrue(invoice.sender_type.is_GAME_MASTER) self.assertEqual(invoice.sender_id, self.superuser.id) self.assertTrue(invoice.currency.is_PREMIUM) self.assertEqual(invoice.amount, 5) self.assertEqual(invoice.description_for_recipient, u'bla-bla') self.assertTrue(invoice.state.is_FORCED) self.check_ajax_ok(response)
def test_success(self): self.assertEqual(BankInvoicePrototype._db_count(), 0) response = self.post_ajax_json(url('shop:give-money', account=self.account.id), self.post_data(amount=5)) self.assertEqual(BankInvoicePrototype._db_count(), 1) invoice = BankInvoicePrototype._db_get_object(0) self.assertTrue(invoice.recipient_type.is_GAME_ACCOUNT) self.assertEqual(invoice.recipient_id, self.account.id) self.assertTrue(invoice.sender_type.is_GAME_MASTER) self.assertEqual(invoice.sender_id, self.superuser.id) self.assertTrue(invoice.currency.is_PREMIUM) self.assertEqual(invoice.amount, 5) self.assertEqual(invoice.description_for_recipient, 'bla-bla') self.assertTrue(invoice.state.is_FORCED) self.check_ajax_ok(response)
def test_process__wait_confirmation__transaction_confirmed__with_referal(self): self.invoice.state = INVOICE_STATE.CONFIRMED self.invoice.save() result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account._model.referral_of_id = account_id self.account.save() self.task.state = self.task.RELATION.WAIT_TRANSACTION_CONFIRMATION self.assertEqual(self.task.process(main_task=mock.Mock()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS) self.assertEqual(InvoicePrototype._db_count(), 2) referral_invoice = InvoicePrototype._db_get_object(1) self.assertTrue(referral_invoice.amount > 0) self.assertTrue(referral_invoice.amount < self.amount) self.assertEqual(referral_invoice.recipient_id, account_id) self.assertTrue(referral_invoice.state.is_FORCED) self.assertTrue(self.task.state.is_SUCCESSED)
def test_from_errors(self): self.check_ajax_error(self.client.post(url('shop:give-money', account=self.account.id), {'amount': 'x', 'description': u'bla-bla'}), 'form_errors') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_for_wront_account(self): self.check_ajax_error(self.client.post(url('shop:give-money', account='xxx'), self.post_data()), 'account.wrong_format') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_for_fast_account(self): self.account.is_fast = True self.account.save() self.check_ajax_error(self.client.post(url('shop:give-money', account=self.account.id), self.post_data()), 'fast_account') self.assertEqual(BankInvoicePrototype._db_count(), 0)
def test_unlogined(self): self.request_logout() self.check_ajax_error(self.post_ajax_json(url('shop:give-money', account=self.account.id), self.post_data()), 'common.login_required') self.assertEqual(BankInvoicePrototype._db_count(), 0)