コード例 #1
0
 def setUp(self):
     '''Should restore only orig receipt at the beginning of subscription.
     '''
     super(TestAppStoreInApps, self).setUp()
     self.store_url = STORE_URL
     self.iface = AppStoreClient(self.store_url)
     self.logger = logging.getLogger('store_test')
     self._crete_user_fixture(USER)
コード例 #2
0
ファイル: tests.py プロジェクト: drewnoff/store-inapp-mock
 def setUp(self):
     '''Should restore only orig receipt at the beginning of subscription.
     '''
     super(TestAppStoreInApps, self).setUp()
     self.store_url = STORE_URL
     self.iface = AppStoreClient(self.store_url)
     self.logger = logging.getLogger('store_test')
     self._crete_user_fixture(USER)
コード例 #3
0
ファイル: tests.py プロジェクト: drewnoff/store-inapp-mock
class TestAppStoreInApps(unittest.TestCase):

    @classmethod
    def print_settings(cls):
        '''Displays tests configuration
        '''
        print 'proxy_url:           %s' % cls.proxy_url

    def _crete_user_fixture(self, user):
        '''Registers user.
        '''
        resp = self.iface.register_user(user)
        # TODO some assert

    def _subscribe(self, user, period, subscription_plan):
        '''Creates InApp autorenewable subscription with @period sec period.
        and subscribes @user according to @subscription_plan.
        '''
        product_id = INAPP_TMPL['product_id'] % str(time.time())
        inapp = dict(INAPP_TMPL)
        inapp['product_id'] = product_id
        inapp['period'] = period
        self.iface.create_inapp(inapp)
        self.iface.subscribe(user['_id'], product_id, subscription_plan)
        return product_id


    def setUp(self):
        '''Should restore only orig receipt at the beginning of subscription.
        '''
        super(TestAppStoreInApps, self).setUp()
        self.store_url = STORE_URL
        self.iface = AppStoreClient(self.store_url)
        self.logger = logging.getLogger('store_test')
        self._crete_user_fixture(USER)

    def test_restore_orig_receipt(self):
        '''Should restore one receipt at the beginning
        '''
        log = self.logger
        user = USER
        log.debug('===test_restore_orig_receipt===')
        subs_plan = [{'value': 'Trial$'},
                     {'value': 'Paid$'},
                     {'value': 'Paid$'},
                     {'idle': 1.4}]
        product_id = self._subscribe(user, 10, subs_plan)
        receipts = self.iface.restore(user['_id'], product_id)['receipts']
        log.debug("resotred receipts: %r", receipts)
        self.assertEqual(len(receipts), 1)

    def test_verify_orig_receipt(self):
        '''Should verify orig receipt.
        Last receipt should be equal current receipt.
        '''
        log = self.logger
        user = USER
        log.debug('===test_verify_orig_receipt===')
        subs_plan = [{'value': 'Trial$'},
                     {'value': 'Paid$'},
                     {'value': 'Paid$'},
                     {'idle': 1.4}]
        product_id = self._subscribe(user, 10, subs_plan)
        receipt = self.iface.restore(user['_id'], product_id)['receipts'][0]
        log.debug("orig receipt: %r", receipt)
        resp = self.iface.verify(receipt)
        self.assertEqual(resp['status'], 0)
        self.assertEqual(resp['receipt']['transaction_id'],
                         receipt['transaction_id'])
        self.assertEqual(resp['receipt']['transaction_id'],
                         resp['latest_receipt_info']['transaction_id'])

    def test_verify_prolonged_subscription(self):
        '''Should retrieve next receipt after subscription prolongation.
        '''
        log = self.logger
        user = USER
        log.debug('===test_verify_prolonged_subscription===')
        subs_plan = [{'value': 'Trial$'},
                     {'value': 'Paid$'},
                     {'value': 'Paid$'},
                     {'idle': 1.4}]
        product_id = self._subscribe(user, 3, subs_plan)
        orig_receipt = self.iface.restore(user['_id'], product_id)['receipts'][-1]
        time.sleep(3)
        resp = self.iface.verify(orig_receipt)
        self.assertEqual(resp['status'], 0)
        latest_receipt = resp['latest_receipt_info']
        receipt = resp['receipt']
        self.assertEqual(receipt['transaction_id'],
                         orig_receipt['transaction_id'])
        self.assertNotEqual(receipt['transaction_id'],
                            latest_receipt['transaction_id'])
        self.assertEqual(receipt['original_transaction_id'],
                         orig_receipt['transaction_id'])
コード例 #4
0
class TestAppStoreInApps(unittest.TestCase):
    @classmethod
    def print_settings(cls):
        '''Displays tests configuration
        '''
        print 'proxy_url:           %s' % cls.proxy_url

    def _crete_user_fixture(self, user):
        '''Registers user.
        '''
        resp = self.iface.register_user(user)
        # TODO some assert

    def _subscribe(self, user, period, subscription_plan):
        '''Creates InApp autorenewable subscription with @period sec period.
        and subscribes @user according to @subscription_plan.
        '''
        product_id = INAPP_TMPL['product_id'] % str(time.time())
        inapp = dict(INAPP_TMPL)
        inapp['product_id'] = product_id
        inapp['period'] = period
        self.iface.create_inapp(inapp)
        self.iface.subscribe(user['_id'], product_id, subscription_plan)
        return product_id

    def setUp(self):
        '''Should restore only orig receipt at the beginning of subscription.
        '''
        super(TestAppStoreInApps, self).setUp()
        self.store_url = STORE_URL
        self.iface = AppStoreClient(self.store_url)
        self.logger = logging.getLogger('store_test')
        self._crete_user_fixture(USER)

    def test_restore_orig_receipt(self):
        '''Should restore one receipt at the beginning
        '''
        log = self.logger
        user = USER
        log.debug('===test_restore_orig_receipt===')
        subs_plan = [{
            'value': 'Trial$'
        }, {
            'value': 'Paid$'
        }, {
            'value': 'Paid$'
        }, {
            'idle': 1.4
        }]
        product_id = self._subscribe(user, 10, subs_plan)
        receipts = self.iface.restore(user['_id'], product_id)['receipts']
        log.debug("resotred receipts: %r", receipts)
        self.assertEqual(len(receipts), 1)

    def test_verify_orig_receipt(self):
        '''Should verify orig receipt.
        Last receipt should be equal current receipt.
        '''
        log = self.logger
        user = USER
        log.debug('===test_verify_orig_receipt===')
        subs_plan = [{
            'value': 'Trial$'
        }, {
            'value': 'Paid$'
        }, {
            'value': 'Paid$'
        }, {
            'idle': 1.4
        }]
        product_id = self._subscribe(user, 10, subs_plan)
        receipt = self.iface.restore(user['_id'], product_id)['receipts'][0]
        log.debug("orig receipt: %r", receipt)
        resp = self.iface.verify(receipt)
        self.assertEqual(resp['status'], 0)
        self.assertEqual(resp['receipt']['transaction_id'],
                         receipt['transaction_id'])
        self.assertEqual(resp['receipt']['transaction_id'],
                         resp['latest_receipt_info']['transaction_id'])

    def test_verify_prolonged_subscription(self):
        '''Should retrieve next receipt after subscription prolongation.
        '''
        log = self.logger
        user = USER
        log.debug('===test_verify_prolonged_subscription===')
        subs_plan = [{
            'value': 'Trial$'
        }, {
            'value': 'Paid$'
        }, {
            'value': 'Paid$'
        }, {
            'idle': 1.4
        }]
        product_id = self._subscribe(user, 3, subs_plan)
        orig_receipt = self.iface.restore(user['_id'],
                                          product_id)['receipts'][-1]
        time.sleep(3)
        resp = self.iface.verify(orig_receipt)
        self.assertEqual(resp['status'], 0)
        latest_receipt = resp['latest_receipt_info']
        receipt = resp['receipt']
        self.assertEqual(receipt['transaction_id'],
                         orig_receipt['transaction_id'])
        self.assertNotEqual(receipt['transaction_id'],
                            latest_receipt['transaction_id'])
        self.assertEqual(receipt['original_transaction_id'],
                         orig_receipt['transaction_id'])