Skip to content

test: Unit testing for paypal/views.py

stephen requested to merge unit-tests--paypal-views into main

This commit adds complete unit test support for /tordonate/paypal/views.py and modifies the directory structure and filename convention inside /tordonate/tests to better reflect the structure and layout of files being tested.

  • The folders tests/paypal/ and tests/paypal/json/ were created, and relevant test files moved into these directories from tests.
  • Additionally, tests/paypal/__init__.py was created so that testing tools would search there for Python files.

In addition, some changes have been made to files being unit tested after testing revealed potential improvements:

  • In paypal/views.py, HttpResponseNotAllowed() is now instantiated with ["POST"] in order to properly express the fact that only POST requests are allowed for that route
  • In paypal/controller.py, isPaymentPaypalFormatted()'s return statement is now wrapped in a try/except block to properly handle TypeError exceptions, such as when isPaymentPaypalFormatted() is passed an integer or float instead of a string.
  • Also in paypal/controller.py, create_subscription() has been modified to phrase the isPaymentPaypalFormatted() check like create_order() does. Rather than passing "Payment malformed" as the ValueError message - which would cause it to be displayed as the user- facing error message, where it would not be tremendously helpful, we instead log that statement and pass self.serviceErrorDisplayMessage as the ValueError message instead, as we do elsewhere throughout the payment process.

Merge request reports