falcon icon indicating copy to clipboard operation
falcon copied to clipboard

Testing Improvement: Allow Capture of srmock Body for Better Unit Tests

Open queertypes opened this issue 13 years ago • 1 comments

I'd like to be able to issue the following style of code and have it work:

# Can already do this much
self.auth_cache.redis.setex(key_hash('1'), ttl=1200, 0)
self.simulate_request('/key/1', method='GET')                                                                                                                       
self.assertEqual(self.srmock.status, falcon.HTTP_200)

# Highly desired
resp_parsed = json.loads(self.srmock.body)
self.assertEqual(resp_parsed['ttl'], 1200)

queertypes avatar May 17 '13 11:05 queertypes

Nevermind. I didn't notice that simulate_request could be used to capture the body, as in:

self.auth_cache.redis.setex(key_hash('1'), ttl=1200, 0)
body = self.simulate_request('/key/1', method='GET')                                                                                                                       
self.assertEqual(self.srmock.status, falcon.HTTP_200)

# Highly desired
resp_parsed = json.loads(body)
self.assertEqual(resp_parsed['ttl'], 1200)

queertypes avatar May 17 '13 12:05 queertypes