Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Make sure purchase_failed() passes kwargs along
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Apr 23, 2012
1 parent 940f014 commit 9d9d064
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions armstrong/apps/donations/tests/views.py
Expand Up @@ -226,6 +226,27 @@ def test_form_is_valid_passes_kwargs_to_purchase_failed(self):

fudge.verify()

def test_purchase_failed_passes_kwargs_to_get_context_data(self):
backend_response = {
"reason": "Some Random Reason",
"response": "Some Random Response",
}
r = lambda: random.randint(100, 200)
random_kwargs = {
"slug%d" % r(): "foo-%d" % r(),
}

get_context_data = fudge.Fake()
(get_context_data.expects_call()
.with_args(**random_kwargs)
.returns({}))

view = self.post_view
with fudge.patched_context(view, "get_context_data", get_context_data):
view.purchase_failed(backend_response, **random_kwargs)

fudge.verify()


def form_is_valid_response(confirmed=False):
def outer(func):
Expand Down
8 changes: 4 additions & 4 deletions armstrong/apps/donations/views.py
Expand Up @@ -110,11 +110,11 @@ def form_is_valid(self, donation_form, **kwargs):
return self.purchase_failed(response, **kwargs)
return HttpResponseRedirect(self.success_url)

def purchase_failed(self, backend_response):
context = {
def purchase_failed(self, backend_response, **kwargs):
context = self.get_context_data(**kwargs)
context.update({
"error_msg": "Unable to process payment",
"reason": backend_response["reason"],
"response": backend_response["response"],
}
context.update(self.get_context_data())
})
return self.render_to_response(context)

0 comments on commit 9d9d064

Please sign in to comment.