def test_done(self): response = ResponseAsync() self.assertFalse(response.done(), 'response does not start done') std_response = Response(200) response.fulfill(std_response) self.assertTrue(response.done(), 'response is done after call to fulfill')
def test_set_and_flag(self): response = ResponseAsync() self.assertFalse(response.done(), 'response does not start done') delay = 0.1 WaitAndSet(response, Response(200), delay).start() start = datetime.now() self.assertFalse(response.done(), 'response still not done') self.assertEqual(response.status, 200, 'expected status code') duration = datetime.now() - start min = timedelta(seconds=delay - 0.1) max = timedelta(seconds=delay + 0.1) self.assertTrue(min < duration and duration < max, 'took around 1s to get response and content') self.assertTrue(response.done(), 'response now done')