Skip to content

Commit 2e74020

Browse files
committed
mod to logic concerning allowedValues in restapi.py and entity.py, split out allowedValues tests to separate file
1 parent 75c3407 commit 2e74020

4 files changed

Lines changed: 78 additions & 33 deletions

File tree

pyral/entity.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,26 @@ def complete(self, context, getCollection):
674674
"""
675675
This method is used to trigger the complete population of all Attributes,
676676
in particular the resolution of refs to AllowedValues that are present after
677-
the instantation of each Attribute.
677+
the instantiation of each Attribute.
678+
There are some standard attributes whose type is COLLECTION that are not to be
679+
treated as "allowedValue" eligible; for the reason that the collections may be
680+
arbitrarily large and more frequently updated as opposed to more "normal"
681+
attributes like 'State', 'Severity', etc.
678682
Sequence through each Attribute and call resolveAllowedValues for each Attribute.
679683
"""
680684
if self.completed:
681685
return True
682-
for attribute in sorted([attr for attr in self.Attributes if attr.AttributeType in ['RATING', 'STATE']]):
686+
for attribute in sorted([attr for attr in self.Attributes if attr.AttributeType in ['RATING', 'STATE', 'COLLECTION']]):
683687
# only an attribute whose AttributeType is RATING or STATE will have allowedValues
688+
if attribute.ElementName in [ 'Attachments', 'Changesets', 'Children', 'Collaborators',
689+
'Defects', 'DefectSuites', 'Discussion', 'Duplicates',
690+
'Release', 'Iteration', 'Milestones',
691+
'Owner', 'Predecessors', 'Project', 'SubmittedBy',
692+
'Successors', 'Tasks', 'TestCases', 'TestSets', 'Results',
693+
'Steps',
694+
'Tags',
695+
]:
696+
continue
684697
attribute.resolveAllowedValues(context, getCollection)
685698

686699
self.completed = True

pyral/restapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,11 +1529,12 @@ def getAllowedValues(self, entityName, attributeName, **kwargs):
15291529
avs = attribute.resolveAllowedValues(context, getCollection)
15301530
if type(avs) not in collection_types:
15311531
return [avs]
1532-
return [av.StringValue for av in avs]
1532+
return [getattr(av, 'LocalizedStringValue', getattr(av, 'StringValue')) for av in avs]
15331533

15341534
# suggested by Scott Vitale to address issue in Rally WebServices response
15351535
# (sometimes value is present, other times StringValue must be used)
1536-
return [av.StringValue for av in attribute.AllowedValues]
1536+
avs = attribute.AllowedValues
1537+
return [getattr(av, 'LocalizedStringValue', getattr(av, 'StringValue')) for av in avs]
15371538

15381539

15391540
def addAttachment(self, artifact, filename, mime_type='text/plain'):

test/test_allowed_values.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/local/bin/python2.7
2+
3+
import sys, os
4+
import types
5+
import py
6+
7+
import pyral
8+
from pyral import Rally
9+
10+
RallyRESTAPIError = pyral.context.RallyRESTAPIError
11+
12+
##################################################################################################
13+
14+
from rally_targets import AGICEN, AGICEN_USER, AGICEN_PSWD
15+
from rally_targets import API_KEY
16+
17+
EXAMPLE_ATTACHMENT_CONTENT = "The quck brown fox eluded the lumbering sloth\n"
18+
19+
##################################################################################################
20+
21+
def test_getAllowedValues_query():
22+
"""
23+
Using a known valid Rally server and known valid access credentials,
24+
request allowed value information for the State field of the Defect entity.
25+
"""
26+
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
27+
avs = rally.getAllowedValues('Defect', 'State')
28+
assert len(avs) > 0
29+
assert len(avs) >= 4
30+
assert 'Open' in avs
31+
assert 'Closed' in avs
32+
33+
avs = rally.getAllowedValues('Defect', 'PrimaryColor')
34+
assert len(avs) > 0
35+
assert len(avs) >= 6 and len(avs) <= 8
36+
assert 'Red' in avs
37+
assert 'Magenta' in avs
38+
39+
40+
def test_getAllowedValues_for_UserStory():
41+
"""
42+
Using a known valid Rally server and known valid access credentials,
43+
request allowed value information for the Milestones field of the UserStory entity.
44+
"""
45+
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
46+
avs = rally.getAllowedValues('Story', 'Milestones')
47+
assert len(avs) == 1
48+
assert avs == [True]
49+
50+
51+
def test_getAllowedValues_for_custom_collections_field_Defect():
52+
rally = Rally(server=AGICEN, apikey=API_KEY, workspace='Rally', project='Rally')
53+
avs = rally.getAllowedValues('Defect', 'MobileOS')
54+
assert len(avs) > 0
55+
target_value = 'Android'
56+
assert len([v for v in avs if v == target_value]) == 1
57+
58+
##########################################################################################
59+
60+

test/test_convenience.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,6 @@ def test_getAllUsers_query():
9191
assert len(everybody) > 0
9292
assert len([user for user in everybody if user.DisplayName == 'da Kipster']) == 1
9393

94-
def test_getAllowedValues_query():
95-
"""
96-
Using a known valid Rally server and known valid access credentials,
97-
request allowed value information for the State field of the Defect entity.
98-
"""
99-
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
100-
avs = rally.getAllowedValues('Defect', 'State')
101-
assert len(avs) > 0
102-
assert len(avs) >= 4
103-
assert 'Open' in avs
104-
assert 'Closed' in avs
105-
106-
avs = rally.getAllowedValues('Defect', 'PrimaryColor')
107-
assert len(avs) > 0
108-
assert len(avs) >= 6 and len(avs) <= 8
109-
assert 'Red' in avs
110-
assert 'Magenta' in avs
111-
112-
def test_getAllowedValues_for_UserStory():
113-
"""
114-
Using a known valid Rally server and known valid access credentials,
115-
request allowed value information for the Milestones field of the UserStory entity.
116-
"""
117-
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
118-
avs = rally.getAllowedValues('Story', 'Milestones')
119-
assert len(avs) == 1
120-
assert avs == [True]
121-
12294
def test_typedef():
12395
"""
12496
Using a known valid Rally server and known valid access credentials,
@@ -174,7 +146,6 @@ def test_getCollection():
174146
#test_getProject()
175147
#test_getUserInfo_query()
176148
#test_getAllUsers_query()
177-
#test_getAllowedValues_query()
178149
#test_typedef
179150
#test_getStates
180151
#test_getCollection

0 commit comments

Comments
 (0)