Skip to content

Commit

Permalink
Merge pull request #183 from gpongelli/long_attributes
Browse files Browse the repository at this point in the history
feat: use a keyword argument to retrieve all workitem attributes
  • Loading branch information
dixudx authored Mar 29, 2023
2 parents 9f4fdaa + 4a872df commit 6536246
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
15 changes: 10 additions & 5 deletions rtcclient/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ class RTCBase(object):
OSLC_CR_XML = "application/x-oslc-cm-change-request+xml"
OSLC_CR_JSON = "application/x-oslc-cm-change-request+json"

def __init__(self, url):
def __init__(self, url, skip_full_attributes=True, **kwargs):
self.url = self.validate_url(url)
self.__skip_full_attributes = skip_full_attributes

def __repr__(self):
return "<%s %s>" % (self.__class__.__name__, str(self))

@property
def skip_full_attributes(self):
return self.__skip_full_attributes

@abc.abstractmethod
def __str__(self):
pass
Expand Down Expand Up @@ -244,8 +249,8 @@ class FieldBase(RTCBase):
__metaclass__ = abc.ABCMeta
log = logging.getLogger("base.FieldBase")

def __init__(self, url, rtc_obj, raw_data=None):
RTCBase.__init__(self, url)
def __init__(self, url, rtc_obj, raw_data=None, **kwargs):
RTCBase.__init__(self, url, **kwargs)
self.field_alias = dict()
self.rtc_obj = rtc_obj
self.raw_data = raw_data
Expand Down Expand Up @@ -306,8 +311,8 @@ def __process_items(self, item):
attr = key.split(":")[-1].replace("-", "_")
attr_list = attr.split(".")

# ignore long attributes
if len(attr_list) > 1:
# user want to ignore long attributes
if self.skip_full_attributes and len(attr_list) > 1:
# attr = "_".join([attr_list[-2],
# attr_list[-1]])
return None
Expand Down
14 changes: 10 additions & 4 deletions rtcclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __init__(self,
searchpath=None,
ends_with_jazz=True,
verify: Union[bool, str] = False,
old_rtc_authentication=False):
old_rtc_authentication=False,
**kwargs):
"""Initialization
See params above
Expand All @@ -70,7 +71,7 @@ def __init__(self,
self.proxies = proxies
self.verify = verify
self.old_rtc_authentication = old_rtc_authentication
RTCBase.__init__(self, url)
RTCBase.__init__(self, url, **kwargs)

if not isinstance(ends_with_jazz, bool):
raise exception.BadValue("ends_with_jazz is not boolean")
Expand Down Expand Up @@ -980,13 +981,17 @@ def listFieldsFromWorkitem(self, copied_from, keep=False):

return self.templater.listFieldsFromWorkitem(copied_from, keep=keep)

def getWorkitem(self, workitem_id, returned_properties=None):
def getWorkitem(self,
workitem_id,
returned_properties=None,
skip_full_attributes=True):
"""Get :class:`rtcclient.workitem.Workitem` object by its id/number
:param workitem_id: the workitem id/number
(integer or equivalent string)
:param returned_properties: the returned properties that you want.
Refer to :class:`rtcclient.client.RTCClient` for more explanations
:param skip_full_attributes: flag to retrieve all attributes.
:return: the :class:`rtcclient.workitem.Workitem` object
:rtype: rtcclient.workitem.Workitem
"""
Expand Down Expand Up @@ -1019,7 +1024,8 @@ def getWorkitem(self, workitem_id, returned_properties=None):
return Workitem(workitem_url,
self,
workitem_id=workitem_id,
raw_data=workitem_raw)
raw_data=workitem_raw,
skip_full_attributes=skip_full_attributes)

except ValueError:
excp_msg = "Please input a valid workitem id"
Expand Down
4 changes: 2 additions & 2 deletions rtcclient/workitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Workitem(FieldBase):

OSLC_CR_RDF = "application/rdf+xml"

def __init__(self, url, rtc_obj, workitem_id=None, raw_data=None):
def __init__(self, url, rtc_obj, workitem_id=None, raw_data=None, **kwargs):
self.identifier = workitem_id
FieldBase.__init__(self, url, rtc_obj, raw_data)
FieldBase.__init__(self, url, rtc_obj, raw_data, **kwargs)
if self.identifier is None:
self.identifier = self.url.split("/")[-1]

Expand Down
67 changes: 67 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,73 @@ def test_get_workitem(self, mocker, myrtcclient):
raw_data=utils_test.workitem1)
assert workitem1 == workitem11

@pytest.mark.parametrize('item,expected', [
('com.ibm.workitem.attribute.custom.completeperc', "0"),
("com.ibm.team.workitem.linktype.parentworkitem.parent",
"input title here for 161"),
("com.ibm.team.workitem.linktype.attachment.attachment",
"input title here for 161"),
("com.ibm.team.workitem.linktype.resolvesworkitem.resolves",
"input title here for 161"),
('com.ibm.team.workitem.linktype.relatedworkitem.related',
"input title here for 161"),
('com.ibm.team.workitem.linktype.resolvesworkitem.resolves',
"input title here for 161"),
("com.ibm.team.enterprise.promotion.linktype.promotionBuildResult.promotionBuildResult",
"input title here for 161"),
("com.ibm.team.enterprise.deployment.linktype.deploymentDefinition.packageDefinition",
"input title here for 161"),
("com.ibm.team.enterprise.deployment.linktype.deploymentBuildResult.packageBuildResult",
"input title here for 161"),
("com.ibm.team.enterprise.promotion.linktype.resultWorkItem.promoted",
"input title here for 161"),
("com.ibm.team.workitem.linktype.schedulePredecessor.predecessor",
"input title here for 161"),
("com.ibm.team.build.linktype.includedPackages.com.ibm.team.build.common.link.includedInPackages",
"input title here for 161"),
("com.ibm.team.enterprise.promotion.linktype.gapChangeSets.gapChangeSets",
"input title here for 161"),
("com.ibm.team.workitem.linktype.resolvesworkitem.resolvedBy",
"input title here for 161"),
("com.ibm.team.workitem.linktype.duplicateworkitem.duplicates",
"input title here for 161"),
("com.ibm.team.workitem.linktype.parentworkitem.children",
"input title here for 161"),
("com.ibm.team.enterprise.promotion.linktype.promotedBuildMaps.promotedBuildMaps",
"input title here for 161"),
("com.ibm.team.workitem.linktype.schedulePredecessor.successor",
"input title here for 161"),
("com.ibm.team.filesystem.workitems.change_set.com.ibm.team.scm.ChangeSet",
"input title here for 161"),
("com.ibm.team.workitem.linktype.blocksworkitem.dependsOn",
"input title here for 161"),
("com.ibm.team.enterprise.promotion.linktype.resultWorkItem.result",
"input title here for 161"),
("com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact",
"input title here for 161"),
("com.ibm.workitem.attribute.custom.odc.deftype", None),
("com.ibm.workitem.attribute.custom.odc.history", None),
("com.ibm.workitem.attribute.custom.odc.qualifier", None),
("com.ibm.workitem.attribute.custom.odc.trigger", None),
("com.ibm.workitem.attribute.custome.isvalid", None)
])
def test_get_workitem_full_attributes(self, mocker, myrtcclient, item,
expected):
mocked_get = mocker.patch("requests.get")
mock_resp = mocker.MagicMock(spec=requests.Response)
mock_resp.status_code = 200
mock_resp.content = utils_test.workitem1_raw
mocked_get.return_value = mock_resp

# Workitem1
workitem1 = Workitem("http://test.url:9443/jazz/oslc/workitems/161",
myrtcclient,
workitem_id=161,
raw_data=utils_test.workitem1,
skip_full_attributes=False)
assert workitem1.identifier == "161"
assert workitem1[item] == expected

@pytest.fixture
def mock_get_workitems(self, mocker):
mocked_get = mocker.patch("requests.get")
Expand Down

0 comments on commit 6536246

Please sign in to comment.