Beispiel #1
0
    def test_transfer_cannot_create_transfer_no_recipient(self):
        request = self.factory.post(path=PAYMENT_NEW_TRANSFER_URL,
                                    data=self.TEST_NO_RECIPIENT_TRANSFER_DATA)

        request.user = self.sender
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()
        response = views.new_transfer(request=request)
        self.assertFalse(Transfer.objects.exists())
        self.assertEqual(
            response.status_code, STATUS_CODE_200
        )  # failed to create the transfer. redirect to same view
Beispiel #2
0
    def test_transfer_cannot_create_transfer_anonyme(self):

        request = self.factory.post(path=PAYMENT_NEW_TRANSFER_URL,
                                    data=self.TEST_TRANSFER_DATA)

        request.user = self.anonymeUser
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()

        response = views.new_transfer(request=request)

        self.assertFalse(Transfer.objects.exists())
        self.assertEqual(response.status_code,
                         STATUS_CODE_302)  # redirect to login view
Beispiel #3
0
    def test_transfer_cannot_create_transfer_sender_insufficient_balance(self):

        request = self.factory.post(path=PAYMENT_NEW_TRANSFER_URL,
                                    data=self.TEST_INSUFFICIENT_TRANSFER_DATA)

        request.user = self.sender
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()
        Account.objects.filter(user=self.sender).update(
            balance=ACCOUNT_BALANCE)
        response = views.new_transfer(request=request)

        account_sender = Account.objects.get(user=self.sender)
        account_recipient = Account.objects.get(user=self.recipient)
        self.assertEqual(response.status_code, STATUS_CODE_200)
        self.assertFalse(Transfer.objects.exists())
        self.assertEqual(account_recipient.balance, 0)
        self.assertEqual(account_sender.balance, ACCOUNT_BALANCE)
Beispiel #4
0
    def test_transfer_create_transfer(self):
        request = self.factory.post(path=PAYMENT_NEW_TRANSFER_URL,
                                    data=self.TEST_TRANSFER_DATA)
        request.user = self.sender
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()

        Account.objects.filter(user=self.sender).update(
            balance=ACCOUNT_BALANCE)
        response = views.new_transfer(request=request)

        self.assertEqual(
            response.status_code, STATUS_CODE_302
        )  # succeed to create the transfer. redirect to 'payments:transfer-done'
        account_sender = Account.objects.get(user=self.sender)
        account_recipient = Account.objects.get(user=self.recipient)
        self.assertEqual(account_recipient.balance, TRANSFER_AMOUNT)
        self.assertEqual(account_sender.balance,
                         ACCOUNT_BALANCE - TRANSFER_AMOUNT)
        self.assertTrue(Transfer.objects.exists())