def test_can_run_funkload(self): conf = WightConfig.load(join(root_path, 'bench', 'wight.yml')) test = conf.tests[0] result = FunkLoadTestRunner.run(root_path, test, self.base_url) expect(result).not_to_be_null() expect(result.exit_code).to_equal(0) text = re.sub(r"\d[.]\d{3}s", "", result.text) expect(text).to_be_like(""" test_healthcheck: [ftest] sleep_time_min not found test_healthcheck: [ftest] sleep_time_max not found test_healthcheck: [ftest] log_path not found test_healthcheck: [ftest] result_path not found . ---------------------------------------------------------------------- Ran 1 test in OK """) log = re.sub("\d*\-\d*\-\d*\s\d*[:]\d*[:]\d*[,]\d*\s", "", result.log) log = re.sub(r"\d[.]\d{3}s", "", log) expect(log).to_be_like(""" INFO test_healthcheck: [test_healthcheck] description not found DEBUG test_healthcheck: Starting ----------------------------------- DEBUG test_healthcheck: GET: http://localhost:2368/HealthCheck Page 1: Get url ... DEBUG test_healthcheck: Done in """)
def test_can_run_funkload(self): team = TeamFactory.create() TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project) load_test.pressure = "small" conf = WightConfig.load(join(root_path, 'bench', 'wight.yml')) test = conf.tests[0] DEFAULT_CYCLES = { "small": [10, 20], "medium": [10, 20, 30], "large": [30, 75, 100], } fl_result = FunkLoadBenchRunner.run(root_path, test, self.base_url, cycles=DEFAULT_CYCLES, duration=5) expect(fl_result).not_to_be_null() expect(fl_result.exit_code).to_equal(0) expect(fl_result.text).to_include("SUCCESSFUL") expect(fl_result.log).to_be_empty() expect(fl_result.result).not_to_be_null() expect(fl_result.config).not_to_be_null() result = LoadTest.get_data_from_funkload_results(fl_result.config, fl_result.result) load_test.add_result(result, fl_result.text) expect(load_test.results).to_length(1)
def test_can_run_funkload_with_dep(self): test_path = join(root_path, 'tests', 'functional') copy(join(test_path, 'with_deps.yml'), join(root_path, 'bench', 'with_deps.yml')) conf = WightConfig.load(join(root_path, 'bench', 'wight.yml')) test = conf.tests[0] result = FunkLoadTestRunner.run(root_path, test, self.base_url) expect(result).not_to_be_null() expect(result.exit_code).to_equal(0)
def test_can_load_files(self): cfg = WightConfig.load(join(root_path, 'wight.yml')) expect(cfg).not_to_be_null() expect(cfg.tests).to_length(1) expect(cfg.tests[0].module).to_equal("healthcheck.py") expect(cfg.tests[0].class_name).to_equal("HealthCheckTest") expect(cfg.tests[0].test_name).to_equal("test_healthcheck")
def test_can_report_failure(self): test_path = join(root_path, 'tests', 'functional') conf = WightConfig.load(join(test_path, 'failures.yml')) test = conf.tests[0] result = FunkLoadTestRunner.run(test_path, test, self.base_url) expect(result).not_to_be_null() expect(result.exit_code).to_equal(1) expect(result.text).to_include("ImportError: No module named fail")
def test_can_parse_configuration_with_utf8(self): cfg_text = """ tests: - description: Testa a saúde da página. module: healthcheck.py class: HealthCheckTest test: test_healthcheck """ cfg = WightConfig(cfg_text) expect(cfg).not_to_be_null() expect(cfg.tests).to_length(1) expect(cfg.tests[0].description).to_equal("Testa a saúde da página.")
def test_can_parse_configuration_with_deps(self): cfg_text = """ tests: - module: healthcheck.py class: HealthCheckTest test: test_healthcheck deps: - request - six """ cfg = WightConfig(cfg_text) expect(cfg).not_to_be_null() expect(cfg.tests).to_length(1) expect(cfg.tests[0].deps).to_be_like(["request", "six"])
def test_can_parse_configuration(self): cfg_text = """ tests: - module: healthcheck.py class: HealthCheckTest test: test_healthcheck """ cfg = WightConfig(cfg_text) expect(cfg).not_to_be_null() expect(cfg.tests).to_length(1) expect(cfg.tests[0].module).to_equal("healthcheck.py") expect(cfg.tests[0].class_name).to_equal("HealthCheckTest") expect(cfg.tests[0].test_name).to_equal("test_healthcheck")
def test_can_run_funkload(self): team = TeamFactory.create() TeamFactory.add_projects(team, 1) user = team.owner project = team.projects[0] load_test = LoadTestFactory.add_to_project(1, user=user, team=team, project=project) load_test.pressure = "small" conf = WightConfig.load(join(root_path, 'bench', 'wight.yml')) test = conf.tests[0] DEFAULT_CYCLES = { "small": [10, 20], "medium": [10, 20, 30], "large": [30, 75, 100], } fl_result = FunkLoadBenchRunner.run(root_path, test, self.base_url, cycles=DEFAULT_CYCLES, duration=5) expect(fl_result).not_to_be_null() expect(fl_result.exit_code).to_equal(0) expect(fl_result.text).to_include("SUCCESSFUL") expect(fl_result.log).to_be_empty() expect(fl_result.result).not_to_be_null() expect(fl_result.config).not_to_be_null() result = LoadTest.get_data_from_funkload_results( fl_result.config, fl_result.result) load_test.add_result(result, fl_result.text) expect(load_test.results).to_length(1)
def test_loading_a_file_that_does_not_exist_returns_none(self): cfg = WightConfig.load('/invalid/path') expect(cfg).to_be_null()
def _load_config_from_yml(self, base_path): logging.debug("parse yml") bench_path = join(base_path, 'bench') return WightConfig.load(join(bench_path, 'wight.yml'))