Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 3
0
    def test_get_transfer_donkies(self, client):
        e = Emulator()
        e.init()
        e.run_transfer_prepare()
        e.run_transfer_donkies_prepare()
        e.emulate_dwolla_transfers()
        client = self.get_auth_client(e.user)

        url = '/v1/transfers_donkies'
        response = client.get(url)
        assert response.status_code == 200
Ejemplo n.º 4
0
    def test06(self, dwolla):
        """
        Should be last test as it changes fixture's funding_source to R01.

        Test initiate and update transfer with insufficient funds.
        1) Should get failed status.
        2) Update failure_code.
        3) Failure code should be "R01"
        """
        customer = dwolla['customer']
        funding_source = get_or_create_funding_source(customer, name='R01')

        e = Emulator(num_debit_accounts=1)
        e.init()
        e.make_transfer_prepare_condition()

        Emulator.run_transfer_prepare()
        Emulator.run_transfer_donkies_prepare()

        # Exchange dwolla_id for mock debit account with
        # real funding source dwolla_id from API
        account = e.debit_accounts[0]
        fs = account.funding_source
        fs.dwolla_id = funding_source['id']
        fs.save()

        tds = TransferDonkies.objects.first()
        tds.save()

        TransferDonkies.objects.initiate_dwolla_transfer(tds.id)

        for _ in range(20):
            TransferDonkies.objects.update_dwolla_transfer(
                tds.id, is_test=True)
            tds.refresh_from_db()

            print('Transfer status: ', tds.status)

            # Process sandbox transfers
            self.dw.press_sandbox_button()

            if tds.status and tds.status != TransferDonkies.PENDING:
                break
            time.sleep(5)

        assert tds.status == TransferDonkies.FAILED
        assert tds.is_failed is True
        assert tds.failure_code is None

        TransferDonkies.objects.update_dwolla_failure_code(tds.id)
        tds.refresh_from_db()
        assert tds.failure_code == 'R01'
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    def test_03(self):
        """
        After processing transfers from TransferPrepare to
        TransferFonkies, Transfer prepare shouldn't have
        is_processed=False, everything should be processed.
        """
        e = Emulator()
        e.init()
        e.make_transfer_prepare_condition()

        Emulator.run_transfer_prepare()
        qs = TransferPrepare.objects.filter(is_processed=False)
        assert qs.count() > 0

        Emulator.run_transfer_donkies_prepare()

        qs = TransferPrepare.objects.filter(is_processed=False)
        assert qs.count() == 0
Ejemplo n.º 7
0
    def test_01(self):
        """
        After prepare transfer from TransferPrepare to
        TransferDonkies, TransferDonkies should get 1 row
        for 1 user. The account is user's funding source.
        """
        # User 1
        e1 = Emulator()
        e1.init()

        # User 2
        e2 = Emulator()
        e2.init()

        Emulator.run_transfer_prepare()
        Emulator.run_transfer_donkies_prepare()

        assert TransferDonkies.objects.count() == 2
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def test05(self, dwolla):
        """
        Test initiate and update transfer with success status.
        """
        funding_source = dwolla['funding_source']

        e = Emulator(num_debit_accounts=1)
        e.init()
        e.make_transfer_prepare_condition()

        Emulator.run_transfer_prepare()
        Emulator.run_transfer_donkies_prepare()

        # Exchange dwolla_id for mock debit account with
        # real funding source dwolla_id from API
        account = e.debit_accounts[0]
        fs = account.funding_source
        fs.dwolla_id = funding_source['id']
        fs.save()

        tds = TransferDonkies.objects.first()
        tds.save()

        TransferDonkies.objects.initiate_dwolla_transfer(tds.id)

        for _ in range(20):
            TransferDonkies.objects.update_dwolla_transfer(
                tds.id, is_test=True)
            tds.refresh_from_db()

            print('Transfer status: ', tds.status)

            # Process sandbox transfers
            self.dw.press_sandbox_button()

            if tds.status and tds.status != TransferDonkies.PENDING:
                break
            time.sleep(5)

        assert tds.status == TransferDonkies.PROCESSED
        assert tds.is_sent is True
        assert tds.sent_at is not None
        assert tds.updated_at is not None
Ejemplo n.º 10
0
 def setup(self):
     e = Emulator()
     e.init()
     e.run_transfer_prepare()
     e.run_transfer_donkies_prepare()
     self.user = e.user