<br><br><div class="gmail_quote">On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Mike wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
<br>
I'm writing an application that needs to fetch a json file from a webserver. I'm writing the tests and have a question:<br>
<br>
if I have the following methods:<br>
<br>
def test_headers(self):<br>
    headers = libary.get_data(data)<br>
    check header status<br>
</blockquote>
<br></div>
With no json experience specifically....<br>
<br>
Checking I/O is nasty since the test running correctly depends on external resources running correctly and not just your program.  I would separate I/O tests from 'process the data' checks and do the latter with canned data.  If the canned data built into the test is the same as that on the test server, then testing the fetch is an equality test.<div>
<div></div><div class="h5"><br>
</div></div></blockquote><div>Thanks, I think I need to separate the tests.<br><br>The way JSON works is: Open a url with a request <- this returns a file like object, the JSON libary reads the file like object and returns a list of dictionary objects.<br>
<br>So first I want to make sure when I do the request I get a 200 OK response, second I want to make sure the JSON object matches my predefined object for it (to ensure no API changes).<br><br>I think I'll have an external test, which will do two calls (unless I can use the result of the response check test). And if this test passes I will then run my mock test which tests for functionality (and can be run offline). If the first fails then its an indication that the api may have changed and I need to change my mocks.<br>
<br>Is this a good testing method/ approach?<br></div></div><br>