def test_006_create_work_item(self): tc = TestCase() tc.title = "regression" tc.description = "regression document test" tc.status = "draft" tc.caseimportance = "high" tc.caselevel = "component" tc.caseautomation = "notautomated" tc.caseposneg = "positive" tc.testtype = "functional" tc.subtype1 = "-" doc = Document(uri=self.doc_create.uri) wi = doc.create_work_item(None, tc) doc_wis = doc.get_work_items(None, True) doc_wi_ids = [doc_wi.work_item_id for doc_wi in doc_wis] self.assertIn(wi.work_item_id, doc_wi_ids) global WI_ID WI_ID = wi.work_item_id
def test_case(path, collect_only, project): """Sync test cases with Polarion.""" testcases = testimony.get_testcases([path]) for path, tests in testcases.items(): requirement = None for test in tests: # Expect test_case_id to be path.test_name or # path.ClassName.test_name. test_case_id_parts = [ path.replace('/', '.').replace('.py', ''), test.name ] if test.parent_class is not None: test_case_id_parts.insert(-1, test.parent_class) test_case_id = '.'.join(test_case_id_parts) if requirement is None: requirement_name = parse_requirement_name(test_case_id) results = Requirement.query('{0}'.format(requirement_name), fields=['title', 'work_item_id']) if len(results) > 0: # As currently is not possible to get a single # match for the title, make sure to not use a # not intended Requirement. for result in results: if result.title == requirement_name: requirement = result if requirement is None: click.echo( 'Creating requirement {0}.'.format(requirement_name)) if not collect_only: requirement = Requirement.create(project, requirement_name, '', reqtype='functional') results = TestCase.query(test_case_id, fields=['description', 'work_item_id']) if len(results) == 0: click.echo( 'Creating test case {0} for requirement {1}.'.format( test.name, requirement_name)) if not collect_only: test_case = TestCase.create( project, test.name, test.docstring if test.docstring else '', caseautomation='automated', casecomponent='-', caseimportance='medium', caselevel='component', caseposneg='positive', subtype1='-', test_case_id=test_case_id, testtype='functional', ) click.echo( 'Liking test case {0} to verify requirement {1}.'.format( test.name, requirement_name)) if not collect_only: test_case.add_linked_item(requirement.work_item_id, 'verifies') else: click.echo( 'Updating test case {0} for requirement {1}.'.format( test.name, requirement_name)) # Ensure that a single match for the Test Case is # returned. assert len(results) == 1 test_case = results[0] if (not collect_only and test_case.description != test.docstring): test_case = TestCase(project, test_case.work_item_id) test_case.description = (test.docstring if test.docstring else '') test_case.update()
def test_case(path, collect_only, project): """Sync test cases with Polarion.""" testcases = testimony.get_testcases([path]) for path, tests in testcases.items(): requirement = None for test in tests: # Expect test_case_id to be path.test_name or # path.ClassName.test_name. test_case_id_parts = [ path.replace('/', '.').replace('.py', ''), test.name ] if test.parent_class is not None: test_case_id_parts.insert(-1, test.parent_class) test_case_id = '.'.join(test_case_id_parts) if requirement is None: requirement_name = parse_requirement_name(test_case_id) results = Requirement.query( '{0}'.format(requirement_name), fields=['title', 'work_item_id'] ) if len(results) > 0: # As currently is not possible to get a single # match for the title, make sure to not use a # not intended Requirement. for result in results: if result.title == requirement_name: requirement = result if requirement is None: click.echo( 'Creating requirement {0}.'.format(requirement_name)) if not collect_only: requirement = Requirement.create( project, requirement_name, '', reqtype='functional' ) results = TestCase.query( test_case_id, fields=['description', 'work_item_id']) if len(results) == 0: click.echo( 'Creating test case {0} for requirement {1}.' .format(test.name, requirement_name) ) if not collect_only: test_case = TestCase.create( project, test.name, test.docstring if test.docstring else '', caseautomation='automated', casecomponent='-', caseimportance='medium', caselevel='component', caseposneg='positive', subtype1='-', test_case_id=test_case_id, testtype='functional', ) click.echo( 'Liking test case {0} to verify requirement {1}.' .format(test.name, requirement_name) ) if not collect_only: test_case.add_linked_item( requirement.work_item_id, 'verifies') else: click.echo( 'Updating test case {0} for requirement {1}.' .format(test.name, requirement_name) ) # Ensure that a single match for the Test Case is # returned. assert len(results) == 1 test_case = results[0] if (not collect_only and test_case.description != test.docstring): test_case = TestCase(project, test_case.work_item_id) test_case.description = ( test.docstring if test.docstring else '') test_case.update()