def test_includes_the_http_method_as_message_data(self, transaction, expected_method): sniffer = Mock() sniffer.transactions = [transaction()] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.data['method'] == expected_method
def test_creates_a_request_message_from_the_transaction_request( self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.category == htmlvis.seqdiag_model.Category.request
def test_the_server_is_the_message_destination(self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.dst == successful_transaction.server_name
def test_passes_multiple_transactions_to_the_sequence_diagram_generator( self, successful_transaction, error_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction, error_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) messages = htmlvis.seqdiag.draw.call_args[1]['messages'] assert len(messages) == 4
def test_writes_the_html_sequence_diagram_to_the_output_file( self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) open.return_value.write.assert_called_once_with( htmlvis.seqdiag.draw.return_value)
def test_combines_http_method_and_url_path_as_message_text( self, transaction, expected_text): sniffer = Mock() sniffer.transactions = [transaction()] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.text == expected_text
def test_the_url_is_passed_as_additional_data(self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.data[ 'url'] == successful_transaction.request.url_path
def test_gets_transactions_from_all_sniffers(self, successful_transaction, error_transaction): sniffer_a = Mock() sniffer_a.transactions = [successful_transaction] sniffer_b = Mock() sniffer_b.transactions = [error_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer_a, sniffer_b]) messages = htmlvis.seqdiag.draw.call_args[1]['messages'] assert len(messages) == 4
def test_converts_transactions_to_messages_ordered_by_elapsed_time( self, successful_transaction, error_transaction): successful_transaction.request.elapsed = 0.01 successful_transaction.response.elapsed = 0.05 error_transaction.request.elapsed = 0.02 error_transaction.response.elapsed = 0.03 sniffer = Mock() sniffer.transactions = [ successful_transaction, error_transaction, ] htmlvis.save_seq_diag('/fake/path', [sniffer]) messages = htmlvis.seqdiag.draw.call_args[1]['messages'] msg_time = [msg.when for msg in messages] assert msg_time == [0.01, 0.02, 0.03, 0.05]
def main(): logging.basicConfig(level=logging.DEBUG) sniffer = RequestsSniffer('Sample client', 'I. Chuck Norris DB') response = requests.get('http://api.icndb.com/jokes/random', hooks={'response': sniffer}) diag = save_seq_diag('diagram.html', [sniffer]) print(diag)
def test_the_body_is_passed_as_note(self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) request_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][0] assert request_msg.note == successful_transaction.request.body
def test_opens_the_output_file_path_for_writing(self, mocker, successful_transaction): sniffer = Mock() sniffer.transactions = [successful_transaction] htmlvis.save_seq_diag('/fake/path', [sniffer]) open.assert_called_once_with('/fake/path', 'w')
def test_uses_the_status_as_message_text(self, transaction, expected_text): sniffer = Mock() sniffer.transactions = [transaction()] htmlvis.save_seq_diag('/fake/path', [sniffer]) response_msg = htmlvis.seqdiag.draw.call_args[1]['messages'][1] assert response_msg.text == expected_text