def test_c4077_get_results(self): case_id = self.cases[1].id original_run = Run(name="A Test Run", case_ids=[case_id], include_all=False) created_run = self.client.add_run(original_run, self.project.id) tests = self.client.get_tests(created_run.id) assert len(tests) == 1 test_id = tests[0].id statuses = [Statuses.failed, Statuses.failed, Statuses.retest, Statuses.passed] original_results = [] expected_results = {} for index, status in enumerate(statuses): comment = f"Result number {index}" result = Result(status_id=status, test_id=test_id, comment=comment) original_results.append(result) expected_results[comment] = result self.client.add_results(original_results, created_run.id) results = self.client.get_results(test_id) assert len(results) == len(expected_results) for result in results: expected = expected_results.pop(result.comment) assert result.status_id == expected.status_id assert result.test_id == expected.test_id assert result.comment == expected.comment
def test_c5833_close_run(self): original = Run(name="A Test Run", description="This is a test run", include_all=True) created_run = self.client.add_run(original, self.project.id) updated_run = self.client.close_run(created_run) assert updated_run.is_completed assert updated_run.completed_on > 0
class TestTestsAPI(APIBaseTest): @pytest.mark.testrail(ids=[4071, 4072]) def test_c4071_c4072_get_test_get_tests(self): # get_test and get_tests are also extensively exercised by test_runs_and_results section = Section(name="Some Section") section = self.client.add_section(section, self.project.id) cases = [] for title in ["Case 1", "Case 2", "Case 3"]: case = Case(title=title, type_id=7, priority_id=2, estimate="10m") case = self.client.add_case(case, section.id) cases.append(case) run = Run(name="A Test Run", description="This is a test run", include_all=True) run = self.client.add_run(run, self.project.id) tests = self.client.get_tests(run.id) assert set(case.id for case in cases) == set(test.case_id for test in tests) for test in tests: assert test.priority_id == 2 assert test.estimate == "10m" individual = self.client.get_test(test.id) # This checks all fields assert individual == test
def test_c4069_get_runs(self): runs = {} run_names = ["Test Run 1", "Test Run 2", "Test Run 3"] for name in run_names: run = Run(name=name, include_all=True) run = self.client.add_run(run, self.project.id) runs[name] = run created = self.client.get_runs(self.project.id) assert len(created) == len(runs) assert set(run.name for run in created) == set(run_names) created_dict = {run.name:run for run in created} for name in run_names: original = runs[name] created_run = created_dict[name] assert created_run.name == original.name assert created_run.include_all assert not created_run.is_completed assert created_run.project_id == self.project.id assert created_run.passed_count == 0 assert created_run.retest_count == 0 assert created_run.blocked_count == 0 assert created_run.failed_count == 0 assert created_run.untested_count == 3
def test_c4112_add_run_empty_run(self): original = Run(name="A Test Run", description="This is a test run", include_all=False) created = self.client.add_run(original, self.project.id) assert created.passed_count == 0 assert created.retest_count == 0 assert created.blocked_count == 0 assert created.failed_count == 0 assert created.untested_count == 0
def test_c4068_get_run(self): original = Run(name="A Test Run", description="This is a test run", include_all=True) created = self.client.add_run(original, self.project.id) run = self.client.get_run(created.id) assert run.id == created.id assert run.name == created.name assert run.description == created.description assert run.include_all
def test_c5776_delete_run(self): original = Run(name="A Test Run", description="This is a test run", include_all=True) created = self.client.add_run(original, self.project.id) runs = self.client.get_runs(self.project.id) assert created.id in set(run.id for run in runs) self.client.delete_run(created) updated_runs = self.client.get_runs(self.project.id) assert created.id not in set(run.id for run in updated_runs)
def test_c9362_get_runs_with_valid_limit(self, params, result): created_runs = [] try: for item in range(10): run = Run(name=f"Test Run {item}") resp = self.client.add_run(run, self.project.id) created_runs.append(resp) runs = self.client.get_runs(self.project.id, **params) assert len(runs) == result finally: for item in created_runs: self.client.delete_run(item)
def test_c4057_add_run(self): run = Run(name="A Test Run", description="This is a test run", include_all=True) created = self.client.add_run(run, self.project.id) assert created.name == run.name assert created.description == run.description assert created.include_all assert not created.is_completed assert created.project_id == self.project.id assert created.passed_count == 0 assert created.retest_count == 0 assert created.blocked_count == 0 assert created.failed_count == 0 assert created.untested_count == 3
def test_c4073_add_result(self): case_id = self.cases[0].id original_run = Run(name="A Test Run", case_ids=[case_id], include_all=False) created_run = self.client.add_run(original_run, self.project.id) tests = self.client.get_tests(created_run.id) assert len(tests) == 1 test_id = tests[0].id result = Result(status_id=Statuses.passed, elapsed="1m 45s") created = self.client.add_result(result, test_id) assert created.elapsed == result.elapsed assert created.status_id == Statuses.passed assert created.test_id == test_id
def test_c4074_add_result_for_case(self): case_id = self.cases[1].id original_run = Run(name="A Test Run", include_all=True) created_run = self.client.add_run(original_run, self.project.id) result = Result(status_id=Statuses.failed, elapsed="1m 45s") created_result = self.client.add_result_for_case(result, created_run.id, case_id) assert created_result.status_id == Statuses.failed assert created_result.elapsed == result.elapsed test_id = created_result.test_id test = self.client.get_test(test_id) assert test.case_id == case_id assert test.status_id == Statuses.failed
def test_c4075_add_results(self): original_run = Run(name="A Test Run", include_all=True) created_run = self.client.add_run(original_run, self.project.id) tests = self.client.get_tests(created_run.id) results = [] statuses = [Statuses.passed, Statuses.failed, Statuses.blocked] expected_results = {} for status, test in zip(statuses, tests): results.append(Result(status_id=status, test_id=test.id)) expected_results[test.id] = status created_results = self.client.add_results(results, created_run.id) assert len(created_results) == len(results) assert {result.test_id: result.status_id for result in created_results} == expected_results
def test_c9363_get_runs_limit_out_of_range(self, params, result): created_runs = [] try: for item in range(10): run = Run(name=f"Test Run {item}") resp = self.client.add_run(run, self.project.id) created_runs.append(resp) with pytest.raises(APIError) as e_info: self.client.get_runs(self.project.id, **params) error = e_info.value assert error.status_code == result[0] assert error.error == result[1] finally: for item in created_runs: self.client.delete_run(item)
def test_c9365_get_runs_with_offset(self, params, result): created_runs = [] try: for item in range(5): run = Run(name=f"Test Run {item}") resp = self.client.add_run(run, self.project.id) created_runs.append(resp) runs_len = len(self.client.get_runs(self.project.id)) runs_with_params = self.client.get_runs(self.project.id, **params) result[1] = runs_len - int(params['offset']) assert result[0] in runs_with_params[0].name assert len(runs_with_params) == result[1] finally: for item in created_runs: self.client.delete_run(item)
def test_c4070_update_run(self): original = Run(name="A Test Run", description="This is a test run", include_all=True) created = self.client.add_run(original, self.project.id) milestone = Milestone(name="A New Milestone", description="This is a description of a milestone") milestone = self.client.add_milestone(milestone, self.project.id) created.name = "A New Name" created.description = "A different description" created.milestone_id = milestone.id created.include_all = False created.case_ids = [case.id for case in self.cases][:2] run = self.client.update_run(created) assert run.name == created.name assert run.description == created.description assert run.milestone_id == created.milestone_id assert not run.include_all assert run.untested_count == 2
def prepare_test_case(cls): cls.projects_created = [] # add project added_project = Project(name="New Project", announcement="Some announcement", show_announcement=False, suite_mode=1) project_created = cls.client.add_project(added_project) cls.projects_created.append(project_created) cls.project_new = project_created # add Section section = Section(name="Test Section") section_created = cls.client.add_section(section, project_created.id) cls.section = section_created # add test case case = Case(title="Test Case") cls.case = cls.client.add_case(case, section_created.id) # add test Run run = Run(name="Test Run") cls.run = cls.client.add_run(run, project_created.id)
def test_c4079_get_results_for_run(self): original_run = Run(name="A Test Run", include_all=True) created_run = self.client.add_run(original_run, self.project.id) statuses = [Statuses.retest, Statuses.failed, Statuses.retest, Statuses.passed] original_results = [] expected_results = {} counter = 0 for status in statuses: for case in self.cases: comment = f"Result number {counter}" counter += 1 result = Result(status_id=status, comment=comment, case_id=case.id) original_results.append(result) expected_results[comment] = result self.client.add_results_for_cases(original_results, created_run.id) results = self.client.get_results_for_run(created_run.id) assert len(results) == len(expected_results) for result in results: expected = expected_results.pop(result.comment) assert result.status_id == expected.status_id assert result.comment == expected.comment
def add_run(self, run, project_id): response = self.client.send_post('add_run/{}'.format(project_id), run) return Run(**response)
def get_runs(self, project_id, **kwargs): response = self.client.send_get(f'get_runs/{project_id}', params=kwargs) return [Run(**args) for args in response]
def update_run(self, run): response = self.client.send_post(f'update_run/{run.id}', run) return Run(**response)
def close_run(self, run): response = self.client.send_post('close_run/{}'.format(run.id)) return Run(**response)
def get_run(self, run_id): response = self.client.send_get(f'get_run/{run_id}') return Run(**response)