Exemple #1
0
    def test_order_closed_api(self):
        # Setup.
        order_id = self._make_api_donation(self.some_user, project=self.some_project, amount=10)
        # Emulate a status change from DocData. Note we need to use an internal API from COWRY for this but it's hard
        # to avoid because we can't automatically make a DocData payment.
        order = Order.objects.get(id=order_id)
        adapter = _adapter_for_payment_method(order.latest_payment.payment_method_id)
        adapter._change_status(order.latest_payment, PaymentStatuses.pending)
        order = Order.objects.get(id=order.id)
        self.assertEqual(order.status, OrderStatuses.closed)

        # Editing the recurring status of a closed order should not be allow.
        order_detail_url = '{0}{1}'.format(self.order_url_base, order_id)
        response = self.client.put(order_detail_url, json.dumps({'recurring': True}), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        # Listing a closed order should be allowed.
        order_donation_list_url = '{0}{1}'.format(order_detail_url, '/donations/')
        response = self.client.get(order_donation_list_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(response.data['count'], 1)

        # Editing a donation with order closed should not be allowed.
        donation_detail_url = '{0}{1}'.format(order_donation_list_url, response.data['results'][0]['id'])
        response = self.client.put(donation_detail_url, json.dumps({'project': self.some_project.slug, 'amount': 5}), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

        # Adding a donation to a closed order should not be allowed.
        response = self.client.post(order_donation_list_url, {'project': self.some_project.slug, 'amount': 10})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
Exemple #2
0
    def test_payment_profile_and_payment_api(self):
        """
        Integration tests for the PaymentProfile and Payment APIs.
        """
        # Setup.
        self._make_api_donation(self.some_user, amount=35, set_payment_method=False)
        payment_url = '{0}{1}'.format(self.payment_url_base, 'current')
        response = self.client.get(payment_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        first_payment_method = response.data['available_payment_methods'][0]

        # Updating the payment method with a value not in the available list should fail.
        response = self.client.put(payment_url, json.dumps({'payment_method': 'some-new-fancy-pm'}), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

        # Updating the payment method with a valid value should provide a payment_url.
        response = self.client.put(payment_url, json.dumps({'payment_method': first_payment_method}), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertTrue(response.data['payment_url'])  # Not empty payment_url.

        # Emulate a status change from DocData. Note we need to use an internal API from COWRY for this but it's hard
        # to avoid because we can't automatically make a DocData payment.
        order = Order.objects.get(user=self.some_user)
        adapter = _adapter_for_payment_method(order.latest_payment.payment_method_id)
        adapter._change_status(order.latest_payment, PaymentStatuses.pending)
        order = Order.objects.get(id=order.id)
        self.assertEqual(order.status, OrderStatuses.closed)
Exemple #3
0
    def test_payment_profile_and_payment_api(self):
        """
        Integration tests for the PaymentProfile and Payment APIs.
        """
        # Make sure we have a current order.
        self.client.login(username=self.some_user.username, password='******')
        response = self.client.get(self.current_order_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(response.data['status'], 'current')

        # Create a Donation for the current order.
        response = self.client.post(self.current_donations_url, {'project': self.some_project.slug, 'amount': 35})
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)
        self.assertEqual(response.data['amount'], '35.00')
        self.assertEqual(response.data['project'], self.some_project.slug)
        self.assertEqual(response.data['status'], 'new')

        # Now retrieve the current order payment profile.
        response = self.client.get(self.payment_profile_current_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)

        # Update the current order payment profile with our information.
        response = self.client.put(self.payment_profile_current_url, self.some_profile)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(response.data['first_name'], 'Nijntje')
        self.assertEqual(response.data['last_name'], 'het Konijnje')
        self.assertEqual(response.data['email'], '*****@*****.**')
        self.assertEqual(response.data['address'], 'Dam')
        self.assertEqual(response.data['postal_code'], '1001AM')
        self.assertEqual(response.data['city'], 'Amsterdam')
        self.assertEqual(response.data['country'], 'NL')

        # Now it's time to pay. Get the payment record.
        response = self.client.get(self.payment_current_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertFalse(response.data['payment_url'])  # Empty payment_url.
        first_payment_method = response.data['available_payment_methods'][0]

        # Updating the payment method with a value not in the available list should fail.
        response = self.client.put(self.payment_current_url, {'payment_method': 'some-new-fancy-pm'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)

        # Updating the payment method with a valid value should provide a payment_url.
        response = self.client.put(self.payment_current_url, {'payment_method': first_payment_method})
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertTrue(response.data['payment_url'])  # Not empty payment_url.

        # The status of the Order should now be 'in_progress'.
        order = Order.objects.filter(user=self.some_user).get()
        self.assertEqual(order.status, OrderStatuses.in_progress)

        # Emulate a status change from DocData. Note we need to use an internal API from COWRY for this but it's hard
        # to avoid because we can't automatically make a DocData payment.
        adapter = _adapter_for_payment_method(order.payment.payment_method_id)
        adapter._change_status(order.payment, PaymentStatuses.pending)
        order = Order.objects.filter(user=self.some_user).get()
        self.assertEqual(order.status, OrderStatuses.closed)