Пример #1
0
    def test01(self):
        """
        If user didn't set funding source, do not process prepare.
        """
        e = Emulator()
        e.init()

        e.clear_funding_source()
        Emulator.run_transfer_prepare()
        assert TransferPrepare.objects.count() == 0
Пример #2
0
 def test02(self):
     """
     Test success transfer.
     Collected roundup should be more than
     settings.TRANSFER_TO_DONKIES_MIN_AMOUNT
     """
     e = Emulator()
     e.init()
     e.make_transfer_prepare_condition()
     Emulator.run_transfer_prepare()
     assert len(e.debit_accounts) == TransferPrepare.objects.count()
Пример #3
0
    def test_02(self):
        """
        Update Stripe transfer.
        """
        e = Emulator()
        e.init()
        Emulator.run_transfer_prepare()
        qs = TransferPrepare.objects.all()
        assert qs.count() > 1

        # Required for real request to Stripe API in
        # TransferStripe.objects.process_transfers()
        account = e.user.get_funding_source_account()
        access_token, account_id = self.get_access_token()
        account.plaid_id = account_id
        account.save()

        item = account.item
        item.access_token = access_token
        item.save()

        dt = self.get_last_date_of_the_month()
        with freeze_time(dt.strftime('%Y-%m-%d %H:%M:%S')):
            # Emulate last day of the month
            TransferStripe.objects.process_transfers()
            assert TransferStripe.objects.count() == 1

        # In sandbox all transfers automatically become SUCCEEDED
        # after creation. (On production few days).
        TransferStripe.objects.update_transfers()
        ts = TransferStripe.objects.first()
        assert ts.status == TransferStripe.SUCCEEDED
        assert ts.paid is True
Пример #4
0
    def test_get_transfer_debt(self, client):
        e = Emulator()
        e.init()
        e.create_stripe_transfers(90)
        e.run_process_users()
        client = self.get_auth_client(e.user)

        count = TransferDebt.objects.count()
        assert count > 0

        url = '/v1/transfers_debt'
        response = client.get(url)
        assert response.status_code == 200
        rd = response.json()
        assert len(rd) == count
Пример #5
0
    def test04(self):
        """
        Test that amounts are equal.
        """
        e = Emulator()
        e.init()

        total_should_be = e.get_total_roundup(e.transactions)
        sum = e.user.get_not_processed_roundup_sum()
        assert sum == total_should_be

        e.make_transfer_prepare_condition()
        e.run_transfer_prepare()

        sum = TransferPrepare.objects.aggregate(Sum('roundup'))['roundup__sum']
        assert total_should_be == sum

        qs = Transaction.objects.active().filter(is_processed=False)
        assert qs.count() == 0
Пример #6
0
    def test_get_transfer_prepare(self, client):
        e = Emulator()
        e.init()
        e.run_transfer_prepare()
        client = self.get_auth_client(e.user)

        url = '/v1/transfers_prepare'
        response = client.get(url)
        assert response.status_code == 200
Пример #7
0
    def test_01(self):
        """
        Test Stat model manager's method.
        """
        e = Emulator()
        e.init()
        e.create_stripe_transfers(90)

        TransferUser.objects.process_users()
        assert TransferUser.objects.count() > 0
        assert TransferDebt.objects.count() > 0

        print(Stat.objects.get_json(e.user.id))
Пример #8
0
    def test03(self):
        """
        Test case where collected roundup is less than
        settings.TRANSFER_TO_DONKIES_MIN_AMOUNT
        Should not send transfers to Donkies.
        """
        e = Emulator()
        e.init()
        sum = e.user.get_not_processed_roundup_sum()

        settings.TRANSFER_TO_DONKIES_MIN_AMOUNT = sum + 1
        Emulator.run_transfer_prepare()
        assert TransferPrepare.objects.count() == 0
Пример #9
0
    def test_close_account01(self):
        """
        Test user's method.
        User closes Donkies account.
        All required steps listed in "user.close_account" method.
        """
        e = Emulator()
        e.init()

        # Emulate transfers to Stripe
        e.create_stripe_transfers(90)
        count = TransferStripe.objects.filter(paid=True).count()
        assert count > 0

        count = TransferStripe.objects.filter(
            is_processed_to_user=True).count()
        assert count == 0

        count = TransferUser.objects.all().count()
        assert count == 0

        # Close user's account
        e.user.close_account()

        # All user's items, accounts and transactions should
        # be not active
        assert Item.objects.filter(is_active=True).count() == 0
        assert Account.objects.filter(is_active=True).count() == 0
        assert Transaction.objects.filter(is_active=True).count() == 0

        # All transfers from TransferStripe should be processed.
        count = TransferStripe.objects.filter(
            is_processed_to_user=False).count()
        assert count == 0

        count = TransferStripe.objects.filter(
            is_processed_to_user=True).count()
        assert count > 0

        # TransferUser model should be filled
        count = TransferUser.objects.all().count()
        assert count > 0

        # TransferDebt model should be filled
        count = TransferDebt.objects.all().count()
        assert count > 0

        e.user.refresh_from_db()
        e.user.is_closed_account is True
Пример #10
0
    def test_close_account02(self):
        """
        Test API endpoint.
        User closes Donkies account.
        """
        e = Emulator()
        e.init()
        e.create_stripe_transfers(90)
        client = self.get_auth_client(e.user)

        url = '/v1/user_close_account'
        dic = {}
        data = json.dumps(dic)
        response = client.post(url, data, content_type='application/json')
        assert response.status_code == 204

        e.user.refresh_from_db()
        assert e.user.is_closed_account is True
Пример #11
0
    def test_01(self):
        """
        Create Stripe transfer.
        After prepare transfer from TransferPrepare,
        TransferStripe should get 1 row for 1 user.
        The account is user's funding source.
        Transfers to Stripe are created on the last day of the month.

        1) TransferStripe should have 1 row
        2) The second transfer for the same user in the same day
           should not work.
        3) The amount (total roundup) in TransferStripe row
           should be equal to total sum in TransferPrepare rows.
        4) All TransferPrepare should be processed:
           (is_processed=True)
        """
        e = Emulator()
        e.init()
        Emulator.run_transfer_prepare()
        qs = TransferPrepare.objects.all()
        assert qs.count() > 1

        sum = TransferPrepare.objects.filter(
            is_processed=False, account__item__user=e.user)\
            .aggregate(Sum('roundup'))['roundup__sum']

        # Required for real request to Stripe API in
        # TransferStripe.objects.process_transfers()
        account = e.user.get_funding_source_account()
        access_token, account_id = self.get_access_token()
        account.plaid_id = account_id
        account.save()

        item = account.item
        item.access_token = access_token
        item.save()

        dt = self.get_last_date_of_the_month()
        with freeze_time(dt.strftime('%Y-%m-%d %H:%M:%S')):
            # Emulate last day of the month
            TransferStripe.objects.process_transfers()

            assert TransferStripe.objects.can_process_user(e.user.id) is True

            # 1
            assert TransferStripe.objects.count() == 1

            tr = TransferStripe.objects.first()
            # "created_at" is not match to our mock date
            # Make this condition.
            tr.created_at = timezone.now()
            tr.save()

            # 2
            assert TransferStripe.objects.can_process_user(e.user.id) is False

        # 3
        qs = TransferStripe.objects.filter(account__item__user=e.user)
        assert qs.first().amount == sum

        # 4
        qs = TransferPrepare.objects.filter(is_processed=False)
        assert qs.count() == 0