Skip to content

Commit 3f3dd5b

Browse files
committed
fixed enableLogging in restapi, updated the attachment tests, the conn tests and re-added support for 3.6 after confirming that 3.6, 3.7, 3.8 and 3.9 all pass the test suite
1 parent 69bd22d commit 3f3dd5b

File tree

6 files changed

+45
-44
lines changed

6 files changed

+45
-44
lines changed

pyral/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def rallyWorkset(args):
7474
or --cfg=<config_file_name>
7575
3) ENV variable with location of rally-<version>.cfg --> RALLY_CONFIG
7676
4) current directory with rally-<version>.cfg
77-
5) RALLY_SERVER, RALLY_USER_NAME, RALLY_PASSWORD, APIKEY, RALLY_WORKSPACE, RALLY_PROJECT, RALLY_PING env VARS
77+
5) RALLY_SERVER, RALLY_USER_NAME, RALLY_PASSWORD, APIKEY, RALLY_WORKSPACE, RALLY_PROJECT env VARS
7878
6) SERVER, USER_NAME, PASSWORD defined in this module
7979
8080
start by priming the return values with #6 and work your way up the priority ladder
@@ -122,7 +122,6 @@ def snarfSettings(targetFile, server_creds):
122122
# #5
123123
# if there are environment vars, use them
124124
#
125-
# purposely excluding RALLY_PING, we'll recognize in the environment later, don't want to make it part of server_creds ...
126125
for ix, name in enumerate(['RALLY_SERVER', 'RALLY_USER', 'RALLY_PASSWORD', 'APIKEY', 'RALLY_WORKSPACE', 'RALLY_PROJECT']):
127126
if name in os.environ:
128127
server_creds[ix] = os.environ[name]

pyral/restapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def enableLogging(self, dest=sys.stdout, attrget=False, append=False):
350350
self._log = True
351351
if hasattr(dest, 'write'):
352352
self._logDest = dest
353-
elif type(dest) == bytes:
353+
elif isinstance(dest, (str,bytes)):
354354
try:
355355
mode = 'w'
356356
if append:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
desc_file = path.join(path.abspath(path.dirname(__file__)), FULL_DESCRIPTION)
2222
with open(desc_file, encoding='utf-8') as df: long_description = df.read()
2323

24-
MINIMUM_REQUESTS_VERSION = '2.25.1' # although 2.25.x is recommended
24+
MINIMUM_REQUESTS_VERSION = '2.25.1'
2525
REQUIRES = ['six',
2626
'requests>=%s' % MINIMUM_REQUESTS_VERSION
2727
]
@@ -33,6 +33,7 @@
3333
'License :: OSI Approved :: BSD License',
3434
'Operating System :: OS Independent',
3535
'Programming Language :: Python',
36+
'Programming Language :: Python :: 3.6',
3637
'Programming Language :: Python :: 3.7',
3738
'Programming Language :: Python :: 3.8',
3839
'Programming Language :: Python :: 3.9',

test/test_attachments.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
from rally_targets import DEFAULT_WORKSPACE, DEFAULT_PROJECT
1717
from rally_targets import YETI_USER, YETI_PSWD, YETI_NAME
1818

19-
EXAMPLE_ATTACHMENT_CONTENT = "The quick brown fox eluded the lumbering sloth\n"
19+
EXAMPLE_ATTACHMENT_CONTENT = b'SERVER = trial.rallydev.com\nUSER = [email protected]\nPASSWORD = RallyDev\nWORKSPACE = Primavera\nPROJECT = Sample Project\n'
20+
EXAMPLE_TEXT_ATTACHMENT_CONTENT = "The quick brown fox eluded the lumbering sloth\n"
2021

2122
##################################################################################################
2223

2324
def conjureUpAttachmentFile(filename, content=None, mimetype="text/plain"):
2425
"""
2526
"""
26-
file_content = content or EXAMPLE_ATTACHMENT_CONTENT
27+
file_content = content or EXAMPLE_TEXT_ATTACHMENT_CONTENT
2728
with open(filename, 'w') as af:
2829
af.write(file_content)
2930
return True
@@ -143,25 +144,26 @@ def test_add_attachment():
143144
def test_get_attachment():
144145
"""
145146
"""
146-
#rally = Rally(server=RALLY, user=RALLY_USER, password=RALLY_PSWD)
147147
rally = Rally(server=RALLY, user=RALLY_USER, apikey=APIKEY)
148-
candidate_story = "US2" # was this in trial -> "US80"
148+
candidate_story = "US2"
149149
target = 'FormattedID = "%s"' % candidate_story
150150
response = rally.get("UserStory", fetch=True, query=target, project=None)
151151
assert response.resultCount == 1
152152
story = response.next()
153-
##
154-
assert True == True
155-
return True
156-
##
157-
assert len(story.Attachments) == 1
158-
attachment = story.Attachments[0]
159-
expected_attachment_name = "Addendum.txt"
160-
assert attachment.Name == expected_attachment_name
153+
154+
atts = story.Attachments
155+
assert len(atts) == 2
156+
att1 = story.Attachments[0]
157+
expected_attachment_name = "buster.cbq"
158+
assert att1.Name == expected_attachment_name
159+
160+
att2 = story.Attachments[1]
161+
expected_attachment_name = 'prima.cfg'
162+
assert att2.Name == expected_attachment_name
161163

162164
attachment = rally.getAttachment(candidate_story, expected_attachment_name)
163165
assert attachment.Name == expected_attachment_name
164-
assert attachment.Content == EXAMPLE_ATTACHMENT_CONTENT
166+
assert EXAMPLE_ATTACHMENT_CONTENT == attachment.Content
165167

166168
def test_add_tcr_attachment():
167169
"""
@@ -220,10 +222,10 @@ def test_add_tcr_attachment():
220222
actual_attachment_content = attachment.Content.decode('UTF-8').replace("\r", '')
221223
att_content = att.Content.decode('UTF-8').replace("\r", '')
222224

223-
assert actual_attachment_content == EXAMPLE_ATTACHMENT_CONTENT
224-
assert att_content == EXAMPLE_ATTACHMENT_CONTENT
225-
#assert attachment.Content.decode('UTF-8') == EXAMPLE_ATTACHMENT_CONTENT
226-
#assert att.Content.decode('UTF-8') == EXAMPLE_ATTACHMENT_CONTENT
225+
assert actual_attachment_content == EXAMPLE_TEXT_ATTACHMENT_CONTENT
226+
assert att_content == EXAMPLE_TEXT_ATTACHMENT_CONTENT
227+
#assert attachment.Content.decode('UTF-8') == EXAMPLE_TEXT_ATTACHMENT_CONTENT
228+
#assert att.Content.decode('UTF-8') == EXAMPLE_TEXT_ATTACHMENT_CONTENT
227229
rally.deleteAttachment(tcr, attachment_name)
228230
rally.delete('TestCaseResult', tcr)
229231
rally.delete('TestCase', test_case)

test/test_conn.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys, os
44
import types
55
import py
6+
import pytest
67
import time
78
import re
89

@@ -101,7 +102,7 @@ def test_basic_connection_with_bad_api_key():
101102
"""
102103
BOGUS_API_KEY = "_ABC123DEF456GHI789JKL012MNO345PQR678STUVZ"
103104
expectedErrMsg = 'Invalid credentials'
104-
with py.test.raises(RallyRESTAPIError) as excinfo:
105+
with pytest.raises(RallyRESTAPIError) as excinfo:
105106
rally = Rally(PROD, "[email protected]", "manict0X0", apikey=BOGUS_API_KEY)
106107
actualErrVerbiage = excinfo.value.args[0]
107108
assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
@@ -117,7 +118,7 @@ def test_basic_connection_with_good_up_and_bad_api_key():
117118
"""
118119
BOGUS_API_KEY = "_ABC123DEF456GHI789JKL012MNO345PQR678STUVZ"
119120
expectedErrMsg = 'Invalid credentials'
120-
with py.test.raises(RallyRESTAPIError) as excinfo:
121+
with pytest.raises(RallyRESTAPIError) as excinfo:
121122
rally = Rally(PROD, user=PROD_USER, password=PROD_PSWD, apikey=BOGUS_API_KEY)
122123
actualErrVerbiage = excinfo.value.args[0]
123124
assert expectedErrMsg == actualErrVerbiage
@@ -134,7 +135,7 @@ def test_nonexistent_server():
134135
bogus_server = "bogus.notreally.bug"
135136
expectedErrMsg = "Target Rally host: '%s' non-existent or unreachable" % bogus_server
136137
#print expectedErrMsg
137-
with py.test.raises(RallyRESTAPIError) as excinfo:
138+
with pytest.raises(RallyRESTAPIError) as excinfo:
138139
rally = Rally(server=bogus_server)
139140
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
140141
#print actualErrVerbiage
@@ -155,14 +156,12 @@ def test_non_rally_server():
155156
non_rally_server = 'www.irs.gov'
156157
#non_rally_server = 'www.espn.com'
157158

158-
with py.test.raises(RallyRESTAPIError) as excinfo:
159+
with pytest.raises(RallyRESTAPIError) as exc:
159160
rally = Rally(server=non_rally_server, timeout=5)
160-
print("Exception typename: %s" % excinfo.typename)
161-
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
162-
print(actualErrVerbiage)
163-
expectedErrMsg = "Target host: '%s' is either not reachable or " % non_rally_server
164-
ex_value_mo = re.search(expectedErrMsg, actualErrVerbiage)
165-
assert ex_value_mo is not None
161+
print("Exception typename: %s" % exc.typename)
162+
print(str(exc))
163+
expected_error = "404 Target host: 'www.irs.gov' is either not reachable or doesn't support the Rally WSAPI"
164+
assert expected_error in str(exc)
166165
time.sleep(1)
167166

168167

@@ -175,13 +174,13 @@ def test_bad_server_spec():
175174
The status_code in the response must indicate a non-success condition.
176175
"""
177176
bad_server = "ww!w.\fo,o\r\n.c%om"
178-
expectedErrMsg = "404 Target host: 'ww!w.\x0co,o\r\n.c%om' is either not reachable or doesn't support the Rally WSAPI"
177+
expectedErrMsg = "host: 'ww!w.\x0co,o\r\n.c%om' is either not reachable or doesn't support the Rally WSAPI"
179178
print("expectedErrMesssage |{0}|".format(expectedErrMsg))
180-
with py.test.raises(RallyRESTAPIError) as excinfo:
179+
with pytest.raises(RallyRESTAPIError) as exc:
181180
rally = Rally(server=bad_server, timeout=3)
182-
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
181+
actualErrVerbiage = exc.value.args[0]
183182
print("actualErrVerbiage |{0}|".format(actualErrVerbiage))
184-
assert actualErrVerbiage == expectedErrMsg
183+
assert expectedErrMsg in actualErrVerbiage
185184
time.sleep(1)
186185

187186

@@ -200,7 +199,7 @@ def test_insuff_credentials():
200199
"""
201200
expectedErrMsg = 'Invalid credentials'
202201

203-
with py.test.raises(RallyRESTAPIError) as excinfo:
202+
with pytest.raises(RallyRESTAPIError) as excinfo:
204203
rally = Rally(server=RALLY, user=RALLY_USER, password="")
205204
response = rally.get('Project', fetch=False, limit=10)
206205
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
@@ -209,7 +208,7 @@ def test_insuff_credentials():
209208
#print "detected valid user, missing password condition"
210209
time.sleep(1)
211210

212-
with py.test.raises(RallyRESTAPIError) as excinfo:
211+
with pytest.raises(RallyRESTAPIError) as excinfo:
213212
rally = Rally(server=RALLY, user="", password="doofus")
214213
response = rally.get('Project', fetch=False, limit=10)
215214
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
@@ -218,7 +217,7 @@ def test_insuff_credentials():
218217
#print "detected blank user, invalid password condition"
219218
time.sleep(1)
220219

221-
with py.test.raises(RallyRESTAPIError) as excinfo:
220+
with pytest.raises(RallyRESTAPIError) as excinfo:
222221
rally = Rally(server=RALLY, user="", password="")
223222
response = rally.get('Project', fetch=False, limit=10)
224223
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
@@ -227,7 +226,7 @@ def test_insuff_credentials():
227226
#print "detected blank user and password condition"
228227
time.sleep(1)
229228

230-
with py.test.raises(RallyRESTAPIError) as excinfo:
229+
with pytest.raises(RallyRESTAPIError) as excinfo:
231230
rally = Rally(server=RALLY, user="guest", password="")
232231
response = rally.get('Project', fetch=False, limit=10)
233232
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
@@ -236,7 +235,7 @@ def test_insuff_credentials():
236235
#print "detected invalid user, blank password condition"
237236
time.sleep(1)
238237

239-
with py.test.raises(RallyRESTAPIError) as excinfo:
238+
with pytest.raises(RallyRESTAPIError) as excinfo:
240239
rally = Rally(server=RALLY, user="guest", password="doofus")
241240
response = rally.get('Project', fetch=False, limit=10)
242241
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
@@ -245,7 +244,7 @@ def test_insuff_credentials():
245244
#print "detected invalid user, invalid password condition"
246245
time.sleep(1)
247246

248-
with py.test.raises(RallyRESTAPIError) as excinfo:
247+
with pytest.raises(RallyRESTAPIError) as excinfo:
249248
rally = Rally(server=RALLY, user="guest")
250249
response = rally.get('Project', fetch=False, limit=10)
251250
actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(

test/test_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def test_query_between_range_operator():
638638
Query for CreatedDate between 2016-09-30T00:00:00Z and 2016-10-04T23:59:59.999Z'
639639
Should get 1 item
640640
"""
641-
# Use DEFAULT_WORKSPACE, DEFAULT_WORKSPACE
641+
# Uses DEFAULT_WORKSPACE, DEFAULT_PROJECT
642642
rally = Rally(server=RALLY, user=RALLY_USER, password=RALLY_PSWD)
643643
response = rally.get('Story', fetch=True, pagesize=100, limit=100)
644644
all_stories = [item for item in response]
@@ -666,7 +666,7 @@ def test_query_not_between_range_operator():
666666
#assert result of query is has some elements less than date_1, and
667667
# has some greater than date_2 and none in the range specified
668668
"""
669-
# Use DEFAULT_WORKSPACE, DEFAULT_WORKSPACE
669+
# Uses DEFAULT_WORKSPACE, DEFAULT_PROJECT
670670
rally = Rally(server=RALLY, user=RALLY_USER, password=RALLY_PSWD)
671671
range_start_date = '2016-09-30T00:00:00Z'
672672
range_end_date = '2016-11-01T00:00:00Z'
@@ -680,7 +680,7 @@ def test_query_not_between_range_operator():
680680
assert after_date_stories
681681
assert len(prior_date_stories) + len(after_date_stories) == len(target_stories)
682682
tweener_stories = [story for story in target_stories
683-
if story.CreationDate >= range_start_date
683+
if story.CreationDate >= range_start_date
684684
and story.CreationDate <= range_end_date]
685685
assert len(tweener_stories) == 0
686686

0 commit comments

Comments
 (0)