def test_pt_whois_search_command_success(request_mocker, mock_cr, client): """ Proper Readable output and context should be set via CommonResults in case of proper response from whois-search API endpoint """ from PassiveTotal_v2 import pt_whois_search_command from PassiveTotal_v2 import get_human_readable_for_whois_commands from PassiveTotal_v2 import get_context_for_whois_commands # Configure args = {'query': '*****@*****.**', 'field': 'email'} with open('test_data/whois_command/whois_command_response.json', 'rb') as f: dummy_response = json.load(f) with open('test_data/whois_command/whois_custom_context.json', 'rb') as f: dummy_custom_context = json.load(f) with open('test_data/whois_command/whois_command_readable_output.md', 'r') as f: dummy_readable_output = f.read() with open( 'test_data/whois_command/whois_command_standard_domain_readable_output.md', 'r') as f: dummy_standard_domain_readable_output = f.read() request_mocker.return_value = dummy_response # Execute domains = dummy_response.get('results') # get human readable via dummy response readable_output = get_human_readable_for_whois_commands(domains) # get custom context via dummy response custom_context = get_context_for_whois_commands(domains)[1] pt_whois_search_command(client, args) # Assert # asserts the readable output assert readable_output == dummy_readable_output # asserts the custom context assert custom_context == dummy_custom_context # assert the standard domain readable output assert dummy_standard_domain_readable_output == mock_cr.call_args_list[0][ 1]['readable_output'] # assert overall command output mock_cr.assert_called_with(outputs_prefix='PassiveTotal.WHOIS', outputs_key_field=['domain', 'lastLoadedAt'], outputs=dummy_custom_context, readable_output=dummy_readable_output, raw_response=dummy_response)
def test_pt_whois_search_empty_response(request_mocker, client): """ Proper message should be display in case of empty response from whois-search API endpoint """ from PassiveTotal_v2 import pt_whois_search_command # Configure args = {'query': '*****@*****.**', 'field': 'email'} empty_response = '{"results": []}' dummy_response = json.loads(empty_response) request_mocker.return_value = dummy_response # Execute message = pt_whois_search_command(client, args) # Assert assert message == 'No domain information were found for the given argument(s).'