Example #1
0
    def test_payment_cannot_create_payment_no_recipient(self):
        request = self.factory.post(path=PAYMENT_NEW_PAYMENT_URL,
                                    data=self.TEST_NO_RECIPIENT_PAYMENT_DATA)

        request.user = self.sender
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()
        response = views.new_payment(request=request)
        self.assertFalse(Payment.objects.exists())
        self.assertEqual(
            response.status_code, STATUS_CODE_200
        )  # failed to create the payment. redirect to same view
Example #2
0
    def test_payment_cannot_create_payment_anonyme(self):

        request = self.factory.post(path=PAYMENT_NEW_PAYMENT_URL,
                                    data=self.TEST_PAYMENT_DATA)

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

        response = views.new_payment(request=request)

        self.assertFalse(Payment.objects.exists())
        self.assertEqual(response.status_code,
                         STATUS_CODE_302)  # redirect to login view
Example #3
0
    def test_payment_cannot_create_payment_sender_insufficient_balance(self):

        request = self.factory.post(path=PAYMENT_NEW_PAYMENT_URL,
                                    data=self.TEST_INSUFFICIENT_PAYMENT_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_payment(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(Payment.objects.exists())
        self.assertEqual(account_recipient.balance, 0)
        self.assertEqual(account_sender.balance, ACCOUNT_BALANCE)
Example #4
0
    def test_payment_create_payment(self):
        request = self.factory.post(path=PAYMENT_NEW_PAYMENT_URL,
                                    data=self.TEST_PAYMENT_DATA)
        request.user = self.sender
        request = add_middledware_to_request(request, SessionMiddleware)
        request.session.save()
        policy = Policy(**policy_test_data.POLICY_DATA)
        policy.save()
        policy.users.add(self.pay_user)
        Account.objects.filter(user=self.sender).update(
            balance=ACCOUNT_BALANCE)
        response = views.new_payment(request=request)

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