# Test_P4JIRA.py # Test harness for P4DTG from __future__ import print_function #---Imports import time import os from ConfigParser import ConfigParser from ctypes import * import DTG import unittest CONFIG_FILE = 'p4dtg.ini' #------------------- class DTG_base(unittest.TestCase): def setUp(self): currdir = os.path.dirname(os.path.abspath(__file__)) os.chdir(os.path.join(currdir, '..')) config_file = os.path.join(currdir, CONFIG_FILE) config = ConfigParser() try: config.read(config_file) except Exception as e: raise Exception("Failed to read config file: %s - %s" % ( config_file, e.message)) section = 'JIRA' if section not in config.sections(): raise Exception("Missing required section '%s' in config file" % section) self.server = config.get(section, "server") self.user = config.get(section, "user") self.password = config.get(section, "password") self.dtg = DTG.DTG("plugins/jiradtg.dll") print("get_name: %s" % self.dtg.get_name()) def runTest(self): print("Asking for attributes") attrs = self.dtg.list_attrs() for a in attrs: print(a) server = DTG.DTGServer(self.dtg) server.connect(self.server, self.user, self.password, None) print("get_server_version: ", server.get_server_version()) server_date = server.get_server_date() print("dt_get_server_date: %d/%02d/%02d %02d:%02d:%02d" % (server_date.contents.year, server_date.contents.month, server_date.contents.day, server_date.contents.hour, server_date.contents.minute, server_date.contents.second)) projects = server.list_projects() print("Projects: '%s'" % str(projects)) project = server.get_project("PROJONE") fields = project.list_fields() print("Fields for project %s:\n%s" % ("PROJONE", "\n".join([str(f) for f in fields]))) mod_date_field = "" for f in fields: if f.readonly == 2: mod_date_field = f.name print("Date modified field: %s" % mod_date_field) since = DTG.DTGDate() since.year = 2014 since.month = 1 since.day = 1 since.hour = 0 since.minute = 0 since.second = 0 defect_ids = project.list_changed_defects(byref(since), mod_date_field=mod_date_field, mod_by_field="*Not Supported*", exclude_user="p4dtg") print("Defect IDs for %s: '%s'" % (str(since), str(defect_ids))) if defect_ids: print("\nIssue fields:") defect = None defect = project.get_defect(defect_ids[1]) field_names = [x.name for x in fields] values = {} for f in field_names: value = defect.get_field(f) values[f] = value print("Field %s: %s" % (f, value)) print("\nUpdating:") fname = "P4Job" new_value = "job000123" # if values[fname]: # new_value = values[fname] + new_value defect.set_field(fname, new_value) result = defect.save() print("\nIssue fields:") defect = None defect = project.get_defect(defect_ids[1]) field_names = [x.name for x in fields] values = {} for f in field_names: value = defect.get_field(f) values[f] = value print("Field %s: %s" % (f, value)) if __name__ == "__main__": unittest.main()