test: Unit testing for paypal/views.py
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/
andtests/paypal/json/
were created, and relevant test files moved into these directories fromtests
. - 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 atry/except
block to properly handle TypeError exceptions, such as whenisPaymentPaypalFormatted()
is passed an integer or float instead of a string. - Also in
paypal/controller.py
,create_subscription()
has been modified to phrase theisPaymentPaypalFormatted()
check likecreate_order()
does. Rather than passing "Payment malformed" as theValueError
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 passself.serviceErrorDisplayMessage
as theValueError
message instead, as we do elsewhere throughout the payment process.