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_domain_reputatoin_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 domain_reputation_command from PassiveTotal_v2 import get_human_readable_for_whois_commands from PassiveTotal_v2 import get_context_for_whois_commands # Configure args = {'domain': 'somedomain.com'} with open('TestData/domain_reputatoin/domain_reputatoin_response.json', 'rb') as f: dummy_response = json.load(f) with open('TestData/domain_reputatoin/domain_reputatoin_context.json', 'rb') as f: dummy_custom_context = json.load(f) with open( 'TestData/domain_reputatoin/domain_reputatoin_command_readable_output.md', 'r') as f: dummy_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, is_reputation_command=True) # get custom context via dummy response custom_context = get_context_for_whois_commands(domains)[1] domain_reputation_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 overall command output mock_cr.assert_called_once_with(outputs_prefix='PassiveTotal.Domain', outputs_key_field='domain', outputs=dummy_custom_context, indicators=mock.ANY, readable_output=dummy_readable_output)