Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
another "Am I doing this wrong?" case of unit tests for a web controller
# test case using fudge 0.9.x for fakes.
class TestUploadList(TestCase):
@with_fakes
def test_upload(self):
"""Upload is converted and JSON returned.
"""
self.req = Fake("Request").has_attr(variables={})
content = "UPLOADED STUFF"
expectedCounts = ["COUNTS"]
self.req.variables['file'] = content
# assert the content is run through conversion
convert = (Fake("convertUpload", expect_call=True)
.with_args(content, arg.any_value()))
self.patch(campaign, "convertUpload", convert)
listclass = Fake("List", callable=True, expect_call=True)
(listclass.returns_fake(name="ListInstance")
.expects('counts')
.returns(expectedCounts))
self.patch(campaign, "List", listclass)
# invoking the unit under test
resp = self.handler.uploadList(self.req)
self.assertIsInstance(resp, Response)
countObj = simplejson.loads(resp.body)
self.assertEqual(expectedCounts, countObj)
# v--- this is the unit under test --v
class CampaignHandler(Handler):
def uploadList(self, req):
# TODO: put that data somewhere
outstream = StringIO()
convertUpload(req.variables['file'], outstream)
l = List(outstream)
counts = l.counts()
return Response(simplejson.dumps(counts), content="text/javascript")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.