-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathtest_requests.robot
302 lines (252 loc) · 11.1 KB
/
test_requests.robot
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
*** Test Cases ***
Get Request
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Get Request Should Have Get Method
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.json()}[method] GET
Get Request With Url Params As Dictionary
[Tags] get
${params}= Create Dictionary param1=1 param2=2
${resp}= GET ${HTTP_LOCAL_SERVER}/anything ${params}
Status Should Be OK ${resp}
Dictionaries Should Be Equal ${params} ${resp.json()}[args]
Get Request With Url Params As Kwargs String
[Tags] get
${params}= Create Dictionary this_is_a_string=1 p2=2
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... params=this_is_a_string=1&p2=2
Status Should Be OK ${resp}
Dictionaries Should Be Equal ${params} ${resp.json()}[args]
Get Request With Url Params As Escaped String
[Tags] get
${params}= Create Dictionary this_is_a_string=1 p2=2
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... this_is_a_string\=1&p2\=2
Status Should Be OK ${resp}
Dictionaries Should Be Equal ${params} ${resp.json()}[args]
Get Request With Url Duplicated Keys In Params
[Tags] get
${array}= Create List 1 2
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... params=key=1&key=2
Status Should Be OK ${resp}
Lists Should Be Equal ${array} ${resp.json()}[args][key]
Get Request With Url Duplicated Keys In Params And PHP Style Array
[Tags] get
${array}= Create List 1 2
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... params=key[]=1&key[]=2
Status Should Be OK ${resp}
Lists Should Be Equal ${array} ${resp.json()}[args][key[]]
Get Request With Url Params As PHP Style Array
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... params=key[]=1,2
Status Should Be OK ${resp}
Should Be Equal As Strings 1,2 ${resp.json()}[args][key[]]
Get Request With Url Params As Array
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/anything
... params=key=[1,2]
Status Should Be OK ${resp}
Should Be Equal As Strings [1,2] ${resp.json()}[args][key]
Get Request With Unordered Parameters
[Tags] get
${params}= Create Dictionary param1=1 param2=2
${resp}= GET params=${params}
... url=${HTTP_LOCAL_SERVER}/anything data=data expected_status=200
Status Should Be OK ${resp}
Dictionaries Should Be Equal ${params} ${resp.json()}[args]
Should Be Equal As Strings data ${resp.json()}[data]
Get Request And Fail By Default On Http Error
[Tags] get
Run Keyword And Expect Error HTTPError: 400*
... GET ${HTTP_LOCAL_SERVER}/status/400
Get Request And Fail By Expecting A 200 Status
[Tags] get
Run Keyword And Expect Error Url: ${HTTP_LOCAL_SERVER}/status/404?param Expected status: 200 != 404
... GET ${HTTP_LOCAL_SERVER}/status/404 param 200
Get Request And Fail By Expecting A 200 Status With A Message
[Tags] get
Run Keyword And Expect Error Custom msg Url: ${HTTP_LOCAL_SERVER}/status/404?param Expected status: 200 != 404
... GET ${HTTP_LOCAL_SERVER}/status/404 param 200 Custom msg
Get Request Expect An Error And Evaluate Response
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/status/401 expected_status=401
Should Be Equal As Strings UNAUTHORIZED ${resp.reason}
Get Request Expect Any Status And Continue On Error
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/status/404 expected_status=ANY
Should Be Equal As Strings NOT FOUND ${resp.reason}
Get Request Expect Anything Status And Continue On Error
[Tags] get
${resp}= GET ${HTTP_LOCAL_SERVER}/status/404 expected_status=Anything
Should Be Equal As Strings NOT FOUND ${resp.reason}
Post Request
[Tags] post
${resp}= POST ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Post Request Should Have Post Method
[Tags] post
${resp}= POST ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.json()}[method] POST
Post Request With Data
[Tags] post
${resp}= POST ${HTTP_LOCAL_SERVER}/anything string
Status Should Be OK ${resp}
Should Be Equal As Strings ${resp.json()}[data] string
Post Request With Json
[Tags] post
${body}= Create Dictionary a=1 b=2
${resp}= POST ${HTTP_LOCAL_SERVER}/anything json=${body}
Status Should Be OK ${resp}
${data}= Evaluate ${resp.json()}[data]
Dictionaries Should Be Equal ${data} ${body}
Post Request Expect An Error And Evaluate Response
[Tags] post
${resp}= POST ${HTTP_LOCAL_SERVER}/status/401 expected_status=401
Should Be Equal As Strings UNAUTHORIZED ${resp.reason}
Post Request Expect Anything Status And Continue On Error
[Tags] post
${resp}= POST ${HTTP_LOCAL_SERVER}/status/400 expected_status=anything
Should Be Equal As Strings BAD REQUEST ${resp.reason}
Put Request
[Tags] put
${resp}= PUT ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Put Request Should Have Put Method
[Tags] put
${resp}= PUT ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.json()}[method] PUT
Put Request With Data
[Tags] put
${resp}= PUT ${HTTP_LOCAL_SERVER}/anything string
Status Should Be OK ${resp}
Should Be Equal As Strings ${resp.json()}[data] string
Put Request With Json
[Tags] put
${body}= Create Dictionary a=1 b=2
${resp}= PUT ${HTTP_LOCAL_SERVER}/anything json=${body}
Status Should Be OK ${resp}
${data}= Evaluate ${resp.json()}[data]
Dictionaries Should Be Equal ${data} ${body}
Put Request Expect An Error And Evaluate Response
[Tags] put
${resp}= PUT ${HTTP_LOCAL_SERVER}/status/401 expected_status=401
Should Be Equal As Strings UNAUTHORIZED ${resp.reason}
Head Request
[Tags] head
${resp}= HEAD ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Head Request Should Not Have A Body
[Tags] head
${resp}= HEAD ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.content} ${Empty}
Head Request With Kwargs Params
[Tags] head
${params}= Create Dictionary param1=1 param2=2
${resp}= HEAD ${HTTP_LOCAL_SERVER}/anything params=${params}
Status Should Be OK ${resp}
Head Request With Header
[Tags] head
${accept_type}= Set Variable application/json
${headers}= Create Dictionary Accept ${accept_type}
${resp}= HEAD ${HTTP_LOCAL_SERVER}/anything headers=${headers}
Status Should Be OK ${resp}
${content_type_response}= Get From Dictionary ${resp.headers} Content-Type
Should Be Equal ${accept_type} ${content_type_response}
Head Request And Fail By Default On Http Error
[Tags] head
Run Keyword And Expect Error HTTPError: 400*
... HEAD ${HTTP_LOCAL_SERVER}/status/400
Head Request Expect An Error And Evaluate Response
[Tags] head
${resp}= HEAD ${HTTP_LOCAL_SERVER}/status/401 expected_status=401
Should Be Equal As Strings UNAUTHORIZED ${resp.reason}
Patch Request
[Tags] patch
${resp}= PATCH ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Patch Request Should Have Patch Method
[Tags] patch
${resp}= PATCH ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.json()}[method] PATCH
Patch Request With Data
[Tags] patch
${resp}= PATCH ${HTTP_LOCAL_SERVER}/anything string
Status Should Be OK ${resp}
Should Be Equal As Strings ${resp.json()}[data] string
Patch Request With Json
[Tags] patch
${body}= Create Dictionary a=1 b=2
${resp}= PATCH ${HTTP_LOCAL_SERVER}/anything json=${body}
Status Should Be OK ${resp}
${data}= Evaluate ${resp.json()}[data]
Dictionaries Should Be Equal ${data} ${body}
Patch Request Expect An Error And Evaluate Response
[Tags] patch
${resp}= PATCH ${HTTP_LOCAL_SERVER}/status/401 expected_status=401
Should Be Equal As Strings UNAUTHORIZED ${resp.reason}
Delete Request
[Tags] delete
${resp}= DELETE ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Delete Request Should Have Delete Method
[Tags] delete
${resp}= DELETE ${HTTP_LOCAL_SERVER}/anything
Should Be Equal As Strings ${resp.json()}[method] DELETE
Delete Request Expect An Error And Evaluate Response
[Tags] delete
${resp}= DELETE ${HTTP_LOCAL_SERVER}/status/202 expected_status=202
Should Be Equal As Strings ACCEPTED ${resp.reason}
Options Request On Existing Session
[Tags] options
${resp}= OPTIONS ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Options Request Check Allow Header
[Tags] options
${allow_header}= Create List GET POST PUT DELETE PATCH TRACE HEAD CONNECT OPTIONS
${resp}= OPTIONS ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
${allow_response_header}= Get From Dictionary ${resp.headers} Allow
${allow_response_header}= Split String ${allow_response_header} ,${SPACE}
Lists Should Be Equal ${allow_header} ${allow_response_header} ignore_order=True
Options Request And Bad Request Not Fail
[Tags] options
${resp}= OPTIONS ${HTTP_LOCAL_SERVER}/status/400
Status Should Be OK ${resp}
Options Request Expect A Success On Unauthorized Request
[Tags] options
${resp}= OPTIONS ${HTTP_LOCAL_SERVER}/status/401 expected_status=200
Status Should Be OK ${resp}
Connect Request
[Tags] connect
${resp}= CONNECT ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Trace Request
[Tags] trace
${resp}= TRACE ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK ${resp}
Get request with last response
[Tags] get
GET ${HTTP_LOCAL_SERVER}/anything
Status Should Be OK
${resp}= Last response
Should be equal ${resp.status_code} ${200}
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything
Post request with last response
[Tags] post
${data}= Create dictionary key1=one key2=two key3=3
POST ${HTTP_LOCAL_SERVER}/anything json=${data}
Status Should Be OK
${resp}= Last response
Should be equal ${resp.status_code} ${200}
Should be equal ${resp.json()}[url] ${HTTP_LOCAL_SERVER}/anything
Should be equal ${resp.json()}[json] ${data}