def test_restart_resets_the_captured_transactions(success_response): sniffing_hook = RequestsSniffer('', '') first_response = requests.get('http://mysniffer.com/api/1/success', hooks={'response': sniffing_hook}) first_response.raise_for_status() sniffing_hook.restart() second_response = requests.get('http://mysniffer.com/api/1/success', hooks={'response': sniffing_hook}) second_response.raise_for_status() assert len(sniffing_hook.transactions) == 1
def test_restart_resets_the_elapsed_time(mocker): mocker.patch('time.time') time.time.return_value = 0.1 sniffing_hook = RequestsSniffer('', '') success_response() start_time = time.time() time.time.return_value = 0.5 response = requests.get('http://mysniffer.com/api/1/success', hooks={'response': sniffing_hook}) time.time.return_value = 2.0 success_response() time.time() - start_time first_transaction = sniffing_hook.transactions[0] sniffing_hook.restart() time.time.return_value = 2.2 response = requests.get('http://mysniffer.com/api/1/success', hooks={'response': sniffing_hook}) response.raise_for_status() second_transaction = sniffing_hook.transactions[0] assert second_transaction.request.elapsed < first_transaction.response.elapsed