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')
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 = []
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 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, } } } } }
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'))
def setUp(self): super(TestPayoutApi, self).setUp() self.client = JSONAPITestClient() self.plain_user = BlueBottleUserFactory.create() self.plain_token = Token.objects.create(user=self.plain_user) self.finance_user = BlueBottleUserFactory.create() self.token = Token.objects.create(user=self.finance_user) financial = Group.objects.get(name='Financial') financial.user_set.add(self.finance_user) yesterday = now() - timedelta(days=1) payout_account = StripePayoutAccountFactory.create(status='verified') self.bank_account = ExternalAccountFactory.create( connect_account=payout_account) self.funding = FundingFactory.create(deadline=yesterday, status='open') self.funding.bank_account = self.bank_account self.funding.save() donations = DonationFactory.create_batch(4, activity=self.funding, amount=Money(35, 'EUR'), status='succeeded') for donation in donations: StripePaymentFactory.create(status='succeeded', donation=donation) self.funding.states.succeed(save=True) self.payout = self.funding.payouts.first() self.payout_url = reverse('payout-details', kwargs={'pk': self.payout.id})
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 }
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, } } } } }
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')
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)
def test_wallposts_with_and_without_donation(self): """ Test that a Wallpost doesn't serializes donation if there isn't one """ TextWallpostFactory.create(content_object=self.funding) self.donation = DonationFactory( amount=Money(35, 'EUR'), user=None, activity=self.funding ) self.donation.states.succeed(save=True) response = self.client.get(self.updates_url, token=self.owner_token) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 2) self.assertEqual( response.data['results'][0]['donation'], { 'name': None, 'fundraiser': None, 'amount': {'currency': 'EUR', 'amount': 35.00}, 'user': None, 'anonymous': False, 'reward': None, 'type': 'contributions/donations', 'id': self.donation.id } ) self.assertEqual(response.data['results'][1]['donation'], None)
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)
def test_wallposts_with_fake_name(self): self.donation = DonationFactory( amount=Money(35, 'EUR'), user=None, name='Tante Ans', activity=self.funding ) self.donation.states.succeed(save=True) response = self.client.get(self.updates_url, token=self.owner_token) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 1) self.assertEqual( response.data['results'][0]['donation'], { 'name': 'Tante Ans', 'fundraiser': None, 'amount': {'currency': 'EUR', 'amount': 35.00}, 'user': None, 'anonymous': False, 'reward': None, 'type': 'contributions/donations', 'id': self.donation.id } )
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)
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())
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')
def test_member_export(self): member = BlueBottleUserFactory.create(username='******') CustomMemberFieldSettings.objects.create(name='Extra Info') field = CustomMemberFieldSettings.objects.create(name='How are you') CustomMemberField.objects.create(member=member, value='Fine', field=field) ParticipantFactory.create(time_spent=5, user=member, status='succeeded') ParticipantFactory.create(time_spent=12, user=member, status='succeeded') ApplicantFactory.create_batch(3, time_spent=10, user=member, status='succeeded') DonationFactory.create_batch(7, amount=Money(5, 'EUR'), user=member, status='succeeded') export_action = self.member_admin.actions[0] response = export_action(self.member_admin, self.request, self.member_admin.get_queryset(self.request)) data = response.content.decode('utf-8').split("\r\n") headers = data[0].split(",") user_data = [] for row in data: if row.startswith('malle-eppie'): user_data = row.split(',') # Test basic info and extra field are in the csv export self.assertEqual(headers, [ 'username', 'email', 'remote_id', 'first_name', 'last name', 'date joined', 'is initiator', 'is supporter', 'is volunteer', 'amount donated', 'time spent', 'subscribed to matching projects', 'Extra Info', 'How are you' ]) self.assertEqual(user_data[0], 'malle-eppie') self.assertEqual(user_data[7], 'True') self.assertEqual(user_data[8], 'True') self.assertEqual(user_data[9], u'35.00 €') self.assertEqual(user_data[10], '47.0') self.assertEqual(user_data[13], 'Fine')
def test_project_systemwallpost_admin(self): funding = FundingFactory.create() donation = DonationFactory(activity=funding) self.wallpost = MediaWallpostFactory.create(content_object=funding, donation=donation) url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, )) response = self.client.get(url) self.assertEqual(response.status_code, 200, response.content) self.assertContains(response, funding.title)
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)
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)
def test_successful_donation_only_once(self): """ Test that a SystemWallpost is created for the project wall when a user does a successful donation """ self.donation = DonationFactory(amount=Money(35, 'EUR'), user=self.user, activity=self.funding) self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1) self.assertEqual(SystemWallpost.objects.first().content_object, self.funding) self.donation.states.fail() self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1)
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" })
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())
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)
def test_generate_payouts(self): Payout.generate(self.funding) self.assertEqual(self.funding.payouts.count(), 3) payout_amounts = [p.total_amount for p in self.funding.payouts.all()] self.assertTrue(Money(1000, 'USD') in payout_amounts) self.assertTrue(Money(1500, 'EUR') in payout_amounts) self.assertTrue(Money(750, 'EUR') in payout_amounts) # More donations for donation in DonationFactory.create_batch(5, amount=Money(150, 'EUR'), activity=self.funding, status='succeeded'): StripePaymentFactory.create(donation=donation) # Recalculate should generate new payouts. One should be higher now. Payout.generate(self.funding) self.assertEqual(self.funding.payouts.count(), 3) payout_amounts = [p.total_amount for p in self.funding.payouts.all()] self.assertTrue(Money(1000, 'USD') in payout_amounts) self.assertTrue(Money(2250, 'EUR') in payout_amounts) self.assertTrue(Money(750, 'EUR') in payout_amounts) with mock.patch('bluebottle.payouts_dorado.adapters.DoradoPayoutAdapter.trigger_payout'): for payout in self.funding.payouts.all(): payout.states.approve() payout.save() # More donations after approved payouts for donation in DonationFactory.create_batch(8, amount=Money(250, 'EUR'), activity=self.funding, status='succeeded'): StripePaymentFactory.create(donation=donation) # Recalculate should generate an additional payout Payout.generate(self.funding) self.assertEqual(self.funding.payouts.count(), 4) payout_amounts = [p.total_amount for p in self.funding.payouts.all()] self.assertTrue(Money(1000, 'USD') in payout_amounts) self.assertTrue(Money(2000, 'EUR') in payout_amounts) self.assertTrue(Money(2250, 'EUR') in payout_amounts) self.assertTrue(Money(750, 'EUR') in payout_amounts)
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)
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))
class TestDonationSignalsTestCase(BluebottleTestCase): def setUp(self): super(TestDonationSignalsTestCase, self).setUp() self.user = BlueBottleUserFactory.create() self.funding = FundingFactory.create(target=Money(5000, 'EUR'), status='open') def test_successful_donation(self): """ Test that a SystemWallpost is created for the project wall when a user does a successful donation """ self.donation = DonationFactory(amount=Money(35, 'EUR'), user=self.user, activity=self.funding) self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1) self.assertEqual(SystemWallpost.objects.all()[0].content_object, self.funding) self.assertEqual(len(mail.outbox), 2) def test_successful_donation_only_once(self): """ Test that a SystemWallpost is created for the project wall when a user does a successful donation """ self.donation = DonationFactory(amount=Money(35, 'EUR'), user=self.user, activity=self.funding) self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1) self.assertEqual(SystemWallpost.objects.first().content_object, self.funding) self.donation.states.fail() self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1) def test_successfull_anonymous_donation(self): """ Test that a SystemWallpost is created without an author when a donation is anonymous """ self.assertEqual(SystemWallpost.objects.count(), 0) self.donation = DonationFactory(amount=Money(35, 'EUR'), user=None, activity=self.funding) self.donation.states.succeed() self.donation.save() self.assertEqual(SystemWallpost.objects.count(), 1) self.assertEqual(SystemWallpost.objects.all()[0].author, None)
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')