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)
示例#2
0
 def test_fail_update_amounts(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     donation.states.succeed(save=True)
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(250, 'EUR'))
     donation.states.succeed(save=True)
     self.assertEqual(self.funding.amount_raised, Money(750, 'EUR'))
     donation.states.fail(save=True)
     self.assertEqual(self.funding.amount_raised, Money(500, 'EUR'))
示例#3
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'))
示例#4
0
    def setUp(self):
        super(ContributionListAPITestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory.create()

        ParticipantFactory.create_batch(2, user=self.user)
        ApplicantFactory.create_batch(2, user=self.user)
        DonationFactory.create_batch(2, user=self.user, status='succeeded')
        DonationFactory.create_batch(2, user=self.user, status='new')

        ParticipantFactory.create()
        ApplicantFactory.create()
        DonationFactory.create()

        self.url = reverse('contribution-list')
示例#5
0
 def test_succeed_mail_supporter(self):
     mail.outbox = []
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     donation.states.succeed(save=True)
     self.assertEqual(mail.outbox[0].subject,
                      u'You have a new donation!\U0001f4b0')
示例#6
0
 def test_succeed_follow(self):
     mail.outbox = []
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     donation.states.succeed(save=True)
     self.assertTrue(
         self.funding.followers.filter(user=donation.user).exists())
示例#7
0
 def test_refund_donation_refunded(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.succeed(save=True)
     payment.states.refund(save=True)
     self.assertEqual(donation.status, 'refunded')
示例#8
0
 def test_fail_remove_wallpost(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     donation.states.succeed(save=True)
     self.assertEqual(Wallpost.objects.count(), 1)
     donation.states.fail(save=True)
     self.assertEqual(Wallpost.objects.count(), 0)
示例#9
0
 def test_webhook_bank_transfer_without_payment(self):
     donation = DonationFactory.create()
     payload = {
         "data": {
             "id": 1231,
             "tx_ref": donation.id,
             "flw_ref": "FLW-MOCK-2345235235",
             "amount": 19500,
             "currency": "NGN",
             "status": "successful",
             "amountsettledforthistransaction": 17500,
             "customer": {
                 "id": 154159,
             },
         },
         "event": "charge.completed"
     }
     with patch('bluebottle.funding_flutterwave.utils.post', return_value=payload):
         response = self.client.post(self.webhook_url, data=payload['data'])
     self.assertEqual(response.status_code, HTTP_200_OK)
     self.assertEqual(donation.payment.status, 'succeeded')
     donation.refresh_from_db()
     self.assertEqual(donation.status, 'succeeded')
     self.assertEqual(donation.amount.amount, 17500)
     self.assertEqual(donation.payout_amount.amount, 17500)
示例#10
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'))
示例#11
0
    def setUp(self):
        super(TelesomPaymentTestCase, self).setUp()
        TelesomPaymentProvider.objects.all().delete()
        TelesomPaymentProviderFactory.create()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()

        self.initiative.states.submit(save=True)
        self.initiative.states.approve(save=True)

        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding,
                                               user=self.user)

        self.payment_url = reverse('telesom-payment-list')

        self.data = {
            'data': {
                'type': 'payments/telesom-payments',
                'attributes': {},
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
示例#12
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')
示例#13
0
    def setUp(self):
        super(TestDonationWallpost, self).setUp()

        self.user = BlueBottleUserFactory.create(about_me="I like to give away all my moneys!")
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.funding = FundingFactory.create(status='open')
        self.wallpost_url = reverse('wallpost_list')
        self.text_wallpost_url = reverse('text_wallpost_list')

        donation = DonationFactory.create(
            user=self.user,
            activity=self.funding,
            fundraiser=None
        )
        donation.states.succeed(save=True)

        self.data = {
            "title": "",
            "text": "What a nice initiative!",
            "parent_id": self.funding.id,
            "parent_type": "funding",
            "donation": donation.id,
            "email_followers": False
        }
示例#14
0
 def test_request_refund(self, mock_retrieve):
     donation = DonationFactory.create(activity=self.funding)
     payment = StripePaymentFactory.create(donation=donation)
     payment.states.succeed(save=True)
     self.assertEqual(payment.status, 'succeeded')
     payment.states.request_refund(save=True)
     self.assertEqual(payment.status, 'refund_requested')
示例#15
0
 def setUp(self, mock_modify):
     super(StripeSourcePaymentStateMachineTests, self).setUp()
     self.donation = DonationFactory.create(activity=self.funding)
     self.payment = StripeSourcePaymentFactory.create(
         charge_token='some_token',
         donation=self.donation
     )
示例#16
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)
示例#17
0
    def setUp(self):
        super(FlutterwavePaymentTestCase, self).setUp()
        self.provider = FlutterwavePaymentProviderFactory.create()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding,
                                               amount=Money(1000, 'NGN'),
                                               user=self.user)

        self.payment_url = reverse('flutterwave-payment-list')

        self.tx_ref = "{}-{}".format(self.provider.prefix, self.donation.id)

        self.data = {
            'data': {
                'type': 'payments/flutterwave-payments',
                'attributes': {
                    'tx-ref': self.tx_ref
                },
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
示例#18
0
    def setUp(self):
        super(PaymentTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory(can_pledge=True)
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding, user=self.user)

        self.donation_url = reverse('funding-donation-list')
        self.payment_url = reverse('pledge-payment-list')

        self.data = {
            'data': {
                'type': 'payments/pledge-payments',
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
        mail.outbox = []
示例#19
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)
示例#20
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)
示例#21
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)
示例#22
0
    def test_results_stats_no_dates(self):
        self.page.start_date = None
        self.page.end_date = None
        self.page.save()

        long_ago = now() - timedelta(days=365 * 2)
        yesterday = now() - timedelta(days=1)
        user = BlueBottleUserFactory(is_co_financer=False)
        funding = FundingFactory(status='open', owner=user)

        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=yesterday,
                               user=user,
                               amount=Money(50, 'EUR'))
        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=long_ago,
                               user=user,
                               amount=Money(50, 'EUR'))

        block = StatsContent.objects.create_for_placeholder(
            self.placeholder, title='Look at us!')
        self.stat1 = StatFactory(type='manual',
                                 title='Poffertjes',
                                 value=3500,
                                 block=block)
        self.stat2 = StatFactory(type='donated_total',
                                 title='Donations',
                                 value=None,
                                 block=block)

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        stats = response.data['blocks'][0]
        self.assertEqual(stats['type'], 'statistics')
        self.assertEqual(stats['title'], 'Look at us!')
        self.assertEqual(stats['stats'][0]['title'], self.stat1.title)
        self.assertEqual(stats['stats'][0]['value'], str(self.stat1.value))
        self.assertEqual(stats['stats'][1]['title'], self.stat2.title)
        self.assertEqual(stats['stats'][1]['value'], {
            "amount": Decimal('100'),
            "currency": "EUR"
        })
示例#23
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())
示例#24
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))
示例#25
0
    def setUp(self):
        super(VitepayPaymentTestCase, self).setUp()
        VitepayPaymentProvider.objects.all().delete()
        VitepayPaymentProviderFactory.create()
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding)
示例#26
0
 def test_request_refund(self):
     donation = DonationFactory.create(activity=self.funding,
                                       amount=Money(500, 'EUR'))
     payment = StripeSourcePaymentFactory.create(donation=donation)
     payment.states.succeed(save=True)
     with patch(
             'bluebottle.funding_stripe.models.StripeSourcePayment.refund'
     ) as refund:
         payment.states.request_refund(save=True)
         refund.assert_called_once()
     self.assertEqual(payment.status, 'refund_requested')
 def setUp(self):
     super(IntentWebhookTestCase, self).setUp()
     StripePaymentProvider.objects.all().delete()
     StripePaymentProviderFactory.create()
     self.initiative = InitiativeFactory.create()
     self.initiative.states.submit()
     self.initiative.states.approve(save=True)
     self.bank_account = ExternalAccountFactory.create()
     self.funding = FundingFactory.create(initiative=self.initiative, bank_account=self.bank_account)
     self.donation = DonationFactory.create(activity=self.funding)
     self.intent = StripePaymentIntentFactory.create(donation=self.donation)
     self.webhook = reverse('stripe-intent-webhook')
示例#28
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')
示例#29
0
    def test_results_supporters(self):
        yesterday = now() - timedelta(days=1)
        co_financer = BlueBottleUserFactory(is_co_financer=True)
        user = BlueBottleUserFactory(is_co_financer=False)
        funding = FundingFactory(status='open', owner=user)

        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=yesterday,
                               user=user,
                               amount=Money(50, 'EUR'))
        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=yesterday,
                               user=co_financer,
                               amount=Money(50, 'EUR'))
        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=yesterday,
                               user=co_financer,
                               amount=Money(50, 'EUR'))

        SupporterTotalContent.objects.create_for_placeholder(self.placeholder)

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        block = response.data['blocks'][0]
        self.assertEqual(block['type'], 'supporter_total')
        self.assertEqual(len(block['co_financers']), 1)
        self.assertEqual(block['co_financers'][0]['total']['amount'], 100)
示例#30
0
 def test_webhook_view(self):
     donation = DonationFactory.create()
     payment = FlutterwavePaymentFactory.create(
         donation=donation,
         tx_ref=donation.id
     )
     payload = {
         "event": "charge.completed",
         "data": {
             "id": 313646423,
             "tx_ref": donation.id,
             "flw_ref": "2Scale/FLW336518359",
             "device_fingerprint": "8a3ceecb7ac72d8b0e7e0e7b5627f966",
             "amount": 50000,
             "currency": "NGN",
             "charged_amount": 50700,
             "app_fee": 700,
             "merchant_fee": 0,
             "processor_response": "Approved by Financial Institution",
             "auth_model": "PIN",
             "ip": "160.152.228.40",
             "narration": "CARD Transaction ",
             "status": "successful",
             "payment_type": "card",
             "created_at": "2020-09-29T14:27:45.000Z",
             "account_id": 179031,
             "customer": {
                 "id": 225543006,
                 "name": "Anonymous customer",
                 "phone_number": "unknown",
                 "email": "*****@*****.**",
                 "created_at": "2020-09-29T14:24:30.000Z"
             },
             "card": {
                 "first_6digits": "123456",
                 "last_4digits": "7890",
                 "issuer": "MASTERCARD ZENITH BANK DEBIT STANDARD",
                 "country": "NG",
                 "type": "MASTERCARD",
                 "expiry": "08/23"
             }
         }
     }
     with patch('bluebottle.funding_flutterwave.utils.post', return_value=payload):
         view = FlutterwaveWebhookView()
         req = type('obj', (object,), {'body': '{{"tx_ref": "{}"}}'.format(donation.id).encode('utf-8')})
         response = view.post(request=req)
     self.assertEqual(response.status_code, HTTP_200_OK)
     payment.refresh_from_db()
     donation.refresh_from_db()
     self.assertEqual(payment.status, 'succeeded')
     self.assertEqual(donation.status, 'succeeded')