コード例 #1
0
    def testSimple(self):
        """
        create a single transaction with PAYMENT_TYPE_AUTHORIZATION / ACTIVE with a $12.34 pledge and see whether the payment
        manager can query and get the right amount.
        """
        user = User.objects.create_user('payment_test', '*****@*****.**',
                                        'payment_test')

        w = Work()
        w.save()
        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction()
        t.amount = D('12.34')
        t.type = PAYMENT_TYPE_AUTHORIZATION
        t.status = 'ACTIVE'
        t.approved = True
        t.campaign = c
        t.user = user
        t.save()

        #test pledge adders
        user.profile.reset_pledge_badge()
        self.assertEqual(user.profile.badges.all()[0].name, 'pledger')

        p = PaymentManager()
        results = p.query_campaign(c, campaign_total=True, summary=False)
        self.assertEqual(results[0].amount, D('12.34'))
        self.assertEqual(c.left, c.target - D('12.34'))
        self.assertEqual(c.supporters_count, 1)
コード例 #2
0
    def handle(self, *args, **options):
        for work in Work.objects.all():
            if work.campaigns.all().count() > 0:
                continue
            campaign = Campaign()
            campaign.name = work.title
            campaign.work = work
            campaign.description = "Test Campaign"

            # random campaign target between $200 and $10,000
            campaign.target = D(randint(200, 10000))

            # add a test rightsholder recipient right now
            campaign.paypal_receiver = settings.PAYPAL_TEST_RH_EMAIL

            # random deadline between 5 days from now and 180 days from now
            _now = now()
            campaign.deadline = random_date(_now + timedelta(days=5),
                                            _now + timedelta(days=180))

            # randomly activate some of the campaigns
            coinflip = D(randint(0, 10))
            if coinflip > 5:
                campaign.activate()

            campaign.save()
            print "campaign %s...status: %s" % (unicode(campaign).encode(
                'ascii', 'replace'), campaign.status)
コード例 #3
0
ファイル: tests.py プロジェクト: kznmft/regluit
class CampaignUiTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test', '*****@*****.**', 'test')
        self.client = Client()
        # load a Work and a Campaign to create a Pledge page
        self.work = Work(title="test Work")
        self.work.save()
        self.campaign = Campaign(target=D('1000.00'), deadline=now() + timedelta(days=180),
                                 work=self.work, description='dummy description')
        self.campaign.save()

        rh = RightsHolder(owner = self.user, rights_holder_name = 'rights holder name')
        rh.save()
        cl = Claim(rights_holder = rh, work = self.work, user = self.user, status = 'active')
        cl.save()

        self.campaign.activate()

    def test_login_required_for_pledge(self):
        """ Make sure that the user has to be logged in to be able to access a pledge page"""
        pledge_path = reverse("pledge", kwargs={'work_id': self.work.id})
        r = self.client.get(pledge_path)
        self.assertEqual(r.status_code, 302)

        # now login and see whether the pledge page is accessible
        self.client.login(username='******', password='******')
        r = self.client.get(pledge_path)
        self.assertEqual(r.status_code, 200)

    def tearDown(self):
        pass
コード例 #4
0
    def test_paymentmanager_charge(self):
        """
        test regluit.payment.manager.PaymentManager.charge
        
        trying to simulate the conditions of having a bare transaction setup before we try to do
        an instant charge.
        
        """
        user = User.objects.create_user('pm_charge', '*****@*****.**',
                                        'payment_test')
        # need to create an Account to associate with user
        from regluit.payment.stripelib import StripeClient, card, Processor

        sc = StripeClient()

        # valid card and Account
        card0 = card()
        stripe_processor = Processor()
        account = stripe_processor.make_account(user=user, token=card0)

        w = Work()
        w.save()

        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction(host='stripelib')

        t.max_amount = D('12.34')
        t.type = PAYMENT_TYPE_NONE
        t.status = TRANSACTION_STATUS_NONE
        t.campaign = c
        t.approved = False
        t.user = user

        t.save()

        pm = PaymentManager()
        response = pm.charge(t)

        self.assertEqual(t.status, TRANSACTION_STATUS_COMPLETE)
        self.assertEqual(t.type, EXECUTE_TYPE_CHAINED_INSTANT)
        self.assertEqual(t.amount, D('12.34'))
コード例 #5
0
ファイル: tests.py プロジェクト: saspi/regluit
class PledgingUiTests(TestCase):
    fixtures = ['initial_data.json', 'neuromancer.json']

    def setUp(self):
        self.USERNAME = '******'
        self.PASSWORD = '******'
        self.EMAIL = '*****@*****.**'
        self.user = User.objects.create_user(self.USERNAME, self.EMAIL,
                                             self.PASSWORD)
        self.client = Client()

        # login and heck whether user logged in
        self.assertTrue(
            self.client.login(username=self.USERNAME, password=self.PASSWORD))
        # https://stackoverflow.com/a/6013115
        #self.assertEqual(self.client.session['_auth_user_id'], self.user.pk)

        user = auth.get_user(self.client)
        assert user.is_authenticated()

        # load a Work by putting it on the User's wishlist
        r = self.client.post("/wishlist/", {"googlebooks_id": "IDFfMPW32hQC"},
                             HTTP_X_REQUESTED_WITH="XMLHttpRequest")
        self.assertEqual(r.status_code, 200)
        self.assertEqual(self.user.wishlist.works.all().count(), 1)
        wished = self.user.wishlist.works.all()[0]
        # test the work page
        r = self.client.get("/work/%s/" % wished.id)
        self.assertEqual(r.status_code, 200)
        anon_client = Client()
        r = anon_client.get("/work/%s/" % wished.id)
        self.assertEqual(r.status_code, 200)

        # load a Work and a Campaign to create a Pledge page
        self.work = self.user.wishlist.works.all()[0]
        self.campaign = Campaign(target=D('1000.00'),
                                 deadline=now() + timedelta(days=180),
                                 work=self.work,
                                 description='dummy description')
        self.campaign.save()

        rh = RightsHolder(owner=self.user,
                          rights_holder_name='rights holder name')
        rh.save()
        cl = Claim(rights_holder=rh,
                   work=self.work,
                   user=self.user,
                   status='active')
        cl.save()

        self.campaign.activate()

    def test_successful_stripe_pledge(self):
        """can we land on the work page and submit a stripe token?"""
        # work page and hit support

        r = self.client.get("/work/%s/" % self.work.id)
        self.assertEqual(r.status_code, 200)

        # go to pledge page
        r = self.client.get("/pledge/%s" % self.work.id, data={}, follow=True)
        self.assertEqual(r.status_code, 200)

        # submit to pledge page
        r = self.client.post("/pledge/%s" % self.work.id,
                             data={
                                 'preapproval_amount': '10',
                                 'premium_id': '150'
                             },
                             follow=True)
        self.assertEqual(r.status_code, 200)

    def tearDown(self):
        pass