def validate_use_http_wrapper(check): """Return true if the check uses the http wrapper class in any of its files. If any of the check's files uses the request library, abort. check -- name of the check """ has_failed = False check_uses_http_wrapper = False for file in get_check_files(check, include_tests=False): file_uses_http_wrapper, file_uses_request_lib = validate_use_http_wrapper_file(file, check) has_failed = has_failed or file_uses_request_lib check_uses_http_wrapper = check_uses_http_wrapper or file_uses_http_wrapper if has_failed: abort() return check_uses_http_wrapper
def test_get_check_files(get_root): get_root.return_value = '' mock_dir_map = { '': [( 'dns_check', [ 'datadog_checks', 'datadog_dns_check.egg-info', 'tests', '.junit', 'assets' ], [ 'CHANGELOG.md', 'MANIFEST.in', 'setup.py', 'requirements-dev.txt', 'tox.ini', 'manifest.json', 'metadata.csv', ], )], 'datadog_checks': [ (join('dns_check', 'datadog_checks'), ['dns_check'], ['__init__.py']), ( join('dns_check', 'datadog_checks', 'dns_check'), ['data'], ['__init__.py', '__about__.py', 'dns_check.py'], ), (join('dns_check', 'datadog_checks', 'dns_check', 'data'), [], ['conf.yaml.example']), ], '.tox': [(join('dns_check', '.tox'), ['py37', '.tmp', 'py27'], [])], 'datadog_dns_check.egg-info': [(join('dns_check', 'datadog_dns_check.egg-info'), [], ['PKG-INFO', 'SOURCES.txt'])], 'tests': [(join('dns_check', 'tests'), [], ['test_dns_check.py', '__init__.py', 'common.py'])], '.junit': [(join('dns_check', '.junit'), [], ['test-e2e-py37.xml', 'test-e2e-py27.xml'])], 'assets': [(join('dns_check', 'assets'), [], ['service_checks.json'])], } default_py_files = [ join('dns_check', 'datadog_checks', '__init__.py'), join('dns_check', 'datadog_checks', 'dns_check', '__init__.py'), join('dns_check', 'datadog_checks', 'dns_check', '__about__.py'), join('dns_check', 'datadog_checks', 'dns_check', 'dns_check.py'), join('dns_check', 'tests', 'test_dns_check.py'), join('dns_check', 'tests', '__init__.py'), join('dns_check', 'tests', 'common.py'), ] with mock.patch('os.walk') as mockwalk: mockwalk.side_effect = lambda base: mock_dir_map[os.path.basename(base) ] files = get_check_files('dns_check') assert list(files) == default_py_files files = get_check_files('dns_check', file_suffix='.json', include_dirs=['assets']) assert list(files) == [ join('dns_check', 'assets', 'service_checks.json') ] files = get_check_files('dns_check', file_suffix='.json', include_dirs=['', 'assets']) assert list(files) == [ join('dns_check', 'manifest.json'), join('dns_check', 'assets', 'service_checks.json') ]