def test_get_detection_results_with_splash_error(mocker): mocker.patch( 'detectem.cli.get_response', side_effect=SplashError('test') ) with pytest.raises(SplashError): get_detection_results('http://domain.tld', timeout=30, metadata=True)
def test_get_detection_ok(mocker): class FakeDetector: def __init__(*args): pass def get_results(**kwargs): return [1, 2, 3] mocker.patch('detectem.cli.get_response', return_value=1) mocker.patch('detectem.cli.Detector', return_value=FakeDetector) rs = get_detection_results('http://domain.tld', timeout=30, metadata=True) assert rs == [1, 2, 3]
def test_get_detection_ok(mocker): class FakeDetector: def __init__(*args): pass def get_results(**kwargs): return [1, 2, 3] mocker.patch("detectem.cli.get_response", return_value=1) mocker.patch("detectem.cli.Detector", return_value=FakeDetector) rs = get_detection_results("http://domain.tld", timeout=30, metadata=True) assert rs == {"url": "http://domain.tld", "softwares": [1, 2, 3]}
def do_detection(): url = request.forms.get('url') metadata = request.forms.get('metadata') metadata = bool(metadata == '1') try: result = get_detection_results(url, timeout=SPLASH_TIMEOUT, metadata=metadata) except (SplashError, NoPluginsError) as e: result = {'error': e.msg} return json.dumps(result)
def do_detection(): # Url is mandatory url = request.forms.get("url") if not url: return json.dumps({"error": "You must provide `url` parameter."}) # metadata is optional metadata = request.forms.get("metadata", "0") metadata = bool(metadata == "1") # timeout is optional timeout = request.forms.get("timeout", type=int) if not timeout: timeout = SPLASH_TIMEOUT try: result = get_detection_results(url, timeout=timeout, metadata=metadata) except (SplashError, NoPluginsError) as e: result = {"error": e.msg} return json.dumps(result)
def do_detection(): # Url is mandatory url = request.forms.get('url') if not url: return json.dumps({'error': 'You must provide `url` parameter.'}) # metadata is optional metadata = request.forms.get('metadata', '0') metadata = bool(metadata == '1') # timeout is optional timeout = request.forms.get('timeout', type=int) if not timeout: timeout = SPLASH_TIMEOUT try: result = get_detection_results(url, timeout=timeout, metadata=metadata) except (SplashError, NoPluginsError) as e: result = {'error': e.msg} return json.dumps(result)
def test_get_detection_results_with_no_plugins(mocker): mocker.patch('detectem.cli.load_plugins', return_value=[]) with pytest.raises(NoPluginsError): get_detection_results('http://domain.tld', timeout=30, metadata=True)
def do_detection(): url = request.forms.get('url') metadata = request.forms.get('metadata') metadata = bool(metadata == '1') return get_detection_results(url, format='json', metadata=metadata)