def main(args): """ Execute a test against the given base url. Keys allowed for args: url - REQUIRED - Base URL test - REQUIRED - Test file (yaml) print_bodies - OPTIONAL - print response body log - OPTIONAL - set logging level {debug,info,warning,error,critical} (default=warning) interactive - OPTIONAL - mode that prints info before and after test exectuion and pauses for user input for each test absolute_urls - OPTIONAL - mode that treats URLs in tests as absolute/full URLs instead of relative URLs """ if 'log' in args and args['log'] is not None: logger.setLevel(LOGGING_LEVELS.get(args['log'].lower(), logging.NOTSET)) if 'import_extensions' in args and args['import_extensions']: extensions = args['import_extensions'].split(';') # We need to add current folder to working path to import modules working_folder = args['cwd'] if working_folder not in sys.path: sys.path.insert(0, working_folder) register_extensions(extensions) test_file = args['test'] test_structure = read_test_file(test_file) my_vars = None if 'vars' in args and args['vars'] is not None: my_vars = yaml.safe_load(args['vars']) if my_vars and not isinstance(my_vars, dict): raise Exception("Variables must be a dictionary!") # Set up base URL base_url = args['url'] if 'absolute_urls' in args and args['absolute_urls']: base_url = '' tests = parse_testsets(base_url, test_structure, working_directory=os.path.dirname(test_file), vars=my_vars) # Override configs from command line if config set for t in tests: if 'print_bodies' in args and args['print_bodies'] is not None and bool(args['print_bodies']): t.config.print_bodies = safe_to_bool(args['print_bodies']) if 'interactive' in args and args['interactive'] is not None: t.config.interactive = safe_to_bool(args['interactive']) if 'verbose' in args and args['verbose'] is not None: t.config.verbose = safe_to_bool(args['verbose']) if 'ssl_insecure' in args and args['ssl_insecure'] is not None: t.config.ssl_insecure = safe_to_bool(args['ssl_insecure']) # Execute all testsets failures = run_testsets(tests) sys.exit(failures)
def test_safe_boolean(self): """ Test safe conversion to boolean """ self.assertFalse(safe_to_bool(False)) self.assertTrue(safe_to_bool(True)) self.assertTrue(safe_to_bool('True')) self.assertTrue(safe_to_bool('true')) self.assertTrue(safe_to_bool('truE')) self.assertFalse(safe_to_bool('false')) # Try things that should throw exceptions try: boolean = safe_to_bool('fail') raise AssertionError('Failed to throw type error that should have') except TypeError: pass # Good try: boolean = safe_to_bool([]) raise AssertionError('Failed to throw type error that should have') except TypeError: pass # Good try: boolean = safe_to_bool(None) raise AssertionError('Failed to throw type error that should have') except TypeError: pass # Good
def test_safe_boolean(self): """ Test safe conversion to boolean """ self.assertFalse(safe_to_bool(False)) self.assertTrue(safe_to_bool(True)) self.assertTrue(safe_to_bool('True')) self.assertTrue(safe_to_bool('true')) self.assertTrue(safe_to_bool('truE')) self.assertFalse(safe_to_bool('false')) #Try things that should throw exceptions try: boolean = safe_to_bool('fail') raise AssertionError('Failed to throw type error that should have') except TypeError: pass #Good try: boolean = safe_to_bool([]) raise AssertionError('Failed to throw type error that should have') except TypeError: pass #Good try: boolean = safe_to_bool(None) raise AssertionError('Failed to throw type error that should have') except TypeError: pass #Good
def parse_configuration(node, base_config=None): """ Parse input config to configuration information """ test_config = base_config if not test_config: test_config = TestConfig() node = lowercase_keys(flatten_dictionaries(node)) # Make it usable for key, value in node.items(): if key == u'timeout': test_config.timeout = int(value) elif key == u'print_bodies': test_config.print_bodies = safe_to_bool(value) elif key == u'retries': test_config.retries = int(value) elif key == u'variable_binds': if not test_config.variable_binds: test_config.variable_binds = dict() test_config.variable_binds.update(flatten_dictionaries(value)) elif key == u'generators': flat = flatten_dictionaries(value) gen_map = dict() for generator_name, generator_config in flat.items(): gen = parse_generator(generator_config) gen_map[str(generator_name)] = gen test_config.generators = gen_map return test_config
def main(args): """ Execute a test against the given base url. Keys allowed for args: url - REQUIRED - Base URL test - REQUIRED - Test file (yaml) print_bodies - OPTIONAL - print response body log - OPTIONAL - set logging level {debug,info,warning,error,critical} (default=warning) interactive - OPTIONAL - mode that prints info before and after test exectuion and pauses for user input for each test """ if 'log' in args and args['log'] is not None: logger.setLevel(LOGGING_LEVELS.get(args['log'].lower(), logging.NOTSET)) if 'import_extensions' in args and args['import_extensions']: extensions = args['import_extensions'].split(';') # We need to add current folder to working path to import modules working_folder = args['cwd'] if working_folder not in sys.path: sys.path.insert(0, working_folder) register_extensions(extensions) test_file = args['test'] test_structure = read_test_file(test_file) tests = parse_testsets(args['url'], test_structure, working_directory=os.path.dirname(test_file)) # Override configs from command line if config set for t in tests: if 'print_bodies' in args and args['print_bodies'] is not None and bool(args['print_bodies']): t.config.print_bodies = safe_to_bool(args['print_bodies']) if 'interactive' in args and args['interactive'] is not None: t.config.interactive = safe_to_bool(args['interactive']) if 'retries' in args and args['retries'] is not None: t.config.retries = args['retries'] logger.debug("Enable retries " + str(t.config.retries)) # Execute all testsets failures = run_testsets(tests) sys.exit(failures)
def main(args): """ Execute a test against the given base url. Keys allowed for args: url - REQUIRED - Base URL test - REQUIRED - Test file (yaml) print_bodies - OPTIONAL - print response body log - OPTIONAL - set logging level {debug,info,warning,error,critical} (default=warning) interactive - OPTIONAL - mode that prints info before and after test exectuion and pauses for user input for each test """ if 'log' in args and args['log'] is not None: logger.setLevel(LOGGING_LEVELS.get(args['log'].lower(), logging.NOTSET)) if 'import_extensions' in args and args['import_extensions']: extensions = args['import_extensions'].split(';') # We need to add current folder to working path to import modules working_folder = args['cwd'] if working_folder not in sys.path: sys.path.insert(0, working_folder) register_extensions(extensions) test_file = args['test'] test_structure = read_test_file(test_file) tests = parse_testsets(args['url'], test_structure, working_directory=os.path.dirname(test_file)) # Override configs from command line if config set for t in tests: if 'print_bodies' in args and args['print_bodies'] is not None and bool(args['print_bodies']): t.config.print_bodies = safe_to_bool(args['print_bodies']) if 'interactive' in args and args['interactive'] is not None: t.config.interactive = safe_to_bool(args['interactive']) # Execute all testsets failures = run_testsets(tests) sys.exit(failures)