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 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 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 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_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 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 tearDownClass(cls): doc = Document(project_id=DEFAULT_PROJ, doc_with_space="Testing/" + DOC_NAME) doc.delete()
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)
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 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_002_get_documents(self): lst_doc = Document.get_documents(Document.default_project, "Testing") doc = lst_doc[0] self.assertIsInstance(doc, Document)
def setUpClass(cls): cls.doc_create = Document.create(Document.default_project, "Testing", DOC_NAME, "Document_Test", ["testcase"], "testspecification")