def update_run(self, updated_run: Run) -> Run: """http://docs.gurock.com/testrail-api2/reference-runs#update_run""" update_run_data = updated_run.to_json(include_none=False) run_data = self._request( f'update_run/{updated_run.id}', method='POST', data=update_run_data, ) return Run.from_json(data_json=run_data)
def test_add_run_raises(testrail_client, mocked_response): expected_run = Run(id=1, project_id=1, name='Test Run', include_all=False, case_ids=[1, 2, 3]) mocked_response(data_json=expected_run.to_json()) with pytest.raises(TestRailException): testrail_client.runs.add_run(run=expected_run)
def test_close_run(testrail_client, mocked_response): expected_run = Run(id=1, project_id=1, name='Test Run', include_all=False, case_ids=[1, 2, 3]) mocked_response(data_json=expected_run.to_json()) api_run = testrail_client.runs.close_run(run_id=1) assert api_run == expected_run
def add_run(self, run: Run, project_id: typing.Optional[ModelID] = None) -> Run: """http://docs.gurock.com/testrail-api2/reference-runs#add_run""" project_id = project_id or self._project_id if project_id is None: raise TestRailException('Provide project id') new_run_data = run.to_json(include_none=False) run_data = self._request(f'add_run/{project_id}', method='POST', data=new_run_data) return Run.from_json(data_json=run_data)
def test_run_from_json_with_unexpected_key(run_data): data_with_extra_key = dict(run_data) data_with_extra_key['some_random_key'] = 'Some random value' run = Run.from_json(data_json=data_with_extra_key) assert run.to_json() == run_data
def test_run_from_json(run_data): run = Run.from_json(data_json=run_data) assert run.assignedto_id == 6 assert run.blocked_count == 0 assert run.completed_on is None assert run.config == 'Firefox, Ubuntu 12' assert run.config_ids == [2, 6] assert run.case_ids is None assert run.created_by == 1 assert run.created_on == 1393845644 assert run.refs == 'SAN-1' assert run.custom['custom_status1_count'] == 0 assert run.custom['custom_status2_count'] == 0 assert run.custom['custom_status3_count'] == 0 assert run.custom['custom_status4_count'] == 0 assert run.custom['custom_status5_count'] == 0 assert run.custom['custom_status6_count'] == 0 assert run.custom['custom_status7_count'] == 0 assert run.description is None assert run.failed_count == 2 assert run.id == 81 assert run.include_all is False assert run.is_completed is False assert run.milestone_id == 7 assert run.name == 'File Formats' assert run.passed_count == 2 assert run.plan_id == 80 assert run.project_id == 1 assert run.retest_count == 1 assert run.suite_id == 4 assert run.untested_count == 3 assert run.url == 'http://<server>/testrail/index.php?/runs/view/81'
def get_runs( self, project_id: typing.Optional[ModelID] = None) -> typing.List[Run]: """http://docs.gurock.com/testrail-api2/reference-runs#get_runs""" project_id = project_id or self._project_id if project_id is None: raise TestRailException('Provide project id') runs_data = self._request(f'get_runs/{project_id}') return [Run.from_json(data_json=run_data) for run_data in runs_data]
def test_run_to_json(run_data): run = Run.from_json(data_json=run_data) assert run.to_json() == run_data
def close_run(self, run_id: ModelID) -> Run: """http://docs.gurock.com/testrail-api2/reference-runs#close_run""" run_data = self._request(f'close_run/{run_id}', method='POST') return Run.from_json(data_json=run_data)
def get_run(self, run_id: ModelID) -> Run: """http://docs.gurock.com/testrail-api2/reference-runs#get_run""" run_data = self._request(f'get_run/{run_id}') return Run.from_json(data_json=run_data)
def run(run_data): return Run.from_json(data_json=run_data)