def main(): client = traw.Client() # Credentials loaded through ENV vars # Get all priorities priorities = client.priorities() # Returns a models.Priority generator priority_1 = next(priorities) print(priority_1.name) # Low priority_2 = next(priorities) print(priority_2.name) # Medium priority_3 = next(priorities) print(priority_3.name) # High priority_4 = next(priorities) print(priority_4.name) # Critical # Given a priority ID, you can get the priority object priority_from_api = client.priority(1) print(priority_from_api.name) # Low # Since you cannot programatically add priorities through the API, # attempting to call `client.priority()` will raise an exception rather # than returning an empty/new Priority object try: client.priority() except NotImplementedError as exc: print( str(exc)) # Not implemented directly. You must pass in int object
def main(): client = traw.Client() # Credentials loaded through ENV vars # Get all available case types: case_types = client.case_types() # Returns a case_types generator case_type_1 = next(case_types) print(case_type_1.name) # Acceptance print(case_type_1.is_default) # False print(isinstance(case_type_1, traw.models.CaseType)) # True case_type_2 = next(case_types) print(case_type_2.name) # Accessibility print(case_type_2.is_default) # False print(isinstance(case_type_2, traw.models.CaseType)) # True # etc # Get a specific case type by case_type_id specific_case_type = client.case_type(7) # Corresponds to the `Other` CT print(specific_case_type.name) # Other print(specific_case_type.is_default) # True # Since you cannot programatically add Case Types through the API, # attempting to call `client.case_type()` will raise an exception rather # than returning an empty/new CaseType object try: client.case_type() except NotImplementedError as exc: print( str(exc)) # Not implemented directly. You must pass in int object
def main(): client = traw.Client() # Credentials loaded through ENV vars # Templates are retrieved by the project they are associated with automation_project = client.project(15) # Get all available templates: templates = client.templates( automation_project) # Returns a templates generator template_1 = next(templates) print(template_1.name) # Default Test Case print(template_1.is_default) # True print(isinstance(template_1, traw.models.Template)) # True template_2 = next(templates) print(template_2.name) # Automation Test Case print(template_2.is_default) # False print(isinstance(template_2, traw.models.Template)) # True # etc # Since you can only retrieve templates based on project, # attempting to call `client.templates()` will raise an exception try: client.templates() except NotImplementedError as exc: # Not implemented directly. You must pass in models.Project or int object print(str(exc))
def main(): client = traw.Client() # Credentials loaded through ENV vars # Get all Statuses statuses = client.statuses() # Returns a models.Status generator status_1 = next(statuses) print(status_1.name) # passed print(status_1.label) # Passed status_2 = next(statuses) print(status_2.name) # blocked print(status_2.label) # Blocked status_3 = next(statuses) print(status_3.name) # untested print(status_3.label) # Untested status_4 = next(statuses) print(status_4.name) # retest print(status_4.label) # Retest status_5 = next(statuses) print(status_5.name) # failed print(status_5.label) # Failed status_6 = next(statuses) print(status_6.name) # custom_status_auto_passed print(status_6.label) # Passed-Automation # etc # Given a status ID, you can get the status object failed_auto_st = client.status(7) print(failed_auto_st.name) # custom_status_auto_failed print(failed_auto_st.label) # Failed-Automation # Given a status label, you can get the status object # By default it ignores case blocked_auto_st = client.status('blocked-automation') print(blocked_auto_st.name) # custom_status_auto_blocked print(blocked_auto_st.label) # Blocked-Automation # You can specify strict casing if necessary: try: client.status('blocked-automation', strict=True) except TRAWClientError as exc: # Could not locate a models.Status with label of blocked-automation print(str(exc)) strict_status = client.status('Blocked-Automation', strict=True) print(strict_status.name) # custom_status_auto_blocked print(strict_status.label) # Blocked-Automation # Since you cannot programatically add statuses through the API, # attempting to call `client.status()` will raise an exception rather # than returning an empty/new Status object try: client.status() except NotImplementedError as exc: print( str(exc)) # Not implemented directly. You must pass in int object
def main(): client = traw.Client() # Credentials loaded through ENV vars # Locate the project you will be adding milestones to project = client.project(15) # Create the parent milestone new_parent_ms = client.milestone() # Creates a new, empty milestone object new_parent_ms.name = "{0}'s Yearly Test Results".format(project.name) new_parent_ms.description = "{0}'s testing results for the year".format( project.name) new_parent_ms.start_on = dt(year=2018, month=1, day=1) # Start on 2018/01/01 new_parent_ms.due_on = dt(year=2018, month=12, day=31) # Due on 2018/12/31 # Associate this milestone with a project new_parent_ms.project = project # Add the new milestone to TestRail, replacing it with the Milestone returned # from the TestRail API. parent_ms = client.add(new_parent_ms) assert isinstance(parent_ms, traw.models.Milestone) # Create a sub milestone for the first quarter of 2018 new_sub_ms = client.milestone() # Creates a new, empty milestone object new_sub_ms.name = "{0}'s 1st Quarter Test Results".format(project.name) new_sub_ms.description = "{0}'s testing results for the first quarter".format( project.name) new_sub_ms.start_on = dt(year=2018, month=1, day=1) # Start on 2018/01/01 new_sub_ms.due_on = dt(year=2018, month=3, day=31) # Due on 2018/03/31 # Associate this milestone with a project new_sub_ms.project = project # Add the parent milestone, transforming this into a sub_milestone object new_sub_ms = new_sub_ms.add_parent(parent_ms) # Add the new milestone to TestRail, replacing it with the Milestone returned # from the TestRail API. sub_ms = client.add(new_sub_ms) assert isinstance(sub_ms, traw.models.SubMilestone) # The sub_ms's parent should match the one we created assert sub_ms.parent.id == parent_ms.id
def main(): client = traw.Client() # Credentials loaded through ENV vars # Tests are retrieved by the run they are associated with # Get an example run using the Run ID auto_run = client.run(72215) # Get all tests for this run: tests = list(client.tests(auto_run)) # Expand the generator to a list print(len(tests)) # 40 tests test_1 = tests[0] print(test_1.title) # Example Test Case Title print(test_1.status.label) # Passed test_2 = tests[1] print(test_2.title) # Example Test Case Title #2 print(test_2.status.label) # Failed # Get all tests with a status of `Failed` or 'Retest' failed_status = client.status('failed') retest_status = client.status('retest') failed_and_retest = list(client.tests(auto_run, with_status=[failed_status, retest_status])) print(len(failed_and_retest)) # 10 # Get a test from its test id example_test = client.test(5792090) print(example_test.id) # 5792090 print(example_test.status.label) # Failed print(example_test.type.name) # Regression print(example_test.priority.name) # Medium print(example_test.estimate) # datetime.timedelta object -> datetime.timedelta(0, 4200) print(list(example_test.refs)) # ['REF001', 'REF002'] # Since you cannot programatically add Tests through the API, # attempting to call `client.test()` will raise an exception rather # than returning an empty/new Test object try: client.test() except NotImplementedError as exc: # Not implemented directly. You must pass in int object print(str(exc))
def main(): client = traw.Client() # Credentials loaded through ENV vars # Create a new project object new_project = client.project() new_project.name = "ACME Contract Testing" new_project.announcement = "For testing associated with the Acme Contract" new_project.show_announcement = True new_project.suite_mode = 1 # Single Suite mode # Add the project to testrail, replacing it with the Milestone returned # from the TestRail API. active_project = client.add(new_project) project_id = active_project.id # Verify some parameters assert active_project.name == "ACME Contract Testing" assert active_project.announcement == "For testing associated with the Acme Contract" assert active_project.is_completed is False # Lets say the project is now complete. # Update the name, announcement, and completion status active_project.name = "ACME Contract Testing - Complete" active_project.announcement = ( "For testing associated with the Acme Contract," "completed 2018/01/02") active_project.is_completed = True # POST the updated project to Testrail, replacing it with the Project returned # from the API closed_project = client.update(active_project) assert closed_project.name == "ACME Contract Testing - Complete" assert closed_project.announcement == ( "For testing associated with the Acme Contract," "completed 2018/01/02") assert closed_project.is_completed is True # Lets say its now a few years later, and we want to remove this old project # NOTE: your user must have admin privs to delete a project old_project = client.project(project_id) client.delete(old_project)
def full_client(): with mock.patch('traw.api.Session') as sess_mock: sess_mock.return_value = sess_mock yield traw.Client(username=USER, password=PASS, url=URL)
def client(): with mock.patch('traw.client.API') as api_mock: api_mock.return_value = api_mock yield traw.Client(username=USER, password=PASS, url=URL)
def main(): client = traw.Client() # Credentials loaded through ENV vars # TestRail returns config groups based on project, with each config group # containing specific configs. To get a config group, you must first get # the corresponding project by project ID: automation_project = client.project(15) # Get all config groups for our project. This method returns a generator, so # Use `list` to get a complete list of config groups config_groups = list(client.config_groups(automation_project)) print(len(config_groups)) # 1 config_group = config_groups[0] print(str(config_group)) # ConfigGroup-4 print(config_group.name) # 'Supported Browsers' print(config_group.project) # Project-15 print(len(list(config_group.configs))) # 2 configs # Get/examine configs for each config group configs = config_groups[0].configs config_1 = next(configs) print(config_1.name) # Chrome print(config_1.config_group) # ConfigGroup-4, a reference back to the CG print(config_1.project) # Project-15, a reference back to the project config_2 = next(configs) print(config_2.name) # Firefox print(config_2.config_group) # ConfigGroup-4, a reference back to the CG print(config_2.project) # Project-15, a reference back to the project # You can retrieve a ConfigGroup using project + config group ID print(client.config_group(automation_project, 4)) # ConfigGroup-4 # You can create new config groups and configs and add them to TestRail new_config_group = client.config_group() # Returns a new/empty config group # Set the name and associate it with a project new_config_group.name = "Supported Operating Systems" new_config_group.project = automation_project # Add the new config group to TestRail, and collect the returned object created_config_group = client.add(new_config_group) # Note that the returned config group matches the one you added and now has # and ID, but no associated configs print(created_config_group.name == new_config_group.name) # True print(created_config_group.id) # 5 print(list(created_config_group.configs)) # [] # Create new configs, associate them with a config group, and add them to TR new_config_1 = client.config() new_config_1.name = "Windows" new_config_1.config_group = created_config_group created_config_1 = client.add(new_config_1) print(created_config_1) # Windows new_config_2 = client.config() new_config_2.name = "Linux" new_config_2.config_group = created_config_group created_config_2 = client.add(new_config_2) print(created_config_2) # Linux new_config_3 = client.config() new_config_3.name = "mac OS" new_config_3.config_group = created_config_group created_config_3 = client.add(new_config_3) print(created_config_3) # mac OS # Re-acquire the config group from the TestRail API updated_config_group = client.config_group(created_config_group.project, created_config_group.id) # Note that it now has three configs: cg_configs = list(updated_config_group.configs) print(cg_configs) # [Config-25, Config-26, Config-24] print(cg_configs[0].name) # Linux print(cg_configs[1].name) # mac OS print(cg_configs[2].name) # Windows # Should you need to update a config group or config to_be_updated_config = cg_configs[0] to_be_updated_config.name = "Linux: Ubuntu" # From 'Linux' to 'Linux: Ubuntu' updated_config = client.update(to_be_updated_config) print(updated_config.name) # 'Linux: Ubuntu' # Re-acquire the config group from the TestRail API updated_config_group = client.config_group(updated_config_group.project, updated_config_group.id) cg_configs = updated_config_group.configs print(next(cg_configs).name) # Linux: Ubuntu print(next(cg_configs).name) # mac OS print(next(cg_configs).name) # Windows # Finally, should you want to delete a config/config group client.delete(updated_config_group) # And it is no longer in TestRail try: client.config_group(updated_config_group.project, updated_config_group.id) except TRAWClientError as exc: # Could not locate a models.ConfigGroup with id of 4 for project with ID 15 print(str(exc))