Exemple #1
0
    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        self.cost = 130

        self.account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=self.account.id)

        self.purchase = PermanentPurchase(uid='clan-creation-rights',
                                          name=self.PURCHASE_TYPE.text,
                                          description=self.PURCHASE_TYPE.description,
                                          cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER),
                                          purchase_type=self.PURCHASE_TYPE,
                                          transaction_description='clan-creation-rights')
Exemple #2
0
    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        self.cost = 130

        self.account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=self.account.id)

        self.purchase = PermanentPurchase(
            uid='infinit-subscription',
            name=self.PURCHASE_TYPE.text,
            description=self.PURCHASE_TYPE.description,
            cost=self.cost,
            purchase_type=self.PURCHASE_TYPE,
            transaction_description='infinit-subscription')
Exemple #3
0
    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        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 = PermanentPurchase(
            uid=u'clan-creation-rights',
            name=self.PURCHASE_TYPE.text,
            description=self.PURCHASE_TYPE.description,
            cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER),
            purchase_type=self.PURCHASE_TYPE,
            transaction_description=u'clan-creation-rights')
Exemple #4
0
    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        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 = PermanentPurchase(uid=u'clan-creation-rights',
                                          name=self.PURCHASE_TYPE.text,
                                          description=self.PURCHASE_TYPE.description,
                                          cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER),
                                          purchase_type=self.PURCHASE_TYPE,
                                          transaction_description=u'clan-creation-rights')
Exemple #5
0
class PermanentPurchaseTests(testcase.TestCase):

    PURCHASE_TYPE = PERMANENT_PURCHASE_TYPE.CLAN_OWNERSHIP_RIGHT

    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        self.cost = 130

        self.account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=self.account.id)

        self.purchase = PermanentPurchase(uid='clan-creation-rights',
                                          name=self.PURCHASE_TYPE.text,
                                          description=self.PURCHASE_TYPE.description,
                                          cost=int(self.cost / payments_settings.GLOBAL_COST_MULTIPLIER),
                                          purchase_type=self.PURCHASE_TYPE,
                                          transaction_description='clan-creation-rights')


    def test_create(self):
        self.assertEqual(self.purchase.uid, 'clan-creation-rights')
        self.assertEqual(self.purchase.purchase_type, self.PURCHASE_TYPE)
        self.assertEqual(self.purchase.cost, self.cost)
        self.assertEqual(self.purchase.name, self.PURCHASE_TYPE.text)
        self.assertEqual(self.purchase.description, self.PURCHASE_TYPE.description)
        self.assertEqual(self.purchase.transaction_description, 'clan-creation-rights')

    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, BuyPermanentPurchase))
        self.assertEqual(postponed_logic.account_id, self.account.id)
        self.assertEqual(postponed_logic.purchase_type, self.PURCHASE_TYPE)

        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, 'clan-creation-rights')
        self.assertEqual(invoice.description_for_recipient, 'clan-creation-rights')

    def test_is_purchasable(self):
        self.assertTrue(self.purchase.is_purchasable(self.account, self.hero))

    def test_is_purchasable__already_purchased(self):
        self.account.permanent_purchases.insert(self.PURCHASE_TYPE)
        self.assertFalse(self.purchase.is_purchasable(self.account, self.hero))

    # TODO: other purchases must be checked in same way
    def test_is_purchasable__have_might(self):
        self.account.set_might(clans_settings.OWNER_MIGHT_REQUIRED)
        self.assertFalse(self.purchase.is_purchasable(self.account, self.hero))
Exemple #6
0
class PermanentPurchaseTests(testcase.TestCase):

    PURCHASE_TYPE = PERMANENT_PURCHASE_TYPE.INFINIT_SUBSCRIPTION

    def setUp(self):
        super(PermanentPurchaseTests, self).setUp()

        create_test_map()

        self.cost = 130

        self.account = self.accounts_factory.create_account()
        self.hero = heroes_logic.load_hero(account_id=self.account.id)

        self.purchase = PermanentPurchase(
            uid='infinit-subscription',
            name=self.PURCHASE_TYPE.text,
            description=self.PURCHASE_TYPE.description,
            cost=self.cost,
            purchase_type=self.PURCHASE_TYPE,
            transaction_description='infinit-subscription')

    def test_create(self):
        self.assertEqual(self.purchase.uid, 'infinit-subscription')
        self.assertEqual(self.purchase.purchase_type, self.PURCHASE_TYPE)
        self.assertEqual(self.purchase.cost, self.cost)
        self.assertEqual(self.purchase.name, self.PURCHASE_TYPE.text)
        self.assertEqual(self.purchase.description,
                         self.PURCHASE_TYPE.description)
        self.assertEqual(self.purchase.transaction_description,
                         'infinit-subscription')

    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, BuyPermanentPurchase))
        self.assertEqual(postponed_logic.account_id, self.account.id)
        self.assertEqual(postponed_logic.purchase_type, self.PURCHASE_TYPE)

        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,
                         'infinit-subscription')
        self.assertEqual(invoice.description_for_recipient,
                         'infinit-subscription')

    def test_is_purchasable(self):
        self.assertTrue(self.purchase.is_purchasable(self.account, self.hero))

    def test_is_purchasable__already_purchased(self):
        self.account.permanent_purchases.insert(self.PURCHASE_TYPE)
        self.assertFalse(self.purchase.is_purchasable(self.account, self.hero))