def test_sort_activity_date(self): first = InitiativeFactory.create(status='approved') FundingFactory.create(initiative=first, status='open', deadline=now() + datetime.timedelta(days=8)) FundingFactory.create(initiative=first, status='submitted', deadline=now() + datetime.timedelta(days=7)) second = InitiativeFactory.create(status='approved') EventFactory.create(initiative=second, status='open', start=now() + datetime.timedelta(days=7)) third = InitiativeFactory.create(status='approved') EventFactory.create(initiative=third, status='open', start=now() + datetime.timedelta(days=7)) AssignmentFactory.create(initiative=third, status='open', date=now() + datetime.timedelta(days=9)) response = self.client.get(self.url + '?sort=activity_date', HTTP_AUTHORIZATION="JWT {0}".format( self.owner.get_jwt_token())) data = json.loads(response.content) self.assertEqual(data['meta']['pagination']['count'], 3) self.assertEqual(data['data'][0]['id'], str(third.pk)) self.assertEqual(data['data'][1]['id'], str(first.pk)) self.assertEqual(data['data'][2]['id'], str(second.pk))
def test_export(self): from_date = now() - timedelta(weeks=2) to_date = now() + timedelta(weeks=1) data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'} tenant = connection.tenant initiatives = InitiativeFactory.create_batch(4) for initiative in initiatives: EventFactory.create_batch(3, initiative=initiative) AssignmentFactory.create_batch(2, initiative=initiative) FundingFactory.create_batch(1, initiative=initiative) result = plain_export(Exporter, tenant=tenant, **data) book = xlrd.open_workbook(result) self.assertEqual(book.sheet_by_name('Users').ncols, 11) self.assertEqual(book.sheet_by_name('Users').nrows, 41) self.assertEqual(book.sheet_by_name('Initiatives').nrows, 5) self.assertEqual(book.sheet_by_name('Funding activities').nrows, 5) self.assertEqual(book.sheet_by_name('Events').nrows, 13) self.assertEqual( book.sheet_by_name('Events').cell(0, 13).value, 'Start') self.assertEqual( book.sheet_by_name('Events').cell(0, 14).value, 'Time needed') self.assertEqual(book.sheet_by_name('Tasks').nrows, 9) self.assertEqual( book.sheet_by_name('Tasks').cell(0, 16).value, 'Preparation time') self.assertEqual( book.sheet_by_name('Tasks').cell(0, 17).value, 'Start time') self.assertEqual( book.sheet_by_name('Tasks').cell(0, 19).value, 'End date')
def test_images(self): EventFactory.create(owner=self.owner, review_status='approved', image=ImageFactory.create()) AssignmentFactory.create(review_status='approved', image=ImageFactory.create()) FundingFactory.create(review_status='approved', image=ImageFactory.create()) response = self.client.get(self.url, user=self.owner) for activity in response.json()['data']: self.assertEqual( activity['relationships']['image']['data']['type'], 'images')
def test_approve_deadline(self): funding = FundingFactory.create( owner=self.initiative.activity_manager, initiative=self.initiative, target=Money(500, 'EUR'), duration=30, deadline=None, bank_account=BankAccountFactory.create(status='verified')) self.assertIsNone(funding.started) BudgetLineFactory.create(activity=funding) funding.bank_account.status = 'verified' funding.states.submit() funding.states.approve(save=True) self.assertIsInstance(funding.started, datetime) deadline = now() + timedelta(days=30) self.assertAlmostEqual(funding.deadline, get_current_timezone().localize( datetime(deadline.year, deadline.month, deadline.day, hour=23, minute=59, second=59)), delta=timedelta(seconds=1))
def test_get_stats(self): event = EventFactory.create(initiative=self.initiative, status='succeeded') ParticipantFactory.create_batch(3, activity=event, status='succeeded', time_spent=3) assignment = AssignmentFactory.create(initiative=self.initiative, status='succeeded', duration=3) ApplicantFactory.create_batch(3, activity=assignment, status='succeeded', time_spent=3) funding = FundingFactory.create(initiative=self.initiative, status='succeeded') DonationFactory.create_batch(3, activity=funding, status='succeeded', amount=Money(10, 'EUR')) DonationFactory.create_batch(3, activity=funding, status='succeeded', amount=Money(10, 'USD')) response = self.client.get(self.url, user=self.owner) self.assertEqual(response.status_code, status.HTTP_200_OK) stats = response.json()['data']['meta']['stats'] self.assertEqual(stats['hours'], 18) self.assertEqual(stats['activities'], 3) self.assertEqual(stats['contributions'], 12) self.assertEqual(stats['amount'], 75.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 = []
def setUp(self): super(PledgePayoutAccountDetailTestCase, self).setUp() self.client = JSONAPITestClient() self.user = BlueBottleUserFactory() self.initiative = InitiativeFactory.create() PledgePaymentProviderFactory.create() self.initiative.states.submit() self.initiative.states.approve(save=True) self.funding = FundingFactory.create(initiative=self.initiative) self.payout_account = PlainPayoutAccountFactory.create( status='verified', owner=self.user ) self.bank_account = PledgeBankAccountFactory.create( connect_account=self.payout_account ) self.bank_account_url = reverse( 'pledge-external-account-detail', args=(self.bank_account.pk, ) ) self.data = { 'data': { 'type': 'payout-accounts/pledge-external-accounts', 'id': self.bank_account.pk, 'attributes': { 'account-number': '11111111', }, } }
def setUp(self): super(FlutterwavePayoutAccountTestCase, self).setUp() self.client = JSONAPITestClient() self.user = BlueBottleUserFactory() self.initiative = InitiativeFactory.create() FlutterwavePaymentProviderFactory.create() self.initiative.states.submit() self.initiative.states.approve(save=True) self.funding = FundingFactory.create(initiative=self.initiative) self.payout_account = PlainPayoutAccountFactory.create( status='verified', owner=self.user) self.payout_account_url = reverse('payout-account-list') self.bank_account_url = reverse('flutterwave-external-account-list') self.data = { 'data': { 'type': 'payout-accounts/flutterwave-external-accounts', 'attributes': { 'bank-code': '044', 'account-number': '123456789', 'account-holder-name': 'Jolof Rice' }, 'relationships': { 'connect-account': { 'data': { 'id': self.payout_account.id, 'type': 'payout-accounts/plains' } } } } }
def setUp(self): super(StripeSourcePaymentAdminTestCase, self).setUp() account = generate_stripe_payout_account() bank_account = ExternalAccountFactory.create(connect_account=account) funding = FundingFactory.create(bank_account=bank_account) self.client.force_login(self.superuser) self.donation = DonationFactory( amount=Money(100, 'EUR'), activity=funding ) with patch('stripe.Source.modify'): self.payment = StripeSourcePaymentFactory.create( source_token='source-token', charge_token='charge-token', donation=self.donation ) self.admin_url = reverse('admin:funding_stripe_stripesourcepayment_change', args=(self.payment.id,)) self.check_status_url = reverse('admin:funding_payment_check', args=(self.payment.id,)) self.source = stripe.Source('source-token') self.source.update({ 'amount': 10000, 'currency': 'EUR', 'status': 'charged' }) self.charge = stripe.Charge('charge-token') self.charge.update({ 'status': 'succeeded', 'refunded': None, 'dispute': None })
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_survive_and_fix_duplicate_follows(self): user = BlueBottleUserFactory.create() funding = FundingFactory.create() Follow.objects.create(instance=funding, user=user) Follow.objects.create(instance=funding, user=user) follow(user, funding) self.assertEqual(Follow.objects.count(), 1)
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)
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 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 test_initiative_with_funding(self): initiative = InitiativeFactory.create() funding = FundingFactory.create(initiative=initiative) data = { 'data': { 'type': 'initiative-redirects', 'attributes': { 'route': 'project', 'params': { 'project_id': initiative.slug } }, } } response = self.client.post(self.url, json.dumps(data)) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.json()['data']['attributes']['target-route'], 'initiatives.activities.details.funding') self.assertEqual( response.json()['data']['attributes']['target-params'], [funding.pk, funding.slug])
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)
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_submit_invalid(self): funding = FundingFactory.create(initiative=self.initiative, target=Money(1000, 'EUR')) funding.bank_account = self.bank_account funding.save() with self.assertRaisesMessage(TransitionNotPossible, 'Conditions not met for transition'): funding.states.submit()
def setUp(self): super(FundingWallpostTest, self).setUp() self.owner = BlueBottleUserFactory.create() self.owner_token = "JWT {0}".format(self.owner.get_jwt_token()) self.initiative = InitiativeFactory.create(owner=self.owner) self.funding = FundingFactory.create(target=Money(5000, 'EUR'), status='open', initiative=self.initiative) self.updates_url = "{}?parent_type=funding&parent_id={}".format(reverse('wallpost_list'), self.funding.id)
def test_deadline_in_past(self): funding = FundingFactory.create( target=Money(100, 'EUR'), deadline=now() - timedelta(days=10), status='in_review' ) errors = list(funding.errors) self.assertEqual(len(errors), 3) self.assertEqual(errors[1].message, 'Make sure deadline is in the future')
def setUp(self): super(FlutterwavePaymentAdminTestCase, self).setUp() bank_account = FlutterwaveBankAccountFactory.create() funding = FundingFactory.create(bank_account=bank_account) self.client.force_login(self.superuser) self.donation = DonationFactory( amount=Money(10000, 'NGN'), activity=funding )
def test_deadline_in_past_with_duration(self): funding = FundingFactory.create( target=Money(100, 'EUR'), deadline=now() - timedelta(days=10), duration=10, status='in_review' ) errors = list(funding.errors) self.assertEqual(len(errors), 2)
def test_reward_currency_change(self): funding = FundingFactory.create(target=Money(100, 'EUR')) RewardFactory.create_batch(5, activity=funding, amount=Money(20, 'EUR')) funding.target = Money(50, 'USD') funding.save() for reward in funding.rewards.all(): self.assertEqual(str(reward.amount.currency), 'USD')
def test_budget_currency_change(self): funding = FundingFactory.create(target=Money(100, 'EUR')) BudgetLineFactory.create_batch(5, activity=funding, amount=Money(20, 'EUR')) funding.target = Money(50, 'USD') funding.save() for line in funding.budget_lines.all(): self.assertEqual(str(line.amount.currency), 'USD')
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 setUp(self): super(UsedCountryListTestCase, self).setUp() belgium = Country.objects.get(translations__name="Belgium") location_be = GeolocationFactory.create(country=belgium) bulgaria = Country.objects.get(translations__name="Bulgaria") location_bg = GeolocationFactory.create(country=bulgaria) germany = Country.objects.get(translations__name="Germany") location_de = GeolocationFactory.create(country=germany) turkey = Country.objects.get(translations__name="Turkey") location_tr = LocationFactory.create(country=turkey) LocationFactory.create(country=Country.objects.get(translations__name='France')) EventFactory.create( status='open', location=location_be ) EventFactory.create( status='full', location=location_bg ) AssignmentFactory.create( status='draft', location=location_de ) EventFactory.create( status='submitted', location=location_de ) initiative = InitiativeFactory.create( status='approved', location=location_tr ) FundingFactory.create( initiative=initiative, status='open' )
def test_verify_submit_activities(self): initiative = InitiativeFactory.create() initiative.states.submit() initiative.states.approve(save=True) complete_funding = FundingFactory.create( bank_account=self.bank_account, initiative=initiative, target=Money(1000, 'EUR')) BudgetLineFactory.create(activity=complete_funding) incomplete_funding = FundingFactory.create( bank_account=self.bank_account, initiative=initiative, target=Money(1000, 'EUR')) self.account.states.verify(save=True) self.assertEqual(self.account.status, 'verified') incomplete_funding.refresh_from_db() self.assertEqual(incomplete_funding.status, 'draft') complete_funding.refresh_from_db() self.assertEqual(complete_funding.status, 'submitted')
def test_budget_line_required(self): funding = FundingFactory.create(target=Money(100, 'EUR')) errors = list(funding.errors) self.assertEqual(len(errors), 2) self.assertEqual(errors[1].message, 'Please specify a budget') BudgetLineFactory.create_batch(5, activity=funding, amount=Money(20, 'EUR')) errors = list(funding.errors) self.assertEqual(len(errors), 1)
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')