Skip to content

Commit

Permalink
Merge pull request #1 from Leits/doc
Browse files Browse the repository at this point in the history
Generate http requests for documentation
  • Loading branch information
kroman0 committed Jan 28, 2016
2 parents 774db67 + f6db6ba commit eef2586
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 50 deletions.
183 changes: 159 additions & 24 deletions docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@
}


answer = {
"data": {
"answer": "Таблицю додано в файлі \"Kalorijnist.xslx\""
}
}

cancellation = {
'data': {
'reason': 'cancellation reason'
}
}

class DumpsTestAppwebtest(TestApp):
def do_request(self, req, status=None, expect_errors=None):
req.headers.environ["HTTP_HOST"] = "api-sandbox.openprocurement.org"
Expand Down Expand Up @@ -207,13 +219,17 @@ def setUp(self):

def test_docs(self):
request_path = '/tenders?opt_pretty=1'

#### Exploring basic rules
#

with open('docs/source/tutorial/tender-listing.http', 'w') as self.app.file_obj:
self.app.authorization = ('Basic', ('token', ''))
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')
self.app.file_obj.write("\n")

with open('docs/source/tutorial/tender-post-attempt-json-data.http', 'w') as self.app.file_obj:
with open('docs/source/tutorial/tender-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')

Expand All @@ -225,11 +241,8 @@ def test_docs(self):
request_path, 'data', content_type='application/json', status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')

with open('docs/source/tutorial/tender-post-attempt-json.http', 'w') as self.app.file_obj:
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post(
request_path, 'data', content_type='application/json', status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
#### Creating tender
#

with open('docs/source/tutorial/tender-post-attempt-json-data.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders?opt_pretty=1', {"data": test_tender_ua_data})
Expand All @@ -242,13 +255,16 @@ def test_docs(self):
response = self.app.get('/tenders/{}'.format(tender['id']))
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/tender-listing.http', 'w') as self.app.file_obj:
with open('docs/source/tutorial/tender-listing-no-auth.http', 'w') as self.app.file_obj:
self.app.authorization = None
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')

self.app.authorization = ('Basic', ('token', ''))

#### Modifying tender
#

tenderPeriod_endDate = get_now() + timedelta(days=15, seconds=10)
with open('docs/source/tutorial/patch-items-value-periods.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), {'data':
Expand All @@ -264,9 +280,13 @@ def test_docs(self):
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')


self.app.authorization = ('Basic', ('token', ''))
self.tender_id = tender['id']

#### Uploading documentation
#

with open('docs/source/tutorial/upload-tender-notice.http', 'w') as self.app.file_obj:
response = self.app.post('/tenders/{}/documents'.format(
self.tender_id), upload_files=[('file', u'Notice.pdf', 'content')])
Expand Down Expand Up @@ -295,6 +315,35 @@ def test_docs(self):
self.tender_id, doc_id), upload_files=[('file', 'AwardCriteria-2.pdf', 'content2')])
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/tender-documents-3.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/documents'.format(
self.tender_id))
self.assertEqual(response.status, '200 OK')

#### Enquiries
#

with open('docs/source/tutorial/ask-question.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/questions'.format(
self.tender_id), question, status=201)
question_id = response.json['data']['id']
self.assertEqual(response.status, '201 Created')

with open('docs/source/tutorial/answer-question.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}/questions/{}'.format(
self.tender_id, question_id), answer, status=200)
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/list-question.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/questions'.format(
self.tender_id))
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/get-answer.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/questions/{}'.format(
self.tender_id, question_id))
self.assertEqual(response.status, '200 OK')

self.go_to_enquiryPeriod_end()
self.app.authorization = ('Basic', ('broker', ''))
with open('docs/source/tutorial/update-tender-after-enqiery.http', 'w') as self.app.file_obj:
Expand Down Expand Up @@ -323,58 +372,144 @@ def test_docs(self):
self.assertEqual(response.status, '200 OK')


#### Registering bid
#

# tutorial/ask-question.http
# tutorial/answer-question.http
# tutorial/list-question.http
# tutorial/get-answer.http

# tutorial/register-bidder.http
bids_access = {}
with open('docs/source/tutorial/register-bidder.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/bids'.format(
self.tender_id), bid)
bid_id = response.json['data']['id']
bids_access[bid_id] = response.json['access']['token']
bid1_id = response.json['data']['id']
bids_access[bid1_id] = response.json['access']['token']
self.assertEqual(response.status, '201 Created')

# tutorial/upload-bid-proposal.http
#### Proposal Uploading
#

with open('docs/source/tutorial/upload-bid-proposal.http', 'w') as self.app.file_obj:
response = self.app.post('/tenders/{}/bids/{}/documents?acc_token={}'.format(
self.tender_id, bid_id, bids_access[bid_id]), upload_files=[('file', 'Proposal.pdf', 'content')])
self.tender_id, bid1_id, bids_access[bid1_id]), upload_files=[('file', 'Proposal.pdf', 'content')])
self.assertEqual(response.status, '201 Created')

# tutorial/bidder-documents.http
with open('docs/source/tutorial/bidder-documents.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/bids/{}/documents?acc_token={}'.format(
self.tender_id, bid_id, bids_access[bid_id]))
self.tender_id, bid1_id, bids_access[bid1_id]))
self.assertEqual(response.status, '200 OK')


response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token),
{'data': {"value": {'amount': 501.0}}})
self.assertEqual(response.status, '200 OK')

#### Bid invalidation
#

with open('docs/source/tutorial/bidder-after-changing-tender.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(
self.tender_id, bid_id, bids_access[bid_id]))
self.tender_id, bid1_id, bids_access[bid1_id]))
self.assertEqual(response.status, '200 OK')

#### Bid confirmation
#

with open('docs/source/tutorial/bidder-activate-after-changing-tender.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}/bids/{}?acc_token={}'.format(
self.tender_id, bid_id, bids_access[bid_id]), {'data': {"status": "active"}})
self.tender_id, bid1_id, bids_access[bid1_id]), {'data': {"status": "active"}})
self.assertEqual(response.status, '200 OK')

# with open('docs/source/tutorial/bidder-after-activate-bid-tender.http', 'w') as self.app.file_obj:
# response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(
# self.tender_id, bid_id, bids_access[bid_id]))
# self.tender_id, bid1_id, bids_access[bid1_id]))
# self.assertEqual(response.status, '200 OK')
# tutorial/register-2nd-bidder.http
with open('docs/source/tutorial/register-2nd-bidder.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/bids'.format(
self.tender_id), bid2)
bid_id = response.json['data']['id']
bids_access[bid_id] = response.json['access']['token']
bid2_id = response.json['data']['id']
bids_access[bid2_id] = response.json['access']['token']
self.assertEqual(response.status, '201 Created')


#### Auction
#
self.set_status('active.auction')
self.app.authorization = ('Basic', ('auction', ''))
patch_data = {
'auctionUrl': u'http://auction-sandbox.openprocurement.org/tenders/{}'.format(self.tender_id),
'bids': [
{
"id": bid1_id,
"participationUrl": u'http://auction-sandbox.openprocurement.org/tenders/{}?key_for_bid={}'.format(self.tender_id, bid1_id)
},
{
"id": bid2_id,
"participationUrl": u'http://auction-sandbox.openprocurement.org/tenders/{}?key_for_bid={}'.format(self.tender_id, bid2_id)
}
]
}
response = self.app.patch_json('/tenders/{}/auction?acc_token={}'.format(self.tender_id, owner_token),
{'data': patch_data})
self.assertEqual(response.status, '200 OK')

self.app.authorization = ('Basic', ('broker', ''))

with open('docs/source/tutorial/auction-url.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/bidder-participation-url.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(self.tender_id, bid1_id, bids_access[bid1_id]))
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/bidder2-participation-url.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(self.tender_id, bid2_id, bids_access[bid2_id]))
self.assertEqual(response.status, '200 OK')

#### Confirming qualification
#
self.app.authorization = ('Basic', ('token', ''))
self.set_status('active.qualification')

with open('docs/source/tutorial/confirm-qualification.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
self.tender_id, owner_token), {'data': {'suppliers': [tender["procuringEntity"]], 'status': 'pending', 'bid_id': bid1_id}})
self.assertEqual(response.status, '201 Created')



#### Preparing the cancellation request
#

with open('docs/source/tutorial/prepare-cancellation.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/cancellations?acc_token={}'.format(
self.tender_id, owner_token), cancellation)
self.assertEqual(response.status, '201 Created')

cancellation_id = response.json['data']['id']

#### Filling cancellation with protocol and supplementary documentation
#

with open('docs/source/tutorial/upload-cancellation-doc.http', 'w') as self.app.file_obj:
response = self.app.post('/tenders/{}/cancellations/{}/documents?acc_token={}'.format(
self.tender_id, cancellation_id, owner_token), upload_files=[('file', u'Notice.pdf', 'content')])
cancellation_doc_id = response.json['data']['id']
self.assertEqual(response.status, '201 Created')

with open('docs/source/tutorial/patch-cancellation.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}/cancellations/{}/documents/{}?acc_token={}'.format(
self.tender_id, cancellation_id, cancellation_doc_id, owner_token), {'data': {"description": 'Changed description'}} )
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/update-cancellation-doc.http', 'w') as self.app.file_obj:
response = self.app.put('/tenders/{}/cancellations/{}/documents/{}?acc_token={}'.format(
self.tender_id, cancellation_id, cancellation_doc_id, owner_token), upload_files=[('file', 'Notice-2.pdf', 'content2')])
self.assertEqual(response.status, '200 OK')

#### Activating the request and cancelling tender
#

with open('docs/source/tutorial/active-cancellation.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}/cancellations/{}?acc_token={}'.format(
self.tender_id, cancellation_id, owner_token), {"data":{"status":"active"}})
self.assertEqual(response.status, '200 OK')
41 changes: 15 additions & 26 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Exploring basic rules

Let's try exploring the `/tenders` endpoint:

.. include:: tutorial/initial-tender-listing.http
.. include:: tutorial/tender-listing.http
:code:

Just invoking it reveals empty set.
Expand Down Expand Up @@ -55,11 +55,11 @@ Let's access the URL of the created object (the `Location` header of the respons

.. XXX body is empty for some reason (printf fails)
We can see the same response we got after creating tender.
We can see the same response we got after creating tender.

Let's see what listing of tenders reveals us:

.. include:: tutorial/tender-listing.http
.. include:: tutorial/tender-listing-no-auth.http
:code:

We do see the internal `id` of a tender (that can be used to construct full URL by prepending `http://api-sandbox.openprocurement.org/api/0/tenders/`) and its `dateModified` datestamp.
Expand Down Expand Up @@ -104,7 +104,7 @@ follow the :ref:`upload` rules.
.. include:: tutorial/upload-tender-notice.http
:code:

`201 Created` response code and `Location` header confirm document creation.
`201 Created` response code and `Location` header confirm document creation.
We can additionally query the `documents` collection API endpoint to confirm the
action:

Expand Down Expand Up @@ -257,47 +257,36 @@ See :ref:`cancellation` data structure for details.
Preparing the cancellation request
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code::
POST /tenders/{id}/cancellations
You should pass `reason`, `status` defaults to `pending`.
You should pass `reason`, `status` defaults to `pending`.

`id` is autogenerated and passed in the `Location` header of response.

.. code::
Location: /tenders/{id}/cancellations/{cancellation-id}
.. include:: tutorial/prepare-cancellation.http
:code:

Filling cancellation with protocol and supplementary documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Upload the file contents

.. code::
POST /tenders/{id}/cancellations/{cancellation-id}/documents
.. include:: tutorial/upload-cancellation-doc.http
:code:

Change the document description and other properties

.. code::

PATCH /tenders/{id}/cancellations/{cancellation-id}/documents/{document-id}
.. include:: tutorial/patch-cancellation.http
:code:

Upload new version of the document

.. code::

PUT /tenders/{id}/cancellations/{cancellation-id}/documents/{document-id}
.. include:: tutorial/update-cancellation-doc.http
:code:

Activating the request and cancelling tender
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code::
PATCH /tenders/{id}/cancellations/{cancellation-id}
{“data”:{“status”:”active”}}
.. include:: tutorial/active-cancellation.http
:code:

0 comments on commit eef2586

Please sign in to comment.