forked from RallyTools/RallyRestToolkitForPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_attachments.py
More file actions
202 lines (153 loc) · 6.21 KB
/
Copy pathtest_attachments.py
File metadata and controls
202 lines (153 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/local/bin/python2.7
import sys, os
import types
import py
import pyral
from pyral import Rally
RallyRESTAPIError = pyral.context.RallyRESTAPIError
##################################################################################################
from rally_targets import AGICEN, AGICEN_USER, AGICEN_PSWD
from rally_targets import DEFAULT_WORKSPACE, DEFAULT_PROJECT
EXAMPLE_ATTACHMENT_CONTENT = "The quck brown fox eluded the lumbering sloth\n"
##################################################################################################
def conjureUpAttachmentFile(filename, content=None, mimetype="text/plain"):
"""
"""
file_content = content or EXAMPLE_ATTACHMENT_CONTENT
with open(filename, 'w') as af:
af.write(file_content)
return True
def retrieveAttachment(rally, artifact, attachmentFileName):
"""
"""
pass
def test_add_attachment():
"""
"""
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
# find a Project with some US artifacts
# pick one with no attachments
# create an attachment file (or choose a smallish file with a commonly used suffix)
# create the attachment in Rally and link it to the US artifact
wksp = rally.getWorkspace()
assert wksp.Name == DEFAULT_WORKSPACE
response = rally.get('Project', fetch=False, limit=10)
assert response != None
assert response.status_code == 200
proj = rally.getProject() # proj.Name == DEFAULT_PROJECT
assert proj.Name == DEFAULT_PROJECT
#response = rally.get("UserStory", fetch="FormattedID,Name,Attachments")
#for story in response:
# print "%s %-48.48s %d" % (story.FormattedID, story.Name, len(story.Attachments))
candidate_story = "US1" # was "US96" in trial
response = rally.get("UserStory", fetch="FormattedID,Name,Attachments",
query='FormattedID = "%s"' % candidate_story)
##print(response.resultCount)
story = response.next()
assert len(story.Attachments) == 0
attachment_name = "Addendum.txt"
att_ok = conjureUpAttachmentFile(attachment_name)
assert att_ok == True
att = rally.addAttachment(story, attachment_name)
assert att.Name == attachment_name
response = rally.get("UserStory", fetch="FormattedID,Name,Attachments",
query='FormattedID = "%s"' % candidate_story)
story = response.next()
assert len(story.Attachments) == 1
def test_get_attachment():
"""
"""
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
candidate_story = "US2" # was this in trial -> "US80"
target = 'FormattedID = "%s"' % candidate_story
response = rally.get("UserStory", fetch=True, query=target, project=None)
assert response.resultCount == 1
story = response.next()
##
assert True == True
return True
##
assert len(story.Attachments) == 1
attachment = story.Attachments[0]
expected_attachment_name = "Addendum.txt"
assert attachment.Name == expected_attachment_name
attachment = rally.getAttachment(candidate_story, expected_attachment_name)
assert attachment.Name == expected_attachment_name
assert attachment.Content == EXAMPLE_ATTACHMENT_CONTENT
def test_add_tcr_attachment():
"""
Add an Attachment to a TestCaseResult item
Create a TestCase, save a reference
Create a TestCaseResult to be associated with the TestCase
Create an attachment
Attach the Attachment to the TestCaseResult item
"""
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
wksp = rally.getWorkspace()
assert wksp.Name == DEFAULT_WORKSPACE
response = rally.get('Project', fetch=False, limit=10)
assert response != None
assert response.status_code == 200
proj = rally.getProject() # proj.Name == Sample Project
assert proj.Name == 'Sample Project'
tc_info = { "Workspace" : wksp.ref,
"Project" : proj.ref,
"Name" : "Heat exposure",
"Type" : "Functional",
}
test_case = rally.create('TestCase', tc_info)
assert int(test_case.oid) > 0
tcr_info = { "Workspace" : wksp.ref,
"TestCase" : test_case.ref,
"Date" : "2016-05-17T14:30:28.000Z",
"Build" : 17,
"Verdict" : "Pass"
}
tcr = rally.create('TestCaseResult', tcr_info)
assert int(tcr.oid) > 0
attachment_name = "Addendum.txt"
att_ok = conjureUpAttachmentFile(attachment_name)
assert att_ok == True
att = rally.addAttachment(tcr, attachment_name)
assert att.Name == attachment_name
def test_detach_attachment():
"""
This is the counterpart test for test_add_attachment
"""
rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
candidate_story = "US1" # "US96"
target = 'FormattedID = "%s"' % candidate_story
response = rally.get("UserStory", fetch=True, query=target, project=None)
assert response.resultCount == 1
story = response.next()
assert len(story.Attachments) == 1
attachment = story.Attachments[0]
expected_attachment_name = "Addendum.txt"
assert attachment.Name == expected_attachment_name
result = rally.deleteAttachment(story, expected_attachment_name)
assert result != False
assert len(result.Attachments) == (len(story.Attachments) - 1)
def x_test_replace_attachment():
"""
"""
def x_test_add_attachments():
"""
"""
def x_test_get_attachments():
"""
"""
def x_test_detach_attachments():
"""
"""
def x_test_replace_attachments():
"""
"""
#expectedErrMsg = "hostname '%s' non-existent or unreachable" % bogus_server
#with py.test.raises(RallyRESTAPIError) as excinfo:
# rally = Rally(server=bogus_server,
# user=AGICEN_USER,
# password=AGICEN_PSWD)
#actualErrVerbiage = excinfo.value.args[0] # becuz Python2.6 deprecates message :-(
#assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
#assert actualErrVerbiage == expectedErrMsg
##########################################################################################