def setUp(self): super(PremiumDaysTests, self).setUp() create_test_map() self.days = 30 self.cost = 130 self.account = self.accounts_factory.create_account() self.hero = heroes_logic.load_hero(account_id=self.account.id) self.purchase = PremiumDays(uid='premium-days-uid', name='premium-days-name', description='premium-days-description', cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER), days=self.days, transaction_description='premium-days-transaction-description')
def setUp(self): super(PremiumDaysTests, self).setUp() create_test_map() self.days = 30 self.cost = 130 result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) self.hero = HeroPrototype.get_by_account_id(account_id) self.purchase = PremiumDays( uid='premium-days-uid', name=u'premium-days-name', description=u'premium-days-description', cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER), days=self.days, transaction_description='premium-days-transaction-description')
def setUp(self): super(PremiumDaysTests, self).setUp() create_test_map() self.days = 30 self.cost = 130 result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account = AccountPrototype.get_by_id(account_id) self.hero = heroes_logic.load_hero(account_id=account_id) self.purchase = PremiumDays(uid='premium-days-uid', name=u'premium-days-name', description=u'premium-days-description', cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER), days=self.days, transaction_description='premium-days-transaction-description')
def setUp(self): super(PremiumDaysTests, self).setUp() create_test_map() self.days = 30 self.cost = 130 result, account_id, bundle_id = register_user("test_user", "*****@*****.**", "111111") self.account = AccountPrototype.get_by_id(account_id) self.hero = HeroPrototype.get_by_account_id(account_id) self.purchase = PremiumDays( uid="premium-days-uid", name=u"premium-days-name", description=u"premium-days-description", cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER), days=self.days, transaction_description="premium-days-transaction-description", )
class PremiumDaysTests(testcase.TestCase): def setUp(self): super(PremiumDaysTests, self).setUp() create_test_map() self.days = 30 self.cost = 130 self.account = self.accounts_factory.create_account() self.hero = heroes_logic.load_hero(account_id=self.account.id) self.purchase = PremiumDays(uid='premium-days-uid', name='premium-days-name', description='premium-days-description', cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER), days=self.days, transaction_description='premium-days-transaction-description') def test_create(self): self.assertEqual(self.purchase.uid, 'premium-days-uid') self.assertEqual(self.purchase.days, self.days) self.assertEqual(self.purchase.cost, self.cost) self.assertEqual(self.purchase.name, 'premium-days-name') self.assertEqual(self.purchase.description, 'premium-days-description') self.assertEqual(self.purchase.transaction_description, 'premium-days-transaction-description') def test_buy__fast_account(self): self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0) self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 0) self.account.is_fast = True self.account.save() self.assertRaises(exceptions.FastAccountError, self.purchase.buy, account=self.account) self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0) self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 0) def test_buy(self): self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0) self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 0) with mock.patch('the_tale.common.postponed_tasks.prototypes.PostponedTaskPrototype.cmd_wait') as cmd_wait: self.purchase.buy(account=self.account) self.assertEqual(cmd_wait.call_count, 1) self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 1) self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 1) postponed_logic = PostponedTaskPrototype._db_get_object(0).internal_logic self.assertTrue(isinstance(postponed_logic, BuyPremium)) self.assertEqual(postponed_logic.account_id, self.account.id) self.assertEqual(postponed_logic.days, self.days) invoice = InvoicePrototype.get_by_id(postponed_logic.transaction.invoice_id) self.assertEqual(invoice.recipient_type, ENTITY_TYPE.GAME_ACCOUNT) self.assertEqual(invoice.recipient_id, self.account.id) self.assertEqual(invoice.sender_type, ENTITY_TYPE.GAME_LOGIC) self.assertEqual(invoice.sender_id, 0) self.assertEqual(invoice.currency, CURRENCY_TYPE.PREMIUM) self.assertEqual(invoice.amount, -self.cost) self.assertEqual(invoice.description_for_sender, 'premium-days-transaction-description') self.assertEqual(invoice.description_for_recipient, 'premium-days-transaction-description') def test_is_purchasable(self): self.assertTrue(self.purchase.is_purchasable(self.account, self.hero)) def test_is_purchasable__premium(self): self.account.prolong_premium(30) self.assertTrue(self.purchase.is_purchasable(self.account, self.hero))