Skip to content

Commit 108b39e

Browse files
author
Kip Lehman
committed
S142094 added Connection and PullRequest classes, implemented augmentSchemaWithPullRequestInfo to imitate typdef for PullRequest class in the absence of real PullRequest typedef in wsapi
1 parent 0a6563d commit 108b39e

File tree

3 files changed

+169
-9
lines changed

3 files changed

+169
-9
lines changed

pyral/entity.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,39 @@ class PortfolioItem_Initiative(PortfolioItem): pass
481481
class PortfolioItem_Theme (PortfolioItem): pass
482482
class PortfolioItem_Feature (PortfolioItem): pass
483483

484+
class Connection(WorkspaceDomainObject):
485+
486+
MINIMAL_WDO_ATTRIBUTES = ['_type',
487+
'oid', 'ref', 'ObjectID', 'ObjectUUID', '_ref',
488+
'_CreatedAt', '_hydrated', 'Subscription', 'Workspace']
489+
CONNECTION_INFO_ATTRS = ['ExternalId', 'ExternalFormattedId', 'Name', 'Description', 'Url', 'Artifact']
490+
491+
def details(self):
492+
tank = ['%s' % self._type]
493+
for attribute_name in (Connection.MINIMAL_WDO_ATTRIBUTES + Connection.CONNECTION_INFO_ATTRIBUTES):
494+
try:
495+
value = getattr(self, attribute_name)
496+
except AttributeError:
497+
continue
498+
if value is None:
499+
continue
500+
if 'pyral.entity.' not in str(type(value)):
501+
anv = ' %-24s : %s' % (attribute_name, value)
502+
else:
503+
mo = re.search(r' \'pyral.entity.(\w+)\'>', str(type(value)))
504+
if mo:
505+
cln = mo.group(1)
506+
anv = " %-24s : %-20.20s (OID %s Name: %s)" % \
507+
(attribute_name, cln + '.ref', value.oid, value.Name)
508+
else:
509+
anv = " %-24s : %s" % (attribute_name, value)
510+
tank.append(anv)
511+
tank.append("")
512+
return tank
513+
514+
515+
class PullRequest(Connection): pass
516+
484517
class CustomField(object):
485518
"""
486519
For non-Rally originated entities
@@ -614,6 +647,8 @@ def __setattr__(self, item, value):
614647
'IterationCumulativeFlowData' : IterationCumulativeFlowData,
615648
'RecycleBinEntry' : RecycleBinEntry,
616649
'SearchObject' : SearchObject,
650+
'Connection' : Connection,
651+
'PullRequest' : PullRequest,
617652
}
618653

619654
for entity_name, entity_class in list(classFor.items()):
@@ -956,6 +991,73 @@ def processSchemaInfo(workspace, schema_info):
956991
rally_entity_class = _createClass(pyralized_class_name, parentClass)
957992
classFor[typePath] = rally_entity_class
958993

994+
augmentSchemaWithPullRequestInfo(workspace)
995+
996+
997+
def puff(attr_name, attr_type, attr_required):
998+
ad = {'_ref' : 'attributedefinition/123456',
999+
'_refObjectName' : attr_name,
1000+
'ElementName' : attr_name,
1001+
'Name' : attr_name,
1002+
'AttributeType' : attr_type,
1003+
'Custom' : False,
1004+
'Required' : attr_required,
1005+
'ReadOnly' : False,
1006+
'Filterable' : True,
1007+
'SchemaType' : 'abc',
1008+
'Hidden' : False,
1009+
'Constrained' : False,
1010+
'AllowedValueType' : False,
1011+
'AllowedValues' : [],
1012+
'MaxLength' : 255,
1013+
'MaxFractionalDigits' : 1
1014+
}
1015+
return ad
1016+
1017+
1018+
def augmentSchemaWithPullRequestInfo(workspace):
1019+
wksp_name, wksp_ref = workspace
1020+
global _rally_schema
1021+
global _rally_entity_cache
1022+
1023+
pr_data = {'_ref' : 'pullrequest/1233456789',
1024+
'_refObjectName' : 'Pull Request',
1025+
'ElementName' : 'PullRequest',
1026+
'Name' : 'pullRequest',
1027+
'DisplayName' : 'PullRequest',
1028+
'TypePath' : 'PullRequest',
1029+
'IDPrefix' : 'PR',
1030+
'Abstract' : False,
1031+
#'Parent' : 'Connection',
1032+
'Parent' : None,
1033+
'Creatable' : True,
1034+
'ReadOnly' : False,
1035+
'Queryable' : False,
1036+
'Deletable' : True,
1037+
'Restorable' : False,
1038+
'Ordinal' : 1,
1039+
'RevisionHistory' : 'putrid',
1040+
'Attributes' : [],
1041+
}
1042+
pr_attr_names = [('ExternalId', 'STRING', True),
1043+
('ExternalFormattedId', 'STRING', True),
1044+
('Name', 'STRING', True),
1045+
('Description', 'TEXT', False),
1046+
('Url', 'STRING', True),
1047+
('Artifact', 'OBJECT', True)]
1048+
#pr_attr_names = ['ExternalId',
1049+
# 'ExternalFormattedId',
1050+
# 'Name',
1051+
# 'Description',
1052+
# 'Url',
1053+
# 'Artifact',
1054+
# ]
1055+
#pr_data['Attributes'] = pr_attr_names
1056+
for pr_attr, pr_type, pr_reqd in pr_attr_names:
1057+
pr_data['Attributes'].append(puff(pr_attr, pr_type, pr_reqd))
1058+
_rally_schema[wksp_ref]['PullRequest'] = SchemaItem(pr_data)
1059+
_rally_schema[wksp_ref]['PullRequest'].completed = True
1060+
9591061

9601062
def getSchemaItem(workspace, entity_name):
9611063
wksp_name, wksp_ref = workspace

test/rally_targets.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
AGICEN = "liart.rallydev.com"
3-
PROD = "officialness.rallydev.com"
2+
AGICEN = "rally1.rallydev.com"
3+
PROD = "rally1.rallydev.com"
44

5-
AGICEN_USER = "usernumbernonei@acme.com"
6-
AGICEN_PSWD = "B1G^S3Kretz"
7-
AGICEN_NICKNAME = "Wiley"
8-
API_KEY = "_ABC123DEF456GHI789JKL012MNO345PQR678STU901VWXZ"
5+
AGICEN_USER = "yeti@rallydev.com"
6+
AGICEN_PSWD = "Vistabahn"
7+
AGICEN_NICKNAME = "Yeti"
8+
#API_KEY = "_ABC123DEF456GHI789JKL012MNO345PQR678STU901VWXZ"
99

10-
DEFAULT_WORKSPACE = "Your Default Workspace"
11-
DEFAULT_PROJECT = "Your Default Project"
12-
NON_DEFAULT_PROJECT = "A non-default Project"
10+
DEFAULT_WORKSPACE = "AC WSAPI Toolkit Python"
11+
DEFAULT_PROJECT = "Sample Project"
12+
NON_DEFAULT_PROJECT = "My Project"
1313
ALTERNATE_WORKSPACE = "An Alternate Workspace"
1414
#ALTERNATE_PROJECT = "Dynamic"
1515
ALTERNATE_PROJECT = "An Alternate Project"

test/test_pull_request.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
3+
import sys, os
4+
import types
5+
import py
6+
7+
from pyral import Rally, RallyUrlBuilder, RallyRESTAPIError
8+
from pyral.entity import classFor
9+
from pyral.restapi import hydrateAnInstance
10+
11+
##################################################################################################
12+
13+
from rally_targets import AGICEN, AGICEN_USER, AGICEN_PSWD
14+
from rally_targets import DEFAULT_WORKSPACE, DEFAULT_PROJECT, NON_DEFAULT_PROJECT
15+
from rally_targets import ALTERNATE_WORKSPACE, ALTERNATE_PROJECT
16+
17+
##################################################################################################
18+
19+
20+
dummy_data = {
21+
'ExternalId' : 'abcde12345bb999ee7733aa77ccfedbeaf', #last commit's sha
22+
'ExternalFormattedId' : 11,
23+
'Url' : 'https://github.com/RallyTools/RallyRestToolkitForJava/pull/11/',
24+
'Name' : 'Prepare for Maven Central Deployment',
25+
'Description': 'What makes you happy about this Pull Request? Katy Perry is staying in my tent tonight!',
26+
#'Workspace' : DEFAULT_WORKSPACE,
27+
'Artifact' : 'story/123543216677' # ref to the Artifact mentioned in some commit message
28+
# CreationDate
29+
# SubscriptionID
30+
# Version
31+
# Subclass_Type
32+
}
33+
34+
def test_create_local_pull_request_instance():
35+
fake_oid = 12345698765
36+
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
37+
context1 = rally.contextHelper.currentContext()
38+
pr_class = classFor['PullRequest']
39+
pr = pr_class(fake_oid, dummy_data['Name'], dummy_data['Url'], context1)
40+
assert pr is not None
41+
assert pr.oid == fake_oid
42+
assert pr.Name == dummy_data['Name']
43+
hydrateAnInstance(context1, dummy_data, existingInstance=pr)
44+
assert pr.ExternalId == dummy_data['ExternalId']
45+
assert pr.ExternalFormattedId == dummy_data['ExternalFormattedId']
46+
assert pr.Url == dummy_data['Url']
47+
assert pr.Description == dummy_data['Description']
48+
assert pr.Workspace == DEFAULT_WORKSPACE
49+
50+
def test_post_pull_request():
51+
expectedErrMsg = "No such entity: PullRequest"
52+
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
53+
with py.test.raises(RallyRESTAPIError) as excinfo:
54+
rally.create('PullRequest', dummy_data)
55+
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
56+
assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
57+
assert expectedErrMsg in actualErrVerbiage
58+

0 commit comments

Comments
 (0)