def list_workitems_in_doc(self, doc_name_with_space): if doc_name_with_space.find('/') < 0: print("Document format should be: 'space/document'") exit(1) doc = Document(Document.default_project, doc_name_with_space) fields = [ 'work_item_id', 'author', 'title', 'type', 'status', 'assignee', 'categories', 'comments', 'created', 'approvals', 'updated' ] self.workitem_list = doc.get_work_items(None, True, fields) return self.workitem_list
def list_workitems_in_doc(self, doc_name_with_space): doc = Document(Document.default_project, doc_name_with_space) fields = ['work_item_id', 'author', 'title', 'type', 'status', 'assignee', 'categories', 'comments', 'created', 'approvals', 'updated'] self.workitem_list = doc.get_work_items(None, True, fields) return self.workitem_list
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 list_documents_by_query(self, query): fields = [ 'document_id', 'document_name', 'author', 'created', 'updated', 'updated_by' ] doc_list = Document.query(query, False, fields) return doc_list
def test_basic(self): self.assertEqual(self.doc.title, "Attribute_Test") self.doc.title = "new title" self.assertEqual(self.doc.title, "new title") self.doc.update() doc2 = Document(project_id=DEFAULT_PROJ, doc_with_space="Testing/" + DOC_NAME) self.assertEqual(doc2.title, "new title")
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 set_document(project, document_name): # DOC need be created before running the script try: document = Document(project, document_name, None, None, None) except PylarionLibException: print( red("Error: Can't not open \"KernelNetworkQE/KN-TC Kernel NIC Driver New Test Cases\" " "to move new case into it.\n Please create it in polarion.\n")) raise else: return document
def list_all_documents_under_space(self, fields=None): fields = ['document_id', 'document_name', 'author', 'created', 'updated', 'updated_by'] doc_list = Document.get_documents(Document.default_project, self.space, fields) return doc_list
def load_polarion(project, spaces): """ Load all Manual cases with given project and spave, return a dictionary, keys are workitem id, values are dicts presenting workitem attributes. """ # If called as a celery task... direct_call = current_task.request.id is None utc = pytz.UTC def flatten_cases(docs): all_cases = {} for doc_id, doc in docs.items(): for wi_id, wi in doc['work_items'].items(): wi_entry = all_cases.setdefault(wi_id, wi) wi_entry.setdefault('documents', []).append(doc_id) return all_cases doc_dict = {} for space in spaces: docs = Document.get_documents( project, space, fields=['document_id', 'title', 'type', 'updated', 'project_id']) for doc_idx, doc in enumerate(docs): if not direct_call: current_task.update_state(state='Fetching documents', meta={ 'current': doc_idx, 'total': len(docs) }) obj_doc = OrderedDict([ ('title', literal(doc.title)), ('type', literal(doc.type)), ('project', project), ('work_items', OrderedDict()), ('updated', utc.localize(doc.updated)), ]) wis = doc.get_work_items( None, True, fields=['work_item_id', 'type', 'title', 'updated']) for wi_idx, wi in enumerate(wis): obj_wi = OrderedDict([ ('title', literal(wi.title)), ('type', literal(wi.type)), ('project', project), ('updated', utc.localize(wi.updated)), ]) obj_doc['work_items'][literal(wi.work_item_id)] = obj_wi doc_dict[literal(doc.document_id)] = obj_doc cases = flatten_cases(doc_dict) return cases
def list_documents_by_query(self, query, is_sql=False, fields=None): fields = ['document_id', 'document_name', 'author', 'created', 'updated', 'updated_by'] doc_list = Document.query(query, is_sql, fields) return doc_list
def load_polarion(project, spaces): """ Load all Manual cases with given project and spave, return a dictionary, keys are workitem id, values are dicts presenting workitem attributes. """ # If called as a celery task... direct_call = current_task.request.id is None utc = pytz.UTC def flatten_cases(docs): all_cases = {} for doc_id, doc in docs.items(): for wi_id, wi in doc['work_items'].items(): wi_entry = all_cases.setdefault(wi_id, wi) wi_entry.setdefault('documents', []).append(doc_id) return all_cases doc_dict = {} for space in spaces: docs = Document.get_documents( project, space, fields=['document_id', 'title', 'type', 'updated', 'project_id']) for doc_idx, doc in enumerate(docs): if not direct_call: current_task.update_state(state='Fetching documents', meta={'current': doc_idx, 'total': len(docs)}) obj_doc = OrderedDict([ ('title', literal(doc.title)), ('type', literal(doc.type)), ('project', project), ('work_items', OrderedDict()), ('updated', utc.localize(doc.updated)), ]) wis = doc.get_work_items(None, True, fields=['work_item_id', 'type', 'title', 'updated']) for wi_idx, wi in enumerate(wis): obj_wi = OrderedDict([ ('title', literal(wi.title)), ('type', literal(wi.type)), ('project', project), ('updated', utc.localize(wi.updated)), ]) obj_doc['work_items'][literal(wi.work_item_id)] = obj_wi doc_dict[literal(doc.document_id)] = obj_doc cases = flatten_cases(doc_dict) return cases
def all_documents(project, spaces): """ Load all documents, return list """ utc = pytz.UTC for idx, space in enumerate(spaces): docs = Document.get_documents( project, space, fields=['document_id', 'title', 'type', 'updated', 'project_id']) for doc in docs: yield { 'space': space, 'title': literal(doc.title), 'type': literal(doc.type), 'id': literal(doc.document_id), 'project': project, 'updated': utc.localize(doc.updated or datetime.datetime.now()), 'workitems': doc.get_work_items(None, True, fields=['work_item_id', 'type', 'title', 'updated']) }
def update_document(self, space, doc_name, doc_title, wi_types=None, doc_type=None, structure_link_role="parent", content=''): cl = CmdList() if cl.list_documents_by_query(doc_name): print("Exit - Found same name '%s/%s'" % (space, doc_name)) return file_path = "" # the content could be file or data if os.path.exists(content): file_path = content with open(content, mode='r') as check_file: content = check_file.read() doc = Document.create(Document.default_project, space, doc_name, doc_title, wi_types, doc_type, structure_link_role, content) if cl.list_documents_by_query(doc_name): print("Created document '%s/%s'" % (space, doc_name)) print(" - document author : %s" % doc.author) print(" - document type : %s" % doc.type) print(" - allowed workitem type: %s" % wi_types) print(" - created date : %s" % doc.created) if file_path != "": print(" - document content is from: %s" % file_path) else: print(" - document content : %s" % content) return True else: print("Failed to create document '%s/%s'" % (space, doc_name)) return False
def test_004_get_name(self): self.doc_get1 = Document(project_id=Document.default_project, doc_with_space="Testing/" + DOC_NAME) self.assertIsInstance(self.doc_get1, Document)
def tearDownClass(cls): doc = Document(project_id=DEFAULT_PROJ, doc_with_space="Testing/" + DOC_NAME) doc.delete()
def setUpClass(cls): cls.doc_create = Document.create( Document.default_project, "Testing", DOC_NAME, "Document_Test", ["testcase"], "testspecification")
def test_002_get_documents(self): lst_doc = Document.get_documents(Document.default_project, "Testing") doc = lst_doc[0] self.assertIsInstance(doc, Document)
def test_003_query(self): lst_doc = Document.query("project.id:" + Document.default_project, limit=10) doc = lst_doc[0] self.assertIsInstance(doc, Document)
def test_007_update(self): doc = Document(uri=self.doc_create.uri) doc.status = "published" doc.update()
def test_005_get_uri(self): self.doc_get2 = Document(uri=self.doc_create.uri) self.assertIsInstance(self.doc_get2, Document)