rossp/django-pinpayments — pull request #1 by huwshimi (2013-06-20 12:44:25+00:00)
Title: Add unit tests for models and template tags

Added unit tests for the models (and model functions) and template tag functions. These tests are run against mocked requests and there are no live API integration tests.

This branch also adds a dependency on Mock.

In models.py I had to modify how the settings were requested so that instead of asking for 'pin_config' it always does a look up like "getattr(settings, 'PIN_ENVIRONMENTS', {})". This is so that the settings do not get cached inside the models module for the cases that settings are modified dynamically. This helps us to test with different settings and also won't break for people who aren't running with static settings.

In 'process_transaction()' I removed the "if self.environment not in pin_config.keys():" as at the top of 'process_transaction()' we call save() which does the same validation and that check never gets called.

Also in 'process_transaction()' if the response has an error there is check for "self.transaction_token = r['charge_token']". I could not reproduce a response including 'charge_token' but I may have not make the right request. I added 'charge_token' to the mocked request so that the tests pass, but wanted to check this was correct.

I think they were the only changes that weren't bug fixes. Please let me know if I've missed anything confusing.

Hope this is all helpful, let me know if there are things I need to fix up.