def test_VoucherRedeemer(self):
        switch_dbuser('testadmin')

        voucher_proxy = TestSalesforceVoucherProxy()
        self.registerUtility(voucher_proxy, ISalesforceVoucherProxy)

        # Mark has some unredeemed vouchers so set one of them as pending.
        mark = getUtility(IPersonSet).getByName('mark')
        voucher = voucher_proxy.getUnredeemedVouchers(mark)[0]
        product = self.factory.makeProduct(owner=mark)
        redeemed_id = voucher.voucher_id
        self.factory.makeCommercialSubscription(
            product, False, 'pending-%s' % redeemed_id)
        transaction.commit()

        self.runFrequently()

        # There should now be 0 pending vouchers in Launchpad.
        num_rows = IMasterStore(CommercialSubscription).find(
            CommercialSubscription,
            Like(CommercialSubscription.sales_system_id, u'pending-%')
            ).count()
        self.assertThat(num_rows, Equals(0))
        # Salesforce should also now have redeemed the voucher.
        unredeemed_ids = [
            v.voucher_id for v in voucher_proxy.getUnredeemedVouchers(mark)]
        self.assertNotIn(redeemed_id, unredeemed_ids)
Exemple #2
0
 def makeVouchers(self, user, number, voucher_proxy=None):
     if voucher_proxy is None:
         voucher_proxy = TestSalesforceVoucherProxy()
     self.registerUtility(voucher_proxy, ISalesforceVoucherProxy)
     vouchers = []
     for n in xrange(number):
         vouchers.append(voucher_proxy.grantVoucher(user, user, user, 12))
     return vouchers
 def makeVouchers(self, user, number, voucher_proxy=None):
     if voucher_proxy is None:
         voucher_proxy = TestSalesforceVoucherProxy()
     self.registerUtility(voucher_proxy, ISalesforceVoucherProxy)
     vouchers = []
     for n in xrange(number):
         vouchers.append(voucher_proxy.grantVoucher(user, user, user, 12))
     return vouchers
    def test_redeem_twice_with_commercial_admin(self):
        # The fields are setup if the commercial admin has vouchers.
        commercial_admin = login_celebrity('commercial_admin')
        voucher_proxy = TestSalesforceVoucherProxy()
        voucher_id_1, voucher_id_2 = self.makeVouchers(
            commercial_admin, 2, voucher_proxy)
        project_1 = self.factory.makeProduct()
        project_2 = self.factory.makeProduct()
        form = self.makeForm(project_1, voucher_id_1)
        view = create_initialized_view(
            commercial_admin, '+vouchers', form=form)
        self.assertRedeem(view, project_1, remaining=1)
        # A job will notify Salesforce of the voucher redemption but here we
        # will do it manually.
        voucher_proxy.redeemVoucher(
            voucher_id_1, commercial_admin, project_1)

        form = self.makeForm(project_2, voucher_id_2)
        view = create_initialized_view(
            commercial_admin, '+vouchers', form=form)
        self.assertRedeem(view, project_2)
Exemple #5
0
    def test_redeem_twice_with_commercial_admin(self):
        # The fields are setup if the commercial admin has vouchers.
        commercial_admin = login_celebrity('commercial_admin')
        voucher_proxy = TestSalesforceVoucherProxy()
        voucher_id_1, voucher_id_2 = self.makeVouchers(commercial_admin, 2,
                                                       voucher_proxy)
        project_1 = self.factory.makeProduct()
        project_2 = self.factory.makeProduct()
        form = self.makeForm(project_1, voucher_id_1)
        view = create_initialized_view(commercial_admin,
                                       '+vouchers',
                                       form=form)
        self.assertRedeem(view, project_1, remaining=1)
        # A job will notify Salesforce of the voucher redemption but here we
        # will do it manually.
        voucher_proxy.redeemVoucher(voucher_id_1, commercial_admin, project_1)

        form = self.makeForm(project_2, voucher_id_2)
        view = create_initialized_view(commercial_admin,
                                       '+vouchers',
                                       form=form)
        self.assertRedeem(view, project_2)