Hm, I'm not worried about receiving a valid response from the third-
party API, just about testing the value of the "msg" parameter that's
passed into it.  I need to test the msg parameter because it is in
turn essentially a proxy for which state was reached in my_view.

my_view is actually a great deal more complex than in the example, and
is indeed broken into many smaller function calls.  I need to unit
test to make sure that the logic is correct -- and since all those
function calls return empty HttpResponse objects, I can't use their
return values to test the correctness of their logic.

Just brainstorming here, could there be a way around this by placing a
logging call of some sort in theAPI.call() that would only be executed
during unit testing, and then to test the contents of the log?


On Jun 20, 6:20 pm, DrBloodmoney <drbloodmo...@gmail.com> wrote:
> On Mon, Jun 20, 2011 at 3:52 PM, Nan <ringe...@gmail.com> wrote:
> > I'm not testing the third-party service.  I need to test *what I send
> > to them*.  I.e. that the output of my_view is correct.  The trouble is
> > that neither my_view nor the API call actually returns the output that
> > I need to check.
>
> > Does that make sense?
>
> Mock is one good solution. Here's what I've done in the past
> (basically half-assed mock):
>
> 1. Have representative data sets that are good for the service (eg.
> whatever you send to them, and whatever they send you in return).
> 2. Monkey patch the call:
>
> def hackety_patch():
>     from StringIO import StringIO
>     data = StringIO(testdata_response_from_API)
>     data.seek(0)
>     return data.read()
>
> # in TestCase subclass
> def setUp(self):
>     third_party.api.urllib2.urlopen = hackety_patch
>
> def tearDown(self):
>     third_party.api.urllib2.urlopen = urllib2.urlopen
>
> 3. Break up your API calling code into more testable units to truly
> isolate your independent code from the API calling code. It'll be much
> easier to catch problems in the API integration code.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to