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))
Пример #2
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)
Пример #3
0
 def test_submit_incomplete(self):
     funding = FundingFactory.create(initiative=self.initiative,
                                     target=Money(1000, 'EUR'))
     BudgetLineFactory.create(activity=self.funding)
     funding.bank_account = self.bank_account
     funding.save()
     with self.assertRaisesMessage(TransitionNotPossible,
                                   'Conditions not met for transition'):
         funding.states.submit()
Пример #4
0
    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')
Пример #5
0
    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)
Пример #6
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,
                                          target=Money(1000, 'EUR'))
     BudgetLineFactory.create(activity=self.funding)
     payout_account = PlainPayoutAccountFactory.create()
     bank_account = BankAccountFactory.create(
         connect_account=payout_account, status='verified')
     self.funding.bank_account = bank_account
     self.funding.states.submit(save=True)
Пример #7
0
 def setUp(self):
     super(FundingTestCase, self).setUp()
     self.initiative = InitiativeFactory.create()
     self.initiative.states.submit()
     self.initiative.states.approve(save=True)
     bank_account = BankAccountFactory.create(status='verified')
     self.funding = FundingFactory.create(owner=self.superuser,
                                          initiative=self.initiative,
                                          bank_account=bank_account)
     BudgetLineFactory.create(activity=self.funding)
     self.admin_url = reverse('admin:funding_funding_change',
                              args=(self.funding.id, ))
Пример #8
0
 def setUp(self):
     super(FundingStatisticsTest, self).setUp()
     payout_account = PlainPayoutAccountFactory.create()
     bank_account = BankAccountFactory.create(
         connect_account=payout_account, status='verified')
     self.funding = FundingFactory.create(owner=self.some_user,
                                          bank_account=bank_account,
                                          initiative=self.initiative,
                                          target=Money(100, 'EUR'))
     BudgetLineFactory.create(activity=self.funding)
     self.funding.states.submit()
     self.funding.states.approve(save=True)
    def test_review(self):
        funding = FundingFactory.create(initiative=self.initiative)
        self.assertEqual(funding.status, funding.states.draft.value)

        BudgetLineFactory.create(activity=funding)
        payout_account = PlainPayoutAccountFactory.create()
        bank_account = BankAccountFactory.create(
            connect_account=payout_account, status='verified')
        funding.bank_account = bank_account

        funding.states.submit(save=True)
        self.assertEqual(funding.status, funding.states.submitted.value)
        organizer = funding.contributions.instance_of(Organizer).get()
        self.assertEqual(organizer.status, organizer.states.new.value)
        self.assertEqual(organizer.user, funding.owner)
Пример #10
0
    def test_submit_initiative_not_submitted(self):
        funding = FundingFactory.create(target=Money(1000, 'EUR'),
                                        initiative=InitiativeFactory.create())
        BudgetLineFactory.create(activity=funding)
        funding.bank_account = self.bank_account
        funding.save()

        with self.assertRaisesMessage(TransitionNotPossible,
                                      'Conditions not met for transition'):
            funding.states.submit()

        funding.initiative.states.submit(save=True)
        funding.refresh_from_db()

        self.assertEqual(funding.status, 'submitted')
 def setUp(self):
     self.initiative = InitiativeFactory.create()
     self.initiative.states.submit()
     self.initiative.states.approve(save=True)
     self.funding = FundingFactory.create(initiative=self.initiative,
                                          deadline=now() +
                                          timedelta(days=10),
                                          target=Money(1000, 'EUR'))
     BudgetLineFactory.create(activity=self.funding)
     payout_account = StripePayoutAccountFactory.create(status='verified')
     self.bank_account = ExternalAccountFactory.create(
         connect_account=payout_account, status='verified')
     self.funding.bank_account = self.bank_account
     self.funding.save()
     self.funding.states.submit()
     self.funding.states.approve(save=True)
Пример #12
0
    def test_approve_set_deadline(self):
        self.funding = FundingFactory.create(initiative=self.initiative,
                                             target=Money(1000, 'EUR'),
                                             deadline=None,
                                             duration=7)
        BudgetLineFactory.create(activity=self.funding)
        payout_account = PlainPayoutAccountFactory.create()
        bank_account = BankAccountFactory.create(
            connect_account=payout_account, status='verified')
        self.funding.bank_account = bank_account
        self.funding.save()

        self.funding.states.submit()
        self.funding.states.approve(save=True)
        next_week = now() + timedelta(days=7)
        self.assertEqual(self.funding.deadline.date(), next_week.date())
Пример #13
0
    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_new_funding_for_running_initiative(self):
        new_funding = FundingFactory.create(
            initiative=self.initiative,
            target=Money(500, 'EUR'),
            deadline=now() + timedelta(weeks=2),
            bank_account=BankAccountFactory.create(status='verified'))
        BudgetLineFactory.create(activity=new_funding)
        new_funding.bank_account.reviewed = True

        new_funding.states.reject(save=True)
        organizer = new_funding.contributions.first()
        self.assertEqual(organizer.status, u'failed')

        new_funding.states.restore(save=True)
        organizer.refresh_from_db()
        self.assertEqual(organizer.status, u'new')

        new_funding.states.submit()
        new_funding.states.approve(save=True)
        organizer.refresh_from_db()
        self.assertEqual(organizer.status, u'succeeded')
Пример #15
0
    def test_submit_with_activities(self):
        event = EventFactory.create(initiative=self.initiative)
        funding = FundingFactory.create(initiative=self.initiative, bank_account=self.bank_account)
        BudgetLineFactory.create(activity=funding)

        incomplete_event = EventFactory.create(initiative=self.initiative, title='')
        self.initiative.states.submit(save=True)

        event.refresh_from_db()
        self.assertEqual(
            event.status, ReviewStateMachine.submitted.value
        )

        funding.refresh_from_db()
        self.assertEqual(
            funding.status, ReviewStateMachine.submitted.value
        )

        incomplete_event.refresh_from_db()
        self.assertEqual(
            incomplete_event.status, ReviewStateMachine.draft.value
        )
Пример #16
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)

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

        self.payment = StripePaymentFactory.create(donation=donation)
        super(StripePaymentTransitionsTestCase, self).setUp()
Пример #17
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 setUp(self):
        super(FundingTestCase, self).setUp()
        user = BlueBottleUserFactory.create(first_name='Jean Baptiste')
        self.initiative = InitiativeFactory.create(activity_manager=user)
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        payout_account = StripePayoutAccountFactory.create(status='verified')
        bank_account = ExternalAccountFactory.create(
            connect_account=payout_account, status='verified')
        self.funding = FundingFactory.create(owner=user,
                                             initiative=self.initiative,
                                             target=Money(500, 'EUR'),
                                             deadline=now() +
                                             timedelta(weeks=2),
                                             bank_account=bank_account)
        BudgetLineFactory.create(activity=self.funding)
        self.funding.bank_account.reviewed = True

        self.funding.states.submit()
        self.funding.states.approve(save=True)
        BudgetLineFactory.create_batch(4,
                                       activity=self.funding,
                                       amount=Money(125, 'EUR'))
        mail.outbox = []
Пример #19
0
    def setUp(self):
        super(StripeConnectWebhookTestCase, self).setUp()
        self.user = BlueBottleUserFactory.create()

        self.connect_account = stripe.Account('some-account-id')

        external_account = stripe.BankAccount('some-bank-token')
        external_account.update(munch.munchify({
            'object': 'bank_account',
            'account_holder_name': 'Jane Austen',
            'account_holder_type': 'individual',
            'bank_name': 'STRIPE TEST BANK',
            'country': 'US',
            'currency': 'usd',
            'fingerprint': '1JWtPxqbdX5Gamtc',
            'last4': '6789',
            'metadata': {
                'order_id': '6735'
            },
            'routing_number': '110000000',
            'status': 'new',
            'account': 'acct_1032D82eZvKYlo2C'
        }))

        external_accounts = stripe.ListObject()
        external_accounts.data = [external_account]
        external_accounts.update({
            'total_count': 1,
        })

        self.connect_account.update(munch.munchify({
            'country': 'NL',
            'requirements': {
                'disabled': False,
                'eventually_due': [],
                'currently_due': [],
                'past_due': [],
                'pending_verification': [],
                'disabled_reason': ''
            },
            'individual': {
                'verification': {
                    'status': 'verified',
                    'document': {
                        "back": None,
                        "details": None,
                        "details_code": None,
                        "front": "file_12345"
                    }
                },
                'requirements': {
                    'eventually_due': [],
                    'currently_due': [],
                    'past_due': [],
                    'pending_verification': [],
                },
            },
            'external_accounts': external_accounts
        }))

        with mock.patch('stripe.Account.create', return_value=self.connect_account):
            self.payout_account = StripePayoutAccountFactory.create(owner=self.user)

        external_account = ExternalAccountFactory.create(connect_account=self.payout_account)

        self.funding = FundingFactory.create(bank_account=external_account)
        self.funding.initiative.states.submit(save=True)
        BudgetLineFactory.create(activity=self.funding)
        self.webhook = reverse('stripe-connect-webhook')