falcon
falcon copied to clipboard
Testing Improvement: Allow Capture of srmock Body for Better Unit Tests
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)
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)