forked from openprocurement/openregistry.lots.basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.py
executable file
·313 lines (238 loc) · 13.7 KB
/
docs.py
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
303
304
305
306
307
308
309
310
311
312
313
# -*- coding: utf-8 -*-
from openregistry.lots.core.tests.base import PrefixedRequestClass, DumpsTestAppwebtest
from openregistry.lots.basic.tests.base import BaseLotWebTest
class LotResourceTest(BaseLotWebTest):
def setUp(self):
super(LotResourceTest, self).setUp()
self.app = DumpsTestAppwebtest(
"config:tests.ini", relative_to=self.relative_to)
self.app.RequestClass = PrefixedRequestClass
self.app.authorization = ('Basic', ('broker', ''))
self.couchdb_server = self.app.app.registry.couchdb_server
self.db = self.app.app.registry.db
def test_docs_tutorial(self):
request_path = '/?opt_pretty=1'
# Exploring basic rules
#
with open('docs/source/tutorial/lot-listing.http', 'w') as self.app.file_obj:
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')
self.app.file_obj.write("\n")
with open('docs/source/tutorial/lot-post-attempt.http', 'w') as self.app.file_obj:
response = self.app.post(request_path, 'data', status=415)
self.assertEqual(response.status, '415 Unsupported Media Type')
with open('docs/source/tutorial/lot-post-attempt-json.http', 'w') as self.app.file_obj:
response = self.app.post(
request_path, 'data', content_type='application/json', status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
# Creating lot in draft status
#
with open('docs/source/tutorial/lot-post-2pc.http', 'w') as self.app.file_obj:
response = self.app.post_json(request_path, {"data": self.initial_data})
self.assertEqual(response.status, '201 Created')
lot_id = response.json['data']['id']
owner_token = response.json['access']['token']
with open('docs/source/tutorial/blank-lot-view.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
# Switch to 'pending'
#
with open('docs/source/tutorial/lot-patch-2pc.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
# Modifying lot
#
with open('docs/source/tutorial/patch-lot.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data':
{
"description": "Змінений опис тестового лоту"
}
})
self.assertEqual(response.status, '200 OK')
self.app.get(request_path)
with open('docs/source/tutorial/lot-listing-after-patch.http', 'w') as self.app.file_obj:
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')
# Switch to 'verification'
#
with open('docs/source/tutorial/lot-patch-2pc-verification.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'verification'}})
self.assertEqual(response.status, '200 OK')
# Hack for update_after
#
self.app.get(request_path)
#
with open('docs/source/tutorial/initial-lot-listing.http', 'w') as self.app.file_obj:
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/create-second-lot.http', 'w') as self.app.file_obj:
response = self.app.post_json(request_path, {"data": self.initial_data})
self.assertEqual(response.status, '201 Created')
second_lot_id = response.json['data']['id']
second_owner_token = response.json['access']['token']
with open('docs/source/tutorial/pending-second-lot.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(second_lot_id, second_owner_token),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
# Hack for update_after
#
self.app.get(request_path)
#
with open('docs/source/tutorial/listing-with-some-lots.http', 'w') as self.app.file_obj:
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')
# Switch to 'deleted'
#
with open('docs/source/tutorial/lot-delete-2pc.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(second_lot_id, second_owner_token),
{'data': {"status": 'deleted'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('broker', ''))
def test_docs_tutorial_with_concierge(self):
request_path = '/?opt_pretty=1'
response = self.app.post_json(request_path, {"data": self.initial_data})
self.assertEqual(response.status, '201 Created')
lot_id = response.json['data']['id']
owner_token = response.json['access']['token']
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'verification'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'active.salable'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.salable'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/concierge-patched-lot-to-active.salable.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('broker', ''))
# Switch to 'pending.dissolution'
#
with open('docs/source/tutorial/patch-lot-to-pending.dissolution.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'pending.dissolution'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'pending.dissolution')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'dissolved'
#
with open('docs/source/tutorial/patch-lot-to-dissolved.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'dissolved'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'dissolved')
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json(request_path, {"data": self.initial_data})
self.assertEqual(response.status, '201 Created')
lot_id = response.json['data']['id']
owner_token = response.json['access']['token']
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'verification'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'pending' from 'verification'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/concierge-patched-lot-to-pending.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'verification'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('concierge', ''))
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.salable'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('convoy', ''))
# Switch to 'active.awaiting'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.awaiting'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/convoy-patched-lot-to-active.awaiting.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
# Switch to 'active.salable' from 'active.awaiting'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.salable'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/convoy-patched-lot-to-active.salable.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.awaiting'}})
self.assertEqual(response.status, '200 OK')
# Switch to 'active.auction'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.auction'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/convoy-patched-lot-to-active.auction.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
# Switch to 'pending.sold'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'pending.sold'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/convoy-patched-lot-to-pending.sold.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'sold'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'sold'}})
self.assertEqual(response.status, '200 OK')
with open('docs/source/tutorial/patch-lot-to-sold-from-pending.sold.http', 'w') as self.app.file_obj:
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
# Recomposed tutorial
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json(request_path, {"data": self.initial_data})
self.assertEqual(response.status, '201 Created')
lot_id = response.json['data']['id']
owner_token = response.json['access']['token']
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'verification'}})
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'active.salable'
#
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'active.salable'}})
self.assertEqual(response.status, '200 OK')
response = self.app.get('/{}'.format(lot_id))
self.assertEqual(response.status, '200 OK')
self.app.authorization = ('Basic', ('broker', ''))
# Switch to 'recomposed'
#
with open('docs/source/tutorial/patch-lot-to-recomposed.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token),
{'data': {"status": 'recomposed'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'recomposed')
self.app.authorization = ('Basic', ('concierge', ''))
# Switch to 'pending'
#
with open('docs/source/tutorial/patch-lot-to-pending-from-recomposed.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}'.format(lot_id),
{'data': {"status": 'pending'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'pending')