Esempio n. 1
0
    def setUp(self):
        self.order = OrderFactory.create(total=Money(200, 'EUR'))
        self.order_payment = OrderPaymentFactory.create(
            payment_method='docdata', order=self.order)

        PaymentFactory.create(order_payment=self.order_payment)
        self.adapter = BasePaymentAdapter(self.order_payment)
Esempio n. 2
0
    def setUp(self):
        self.order = OrderFactory.create(total=Money(200, 'EUR'))
        self.order_payment = OrderPaymentFactory.create(
            payment_method='docdata',
            order=self.order
        )

        PaymentFactory.create(order_payment=self.order_payment)
        self.adapter = BasePaymentAdapter(self.order_payment)
Esempio n. 3
0
    def test_locked_order_timeout(self):
        with mock.patch.object(timeout_locked_order,
                               'apply_async') as apply_async:
            with mock.patch.object(timeout_new_order, 'apply_async'):
                order = OrderFactory.create()
                PaymentFactory.create(order_payment=OrderPaymentFactory.create(
                    order=order))
                self.assertEqual(order.status, StatusDefinition.LOCKED)

                args, kwargs = apply_async.call_args
                self.assertEqual(args[0], [order, connection.tenant])

                self.assertTrue(
                    kwargs['eta'] - timezone.now() < timedelta(hours=3))
                self.assertTrue(
                    kwargs['eta'] -
                    timezone.now() > timedelta(hours=2, minutes=59))
Esempio n. 4
0
    def test_payment_status_changes(self):
        self.payment = PaymentFactory.create(order_payment=self.order_payment)

        self.assertEqual(self.order_payment.status, StatusDefinition.STARTED,
                         'Starting a Payment should change Order Payment to started')

        self.payment.status = StatusDefinition.AUTHORIZED
        self.payment.save()
        self.assertEqual(self.order_payment.status, StatusDefinition.AUTHORIZED,
                         'Authorizing a Payment should change Order Payment to authorized')
        self.assertEqual(self.order.status, StatusDefinition.PENDING,
                         'Authorizing a Payment should change Order Payment to pending')
Esempio n. 5
0
    def test_payment_status_changes(self):
        self.payment = PaymentFactory.create(order_payment=self.order_payment)

        self.assertEqual(self.order_payment.status, StatusDefinition.STARTED,
                         'Starting a Payment should change Order Payment to started')

        self.payment.status = StatusDefinition.AUTHORIZED
        self.payment.save()
        self.assertEqual(self.order_payment.status, StatusDefinition.AUTHORIZED,
                         'Authorizing a Payment should change Order Payment to authorized')
        self.assertEqual(self.order.status, StatusDefinition.PENDING,
                         'Authorizing a Payment should change Order Payment to pending')
Esempio n. 6
0
    def test_bad_payment_status_changes(self):
        self.payment = PaymentFactory.create(order_payment=self.order_payment)
        self.payment.status = StatusDefinition.AUTHORIZED
        self.payment.save()

        self.assertEqual(self.order_payment.status, StatusDefinition.AUTHORIZED,
            'Authorizing a Payment should change Order Payment to authorized')

        self.payment.status = StatusDefinition.STARTED

        # Starting an authorized Payment should not change Order Payment status
        with self.assertRaises(TransitionNotAllowed):
            self.payment.save()

        self.assertEqual(self.payment.order_payment.status, StatusDefinition.AUTHORIZED,
            'Starting an authorized Payment should not change Order Payment status')

        self.assertEqual(self.payment.order_payment.order.status, StatusDefinition.PENDING,
            'Starting an authorized Payment should not change Order status')
Esempio n. 7
0
    def test_bad_payment_status_changes(self):
        self.payment = PaymentFactory.create(order_payment=self.order_payment)
        self.payment.status = StatusDefinition.AUTHORIZED
        self.payment.save()

        self.assertEqual(self.order_payment.status, StatusDefinition.AUTHORIZED,
                         'Authorizing a Payment should change Order Payment to authorized')

        self.payment.status = StatusDefinition.STARTED

        # Starting an authorized Payment should not change Order Payment status
        with self.assertRaises(TransitionNotAllowed):
            self.payment.save()

        self.assertEqual(self.payment.order_payment.status,
                         StatusDefinition.AUTHORIZED,
                         'Starting an authorized Payment should not change Order Payment status')

        self.assertEqual(self.payment.order_payment.order.status,
                         StatusDefinition.PENDING,
                         'Starting an authorized Payment should not change Order status')
    def setUp(self):
        super(AccountingStatisticsTests, self).setUp()

        self.today = timezone.now()
        last_year = self.today.year - 1
        self.last_year = datetime.datetime(last_year, 1, 1, tzinfo=pytz.timezone('Europe/Amsterdam'))
        self.middle_date = datetime.datetime(last_year, 6, 1, tzinfo=pytz.timezone('Europe/Amsterdam'))

        # other categories from the fixtures are [u'Checking to savings', u'Savings to checking',
        # u'Bank costs', u'Donations to be transferred', u'Interest', u'Settle Bank costs', u'Total']
        self.CAMPAIGN_PAYOUT = BankTransactionCategory.objects.get(name='Campaign Payout')
        self.DOCDATA_PAYOUT = BankTransactionCategory.objects.get(name='Docdata payout')
        self.DOCDATA_PAYMENT = BankTransactionCategory.objects.get(name='Docdata payment')

        self.status = BankTransaction.IntegrityStatus # .Valid .UnknownTransaction .AmountMismatch
        self.creditdebit = BankTransaction.CreditDebit # .credit  .debit

        # ##### One organization has 2 projects ##### #
        self.organization = OrganizationFactory.create(name='test_org', slug='test_org')
        self.project1_owner = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.project2_owner = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')

        # deadline defaults to timezone.now() + timedelta(days=100)
        #  allow_overfunding defaults to True
        self.project1 =  ProjectFactory(owner=self.project1_owner, organization=self.organization,
                                        title='Project 1', amount_needed=1111, amount_asked=1111)
        self.project2 = ProjectFactory(owner=self.project2_owner, organization=self.organization,
                                       title='Project 2', amount_needed=2222, amount_asked=2222)

        # ##### Person 1 makes 1 order that contains 2 donations for both projects ##### #
        self.person1 = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.order1 = OrderFactory.create(user=self.person1)
        self.donation1_person1 = DonationFactory(order=self.order1, project=self.project1, amount=111)
        self.donation2_person1 = DonationFactory(order=self.order1, project=self.project2, amount=222)

        # ##### Person 2 makes 1 donations for project 1 ##### #
        self.person2 = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******')
        self.order2 = OrderFactory.create(user=self.person2, status='success')
        self.donation1_person2 = DonationFactory(order=self.order2, project=self.project1, amount=1000)

        # ##### ORDER PAYMENT AND PAYMENT ##### #
        self.assertEqual(self.order1.status, 'created')
        self.order_payment = OrderPaymentFactory.create(order=self.order1)
        self.assertEqual(self.order1.status, 'locked')
        self.assertEqual(Payment.objects.all().count(), 0)
        self.order_payment.started()
        self.order_payment.save()
        self.payment = PaymentFactory.create(order_payment=self.order_payment)
        self.assertEqual(Payment.objects.all().count(), 1)
        self.assertEqual(self.order1.status, StatusDefinition.LOCKED)
        self.order_payment.authorized()
        self.order_payment.save()
        self.assertEqual(self.order1.status, StatusDefinition.PENDING)
        self.order_payment.settled()
        self.order_payment.save()
        self.assertEqual(self.order1.status, StatusDefinition.SUCCESS)
        # #####

        # ##### make Docdata Payout and Payment ##### #
        self.remoteDDPayout = RemoteDocdataPayoutFactory.create(collected_amount=Decimal('123.45'),
                                                                payout_amount=Decimal('20'))
        self.remoteDDPayment = RemoteDocdataPaymentFactory.create(remote_payout=self.remoteDDPayout,
                                                                  local_payment=self.payment,
                                                                  amount_collected=Decimal('123.45'),
                                                                  docdata_fee=Decimal('0.33'))
        self.assertEqual(self.remoteDDPayout.collected_amount, Decimal('123.45'))
        self.assertEqual(self.remoteDDPayout.payout_amount, Decimal('20'))
        self.assertEqual(self.remoteDDPayment.amount_collected, Decimal('123.45'))
        self.assertEqual(self.remoteDDPayment.docdata_fee, Decimal('0.33'))
        self.assertEqual(self.remoteDDPayment.status, 'valid')

        # completed should be between start and end to appear in the statistics
        self.project1_payout = ProjectPayoutFactory.create(
            completed=self.middle_date, status = StatusDefinition.SETTLED, project=self.project1,
            amount_raised=333, organization_fee=0, amount_payable=333)
        self.project2_payout = ProjectPayoutFactory.create(
            completed=self.middle_date, status = StatusDefinition.SETTLED, project=self.project2,
            amount_raised=1000, organization_fee=50, amount_payable=950)

        BankTransactionFactory.create(amount=Decimal('1000'),
                                      category=self.CAMPAIGN_PAYOUT,
                                      credit_debit=self.creditdebit.credit,
                                      status=self.status.Valid,
                                      payout=self.project2_payout,
                                      remote_payout=None,
                                      remote_payment=None,
                                      )