예제 #1
0
    def test_funding_admin_add_matching(self):
        self.funding.states.submit()
        self.funding.states.approve()
        self.funding.target = Money(100, 'EUR')
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(70, 'EUR'))
        donation.states.succeed(save=True)
        PledgePaymentFactory.create(donation=donation)
        self.assertEqual(self.funding.amount_raised, Money(70, 'EUR'))
        self.funding.deadline = now() - timedelta(days=1)
        self.funding.save()
        self.assertEqual(self.funding.amount_raised, Money(70, 'EUR'))
        self.funding.amount_matching = Money(30, 'EUR')
        self.funding.save()

        self.client.force_login(self.superuser)
        response = self.client.get(self.admin_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertContains(response, self.funding.title)
        self.assertContains(response, 'recalculate')
        recalculate_url = reverse('admin:funding_funding_state_transition',
                                  args=(self.funding.id, 'states',
                                        'recalculate'))

        self.assertContains(response, recalculate_url)
        self.client.post(recalculate_url, {'confirm': True})
        self.funding.refresh_from_db()
        self.assertEqual(self.funding.status, 'succeeded')
        self.funding.save()
        self.assertEqual(self.funding.amount_raised, Money(100, 'EUR'))
예제 #2
0
 def test_refund_activity(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.assertEqual(donation.status, 'succeeded')
     donation.states.activity_refund(save=True)
     self.assertEqual(donation.status, 'activity_refunded')
    def test_enough_donations(self):
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(300, 'EUR'))
        PledgePaymentFactory.create(donation=donation)
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(450, 'EUR'))
        PledgePaymentFactory.create(donation=donation)
        self.assertEqual(len(mail.outbox), 4)
        self.assertEqual(donation.status, 'succeeded')
        self.funding.deadline = now() - timedelta(days=1)
        self.funding.save()

        # Run scheduled task
        tenant = connection.tenant
        funding_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            self.funding.refresh_from_db()

        self.assertEqual(len(mail.outbox), 5)
        self.assertEqual(
            mail.outbox[4].subject,
            u'Your campaign "{}" has been successfully completed! \U0001f389'.
            format(self.funding.title))
        self.assertTrue('Hi Jean Baptiste,' in mail.outbox[4].body)
        self.assertTrue(self.funding.title in mail.outbox[4].body)
        url = 'http://testserver/en/initiatives/activities/details/funding/{}/{}'.format(
            self.funding.id, self.funding.slug)
        self.assertTrue(url in mail.outbox[4].body)

        organizer = self.funding.contributions.instance_of(Organizer).get()
        self.assertEqual(organizer.status, organizer.states.succeeded.value)
예제 #4
0
 def test_refund_remove_wallpost(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.assertEqual(Wallpost.objects.count(), 1)
     donation.payment.states.refund(save=True)
     self.assertEqual(Wallpost.objects.count(), 0)
예제 #5
0
    def setUp(self):
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(
            initiative=self.initiative,
            duration=30,
            target=Money(1000, 'EUR')
        )
        BudgetLineFactory.create(activity=self.funding)
        payout_account = StripePayoutAccountFactory.create(reviewed=True, status='verified')
        self.bank_account = ExternalAccountFactory.create(connect_account=payout_account, status='verified')
        self.funding.bank_account = self.bank_account
        self.funding.states.submit()
        self.funding.states.approve(save=True)

        for donation in DonationFactory.create_batch(
                3,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                2,
                amount=Money(200, 'USD'),
                payout_amount=(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        donation = DonationFactory.create(
            amount=Money(750, 'EUR'),
            activity=self.funding,
            status='succeeded')
        PledgePaymentFactory.create(donation=donation)

        self.donation = donation

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)
예제 #6
0
 def test_close_with_donations(self):
     mail.outbox = []
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     with self.assertRaisesMessage(TransitionNotPossible,
                                   'Conditions not met for transition'):
         self.funding.states.reject(save=True)
예제 #7
0
 def _prepare_succeeded(self):
     self.funding.states.submit()
     self.funding.states.approve(save=True)
     self.assertEqual(self.funding.status, 'open')
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(1000, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.funding.deadline = now() - timedelta(days=1)
예제 #8
0
 def test_refund_unfollow(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.assertTrue(
         self.funding.followers.filter(user=donation.user).exists())
     donation.payment.states.refund(save=True)
     self.assertFalse(
         self.funding.followers.filter(user=donation.user).exists())
예제 #9
0
 def test_refund_activity_mail_supporter(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     mail.outbox = []
     donation.states.activity_refund(save=True)
     self.assertEqual(
         mail.outbox[0].subject,
         u'Your donation for the campaign "{}" will be refunded'.format(
             self.funding.title))
예제 #10
0
    def test_donation_total(self):
        for donation in DonationFactory.create_batch(2,
                                                     activity=self.funding,
                                                     amount=Money(100, 'NGN')):
            PledgePaymentFactory.create(donation=donation)

        self.client.force_login(self.superuser)
        response = self.client.get(self.admin_url)
        self.assertTrue(u'Total amount:  <b>0.60 €</b>'.encode('utf-8') in
                        response.content)
예제 #11
0
 def test_refund_update_amounts(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(250, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.assertEqual(self.funding.amount_raised, Money(750, 'EUR'))
     donation.payment.states.refund(save=True)
     self.assertEqual(self.funding.amount_raised, Money(500, 'EUR'))
예제 #12
0
 def _prepare_extend(self):
     self.funding.states.submit()
     self.funding.states.approve(save=True)
     self.assertEqual(self.funding.status, 'open')
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     # Changing the deadline to the past should trigger a transition
     self.funding.deadline = now() - timedelta(days=1)
     self.funding.save()
     self.funding.refresh_from_db()
     self.assertEqual(self.funding.status, 'partially_funded')
예제 #13
0
    def test_pledge(self):
        self.funding.states.succeed(save=True)

        contribution = DonationFactory.create(activity=self.funding,
                                              user=self.other_user,
                                              amount=Money(50, 'EUR'))
        PledgePaymentFactory.create(donation=contribution)

        self.assertEqual(self.stats.activities_online, 0)
        self.assertEqual(self.stats.activities_succeeded, 1)
        self.assertEqual(self.stats.fundings_succeeded, 1)
        self.assertEqual(self.stats.pledged_total, Money(50, 'EUR'))
        self.assertEqual(self.stats.donated_total, Money(50, 'EUR'))
        self.assertEqual(self.stats.donations, 1)
        self.assertEqual(self.stats.people_involved, 2)
예제 #14
0
    def setUp(self):
        super(TestPayoutAdapter, self).setUp()
        self.funding = FundingFactory.create(target=Money(500, 'EUR'),
                                             status='open')
        donations = DonationFactory.create_batch(7,
                                                 activity=self.funding,
                                                 amount=Money(100, 'EUR'))
        for donation in donations:
            PledgePaymentFactory.create(donation=donation)
        yesterday = now() - timedelta(days=1)
        self.funding.deadline = yesterday
        self.funding.save()

        self.mock_response = requests.Response()
        self.mock_response.status_code = 200

        self.adapter = DoradoPayoutAdapter(self.funding)
    def test_extend_past_deadline(self):
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(1000, 'EUR'))
        PledgePaymentFactory.create(donation=donation)

        self.funding.deadline = now() - timedelta(days=1)
        self.funding.save()

        # Run scheduled task
        tenant = connection.tenant
        funding_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            self.funding.refresh_from_db()

        self.assertEqual(self.funding.status, 'succeeded')

        with self.assertRaises(TransitionNotPossible):
            self.funding.states.extend(save=True)
 def test_funding_scheduled_task_partial(self):
     donation = DonationFactory.create(activity=self.funding,
                                       user=BlueBottleUserFactory.create(),
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.funding.deadline = now() - timedelta(days=1)
     mail.outbox = []
     tenant = connection.tenant
     with mock.patch.object(timezone,
                            'now',
                            return_value=(timezone.now() +
                                          timedelta(days=20))):
         funding_tasks()
     with LocalTenant(tenant, clear_tenant=True):
         self.funding.refresh_from_db()
     self.assertEqual(self.funding.status, 'partially_funded')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      u'Your crowdfunding campaign deadline passed')
예제 #17
0
 def test_trigger_lower_target(self):
     self.assertEqual(self.funding.status,
                      FundingStateMachine.submitted.value)
     self.funding.states.approve(save=True)
     self.assertEqual(self.funding.status, FundingStateMachine.open.value)
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     # Changing the deadline to the past should trigger a transition
     self.funding.deadline = now() - timedelta(days=1)
     self.funding.save()
     self.funding.refresh_from_db()
     self.assertEqual(self.funding.status,
                      FundingStateMachine.partially_funded.value)
     # Lower target of the project should transition it to succeeded
     self.funding.target = Money(500, 'EUR')
     self.funding.save()
     self.funding.refresh_from_db()
     self.assertEqual(self.funding.status,
                      FundingStateMachine.succeeded.value)
예제 #18
0
    def test_refund(self):
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(500, 'EUR'))
        PledgePaymentFactory.create(donation=donation)
        self.assertEqual(donation.status, 'succeeded')

        mail.outbox = []
        donation.payment.states.refund(save=True)
        self.assertEqual(donation.status, 'refunded')

        self.assertEqual(mail.outbox[0].recipients(), [donation.user.email])

        self.assertEqual(
            mail.outbox[0].subject,
            u'Your donation for the campaign "{}" will be refunded'.format(
                self.funding.title))

        self.assertTrue(
            'You have requested a refund for your donation to the campaign "{}"'
            .format(self.funding.title) in mail.outbox[0].body)
 def test_funding_scheduled_task_succeed(self):
     donation = DonationFactory.create(activity=self.funding,
                                       user=BlueBottleUserFactory.create(),
                                       amount=Money(1000, 'EUR'))
     PledgePaymentFactory.create(donation=donation)
     self.funding.deadline = now() - timedelta(days=1)
     mail.outbox = []
     tenant = connection.tenant
     with mock.patch.object(timezone,
                            'now',
                            return_value=(timezone.now() +
                                          timedelta(days=20))):
         funding_tasks()
     with LocalTenant(tenant, clear_tenant=True):
         self.funding.refresh_from_db()
     self.assertEqual(self.funding.status, 'succeeded')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(
         mail.outbox[0].subject,
         u'Your campaign "{}" has been successfully completed! \U0001f389'.
         format(self.funding.title))
예제 #20
0
 def setUp(self):
     self.initiative = InitiativeFactory.create()
     self.initiative.states.submit()
     self.initiative.states.approve(save=True)
     self.payout_account = PlainPayoutAccountFactory.create(
         status='verified'
     )
     self.bank_account = BankAccountFactory.create(connect_account=self.payout_account, status='verified')
     self.funding = FundingFactory.create(
         initiative=self.initiative,
         target=Money(1000, 'EUR'),
         duration=30,
         bank_account=self.bank_account
     )
     BudgetLineFactory.create(activity=self.funding)
     self.funding.states.submit(save=True)
     self.donation = DonationFactory.create(
         activity=self.funding,
         amount=Money(100, 'EUR'),
         status='succeeded'
     )
     PledgePaymentFactory.create(donation=self.donation)
    def test_extend(self):
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(1000, 'EUR'))
        PledgePaymentFactory.create(donation=donation)

        self.funding.deadline = now() + timedelta(days=1)
        self.funding.save()

        # Run scheduled task
        tenant = connection.tenant
        future = now() + timedelta(days=2)
        with mock.patch.object(timezone, 'now', return_value=future):
            funding_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            self.funding.refresh_from_db()

        self.assertEqual(self.funding.status, 'succeeded')

        self.funding.deadline = now() + timedelta(days=1)
        self.funding.save()

        # self.funding.states.extend()
        self.assertEqual(self.funding.status, 'open')
예제 #22
0
    def test_donation_admin_pledge_filter(self):
        for donation in DonationFactory.create_batch(2, activity=self.funding):
            PledgePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(7, activity=self.funding):
            StripePaymentFactory.create(donation=donation)

        self.client.force_login(self.superuser)

        response = self.client.get(self.admin_url, {'status__exact': 'all'})
        self.assertContains(response, '9 Donations')

        response = self.client.get(self.admin_url, {
            'status__exact': 'all',
            'pledge': 'paid'
        })
        self.assertContains(response, '7 Donations')

        response = self.client.get(self.admin_url, {
            'status__exact': 'all',
            'pledge': 'pledged'
        })
        self.assertContains(response, '2 Donations')
    def test_some_donations(self):
        user = BlueBottleUserFactory.create(first_name='Bill')
        donation = DonationFactory.create(user=user,
                                          activity=self.funding,
                                          amount=Money(50, 'EUR'))
        donation.states.succeed(save=True)
        PledgePaymentFactory.create(donation=donation)
        self.assertEqual(donation.status, donation.states.succeeded.value)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].subject,
                         u'You have a new donation!💰')
        self.assertEqual(mail.outbox[1].subject, 'Thanks for your donation!')
        self.assertTrue('Hi Jean Baptiste,' in mail.outbox[0].body)
        self.assertTrue('Hi Bill,' in mail.outbox[1].body)

        # Donation amount should appear in both emails
        self.assertTrue(u'50.00 €' in mail.outbox[0].body)
        self.assertTrue(u'50.00 €' in mail.outbox[1].body)

        self.funding.deadline = now() - timedelta(days=1)
        self.funding.save()

        # Run scheduled task
        tenant = connection.tenant
        funding_tasks()
        with LocalTenant(tenant, clear_tenant=True):
            self.funding.refresh_from_db()

        self.assertEqual(self.funding.status, 'partially_funded')
        self.assertEqual(len(mail.outbox), 3)
        self.assertEqual(mail.outbox[2].subject,
                         'Your crowdfunding campaign deadline passed')
        self.assertTrue('Hi Jean Baptiste,' in mail.outbox[0].body)
        self.assertTrue(self.funding.title in mail.outbox[0].body)
        url = 'http://testserver/en/initiatives/activities/details/funding/{}/{}'.format(
            self.funding.id, self.funding.slug)
        self.assertTrue(url in mail.outbox[0].body)
    def test_refund(self):
        donation = DonationFactory.create(activity=self.funding,
                                          amount=Money(50, 'EUR'))
        PledgePaymentFactory.create(donation=donation)

        self.funding.deadline = now() - timedelta(days=1)
        self.funding.save()

        tenant = connection.tenant
        funding_tasks()

        with LocalTenant(tenant, clear_tenant=True):
            self.funding.refresh_from_db()

        self.funding.refresh_from_db()
        self.assertEqual(self.funding.status, 'partially_funded')
        self.funding.states.refund(save=True)

        for contribution in self.funding.donations.all():
            self.assertEqual(contribution.status,
                             contribution.states.activity_refunded.value)

        self.funding.update_amounts()
        self.assertEqual(self.funding.amount_raised, donation.amount)