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
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
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
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()
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
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
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