def setUpClass(cls): tc1 = TestCase.create(DEFAULT_PROJ, "regression", "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") cls.NEW_TEST_CASE = tc1.work_item_id tc2 = TestCase.create(DEFAULT_PROJ, "regression", "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") cls.NEW_TEST_CASE2 = tc2.work_item_id Plan.create(plan_id=PLAN_ID, plan_name="regression", project_id=DEFAULT_PROJ, parent_id=None, template_id="release") cls.NEW_PLAN = PLAN_ID
def test_009_dynamic_records(self): """This test does the following: * creates a TestCase * creates a TestRun based on the Example template (Dynamic query) * verifies that it is a dynamic query * updates an test record. * reloads * verifies that the record has been added """ TestCase.create(DEFAULT_PROJ, TIME_STAMP, "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") tr = TestRun.create("proj1", "querytest-%s" % TIME_STAMP, "Example", "querytest-%s" % TIME_STAMP, query=TIME_STAMP) self.assertEquals(tr.select_test_cases_by, "dynamicQueryResult") num_recs = len(tr.records) test_case_id = tr.records[0].test_case_id tr.update_test_record_by_fields(test_case_id, "blocked", "comment", tr.logged_in_user_id, datetime.datetime.now(), 0) tr.reload() self.assertEquals(num_recs, len(tr.records)) self.assertEquals(test_case_id, tr.records[0].test_case_id) self.assertEquals(tr.records[0].result, "blocked")
def setUpClass(cls): global TEST_RUN_ID cls.doc = Document.create(DEFAULT_PROJ, "Testing", DOC_NAME, "Attribute_Test", ["testcase"], "testspecification") cls.testrun = TestRun.create(DEFAULT_PROJ, TEST_RUN_ID, "example", TEST_RUN_TITLE) TEST_RUN_ID = cls.testrun.test_run_id # arch is a custom field defined by global admins for test runs. # It is set here for a test on custom fields that requires at least two # valid values. If in the future, this custom field is removed, or the # number of valid values is lowered to 1, a different custom field will # have to be used. valid_values = cls.testrun.get_valid_field_values("arch") cls.testrun.arch = valid_values[1] cls.testrun.update() cls.tc = TestCase.create(DEFAULT_PROJ, "regression", "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") cls.TEST_CASE_ID = cls.tc.work_item_id
def setUpClass(cls): tc = TestCase.create(DEFAULT_PROJ, "regression", "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") req = Requirement.create(DEFAULT_PROJ, "regression _link", "regression link", reqtype="functional", severity="should_have") cls.work_item_id = tc.work_item_id cls.work_item_uri = tc.uri cls.work_item_id_2 = req.work_item_id cls.work_item_uri_2 = req.uri
def create_new_case(prefix, case_name, topo, document, project): """create new case through the name and topo of case""" print(green("Create New Testcase NAME:%s, TOPO:%s" % (case_name, topo))) if topo == "": case_title = "{}: {}".format(prefix, case_name) else: case_title = "{}: {} FUNC={}".format(prefix, case_name, topo) try: case_item = TestCase.create(project, title=case_title, desc="", caseimportance="high", caseautomation="automated", caseposneg="positive", caselevel="component", testtype="functional", subtype1="-") document.move_work_item_here(case_item.work_item_id, None) except: return create_new_case(prefix, case_name, topo, document, project) return case_item.work_item_id
def add_test_case(args): """Task that creates or updates Test Cases and manages their Requirement. This task relies on ``OBJ_CACHE`` to get the collect_only and project objects. :param args: A tuple where the first element is a path and the second is a list of ``TestFunction`` objects mapping the tests from that path. """ path, tests = args collect_only = OBJ_CACHE['collect_only'] project = OBJ_CACHE['project'] for test in tests: # Fetch the test case id if the @Id tag is present otherwise generate a # test_case_id based on the test Python import path test_case_id = test.tokens.get('id', generate_test_id(test)) if test.docstring: if not type(test.docstring) == unicode: test.docstring = test.docstring.decode('utf8') # Is the test automated? Acceptable values are: # automated, manualonly, and notautomated auto_status = test.tokens.get( 'caseautomation', 'notautomated' if test.tokens.get('status') else 'automated' ).lower() caseposneg = test.tokens.get( 'caseposneg', 'negative' if 'negative' in test.name else 'positive' ).lower() subtype1 = test.tokens.get( 'subtype1', '-' ).lower() casecomponent = test.tokens.get('casecomponent', '-').lower() caseimportance = test.tokens.get( 'caseimportance', 'medium').lower() caselevel = test.tokens.get('caselevel', 'component').lower() description = test.tokens.get( 'description', test.docstring if test.docstring else '') description = RST_PARSER.parse(description) setup = test.tokens.get('setup') status = test.tokens.get('status', 'approved').lower() testtype = test.tokens.get( 'testtype', 'functional' ).lower() title = test.tokens.get('title', test.name) upstream = test.tokens.get('upstream', 'no').lower() steps = test.tokens.get('steps') expectedresults = test.tokens.get('expectedresults') if steps and expectedresults: test_steps = generate_test_steps( map_steps(steps, expectedresults)) else: test_steps = None results = [] if not collect_only: results = TestCase.query( test_case_id, fields=[ 'caseautomation', 'caseposneg', 'description', 'work_item_id' ] ) requirement_name = test.tokens.get( 'requirement', parse_requirement_name(path)) if len(results) == 0: click.echo( 'Creating test case {0} for requirement: {1}.' .format(title, requirement_name) ) if not collect_only: test_case = TestCase.create( project, title, description, caseautomation=auto_status, casecomponent=casecomponent, caseimportance=caseimportance, caselevel=caselevel, caseposneg=caseposneg, setup=setup, subtype1=subtype1, test_case_id=test_case_id, testtype=testtype, upstream=upstream, ) test_case.status = status if test_steps: test_case.test_steps = test_steps test_case.update() click.echo( 'Linking test case {0} to requirement: {1}.' .format(title, requirement_name) ) if not collect_only: requirement = fetch_requirement( requirement_name, project, collect_only) test_case.add_linked_item( requirement.work_item_id, 'verifies') else: click.echo( 'Updating test case {0} for requirement {1}.' .format(title, 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 any(( test_case.caseautomation != auto_status, test_case.casecomponent != casecomponent, test_case.caseimportance != caseimportance, test_case.caselevel != caselevel, test_case.caseposneg != caseposneg, test_case.description != description, test_case.setup != setup, test_case.status != status, test_case.subtype1 != subtype1, test_case.test_steps != test_steps, test_case.testtype != testtype, test_case.title != title, test_case.upstream != upstream, )): test_case.caseautomation = auto_status test_case.casecomponent = casecomponent test_case.caseimportance = caseimportance test_case.caselevel = caselevel test_case.caseposneg = caseposneg test_case.description = description test_case.setup = setup test_case.status = status test_case.subtype1 = subtype1 test_case.testtype = testtype test_case.title = title test_case.upstream = upstream if test_steps: test_case.test_steps = test_steps test_case.update()
def add_test_case(args): """Task that creates or updates Test Cases and manages their Requirement. This task relies on ``OBJ_CACHE`` to get the collect_only and project objects. :param args: A tuple where the first element is a path and the second is a list of ``TestFunction`` objects mapping the tests from that path. """ path, tests = args collect_only = OBJ_CACHE['collect_only'] project = OBJ_CACHE['project'] # Fetch or create a Requirement requirement = None requirement_name = parse_requirement_name(path) click.echo( 'Fetching requirement {0}.'.format(requirement_name)) if not collect_only: 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' ) for test in tests: # Generate the test_case_id. It could be either path.test_name or # path.ClassName.test_name if the test methods is defined within a # class. 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 test.docstring: if not type(test.docstring) == unicode: test.docstring = test.docstring.decode('utf8') test.docstring = RST_PARSER.parse(test.docstring) # Is the test automated? Acceptable values are: # automated, manualonly, and notautomated auto_status = 'automated' if test.automated else 'notautomated' caseposneg = 'negative' if 'negative' in test.name else 'positive' setup = test.setup if test.setup else None results = [] if not collect_only: results = TestCase.query( test_case_id, fields=[ 'caseautomation', 'caseposneg', '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=auto_status, casecomponent='-', caseimportance='medium', caselevel='component', caseposneg=caseposneg, subtype1='-', test_case_id=test_case_id, testtype='functional', setup=setup, ) click.echo( 'Linking 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 or test_case.caseautomation != auto_status or test_case.caseposneg != caseposneg or test_case.setup != setup)): test_case.description = ( test.docstring if test.docstring else '') test_case.caseautomation = auto_status test_case.caseposneg = caseposneg test_case.setup = setup 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()
def create_polarion_tc(self): """ Given the pong.TestCase, convert it to the equivalent pylarion.work_item.TestCase """ t = lambda x: unicode.encode(x, encoding="utf-8", errors="ignore") if isinstance(x, unicode) else x desc, title = [t(x) for x in [self.description, self.title]] # Check to see if we already have an existing test case tc = None if self.polarion_tc: log.info("Getting TestCase for {}: {}".format(title, desc)) tc = self.polarion_tc self.validate_test(tc) if not self.polarion_tc.title.startswith(self.prefix): self.polarion_tc.title = self.prefix + self.polarion_tc.title # See if the Polarion Test Case has steps. The TestCase will contain a TestSteps array of size 1 # The step will have 2 columns (or key-value pairs) # | step | expectedResult # +======+=============== # | args | PASS test_steps = tc.get_test_steps() steps = test_steps.steps # If this TestCase has more than 1 TestStep, it's the older workaround where a TestStep was a row # of data in the 2d array. Moving to the SR2 2015 release with parameterized testing instead if len(steps) > 1: tc.set_test_steps() # Empty the TestSteps if len(steps) == 0: step = self.make_polarion_test_step() tc.set_test_steps([step]) else: log.info("Generating new TestCase for {} : {}".format(title, desc)) WORKAROUND_949 = False try: self.description.decode(encoding="utf-8") except UnicodeError: raw = self.description.encode("utf-8") self.description = unicode(raw, encoding="utf-8", errors="replace") try: self.description.decode(encoding="utf-8") except UnicodeError: WORKAROUND_949 = True if WORKAROUND_949: self.description = unicode("", encoding="utf-8") from pylarion.work_item import TestCase as PylTestCase tc = PylTestCase.create(self.project, self.title, self.description, **TC_KEYS) # Create PylTestSteps if needed and add it if self.step_results: step = self.make_polarion_test_step() tc.set_test_steps([step]) if not tc: raise Exception("Could not create TestCase for {}".format(self.title)) else: self.polarion_tc = tc self.link_requirements(tc) self.polarion_tc.update() return tc
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 create_polarion_tc(self): """ Given the pong.TestCase, convert it to the equivalent pylarion.work_item.TestCase """ t = lambda x: unicode.encode(x, encoding="utf-8", errors="ignore" ) if isinstance(x, unicode) else x desc, title = [t(x) for x in [self.description, self.title]] # Check to see if we already have an existing test case tc = None if self.polarion_tc: log.info("Getting TestCase for {}: {}".format(title, desc)) tc = self.polarion_tc self.validate_test(tc) if not self.polarion_tc.title.startswith(self.prefix): self.polarion_tc.title = self.prefix + self.polarion_tc.title # See if the Polarion Test Case has steps. The TestCase will contain a TestSteps array of size 1 # The step will have 2 columns (or key-value pairs) # | step | expectedResult # +======+=============== # | args | PASS test_steps = tc.get_test_steps() steps = test_steps.steps # If this TestCase has more than 1 TestStep, it's the older workaround where a TestStep was a row # of data in the 2d array. Moving to the SR2 2015 release with parameterized testing instead if len(steps) > 1: tc.set_test_steps() # Empty the TestSteps if len(steps) == 0: step = self.make_polarion_test_step() tc.set_test_steps([step]) else: log.info("Generating new TestCase for {} : {}".format(title, desc)) WORKAROUND_949 = False try: self.description.decode(encoding="utf-8") except UnicodeError: raw = self.description.encode("utf-8") self.description = unicode(raw, encoding="utf-8", errors="replace") try: self.description.decode(encoding="utf-8") except UnicodeError: WORKAROUND_949 = True if WORKAROUND_949: self.description = unicode("", encoding="utf-8") from pylarion.work_item import TestCase as PylTestCase tc = PylTestCase.create(self.project, self.title, self.description, **TC_KEYS) # Create PylTestSteps if needed and add it if self.step_results: step = self.make_polarion_test_step() tc.set_test_steps([step]) if not tc: raise Exception("Could not create TestCase for {}".format( self.title)) else: self.polarion_tc = tc self.link_requirements(tc) self.polarion_tc.update() return tc
def add_test_case(args): """Task that creates or updates Test Cases and manages their Requirement. This task relies on ``OBJ_CACHE`` to get the collect_only and project objects. :param args: A tuple where the first element is a path and the second is a list of ``TestFunction`` objects mapping the tests from that path. """ path, tests = args collect_only = OBJ_CACHE['collect_only'] project = OBJ_CACHE['project'] for test in tests: # Fetch the test case id if the @Id tag is present otherwise generate a # test_case_id based on the test Python import path test_case_id = test.unexpected_tags.get('id') if not test_case_id: # Generate the test_case_id. It could be either path.test_name or # path.ClassName.test_name if the test methods is defined within a # class. 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 test.docstring: if not type(test.docstring) == unicode: test.docstring = test.docstring.decode('utf8') test.docstring = RST_PARSER.parse(test.docstring) # Is the test automated? Acceptable values are: # automated, manualonly, and notautomated auto_status = test.unexpected_tags.get( 'caseautomation', 'automated' if test.automated else 'notautomated' ).lower() caseposneg = test.unexpected_tags.get( 'caseposneg', 'negative' if 'negative' in test.name else 'positive' ).lower() subtype1 = test.unexpected_tags.get( 'subtype1', '-' ).lower() casecomponent = test.unexpected_tags.get('casecomponent', '-').lower() caseimportance = test.unexpected_tags.get( 'caseimportance', 'medium').lower() caselevel = test.unexpected_tags.get('caselevel', 'component').lower() setup = test.setup if test.setup else None status = test.unexpected_tags.get('status', 'approved').lower() testtype = test.unexpected_tags.get( 'testtype', 'functional' ).lower() upstream = test.unexpected_tags.get('upstream', 'no').lower() results = [] if not collect_only: results = TestCase.query( test_case_id, fields=[ 'caseautomation', 'caseposneg', 'description', 'work_item_id' ] ) requirement_name = test.unexpected_tags.get( 'requirement', parse_requirement_name(path)) 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=auto_status, casecomponent=casecomponent, caseimportance=caseimportance, caselevel=caselevel, caseposneg=caseposneg, subtype1=subtype1, test_case_id=test_case_id, testtype=testtype, setup=setup, upstream=upstream, ) test_case.status = status test_case.update() click.echo( 'Linking test case {0} to verify requirement {1}.' .format(test.name, requirement_name) ) if not collect_only: requirement = fetch_requirement( requirement_name, project, 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 any(( test_case.caseautomation != auto_status, test_case.casecomponent != casecomponent, test_case.caseimportance != caseimportance, test_case.caselevel != caselevel, test_case.caseposneg != caseposneg, test_case.description != test.docstring, test_case.setup != setup, test_case.subtype1 != subtype1, test_case.testtype != testtype, test_case.upstream != upstream, test_case.status != status, )): test_case.description = ( test.docstring if test.docstring else '') test_case.caseautomation = auto_status test_case.casecomponent = casecomponent test_case.caseimportance = caseimportance test_case.caselevel = caselevel test_case.caseposneg = caseposneg test_case.setup = setup test_case.status = status test_case.subtype1 = subtype1 test_case.testtype = testtype test_case.upstream = upstream test_case.update()