Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ktarasz committed Apr 28, 2016
1 parent 2978879 commit 62a09af
Show file tree
Hide file tree
Showing 17 changed files with 1,041 additions and 51 deletions.
137 changes: 107 additions & 30 deletions docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from openprocurement.api.models import get_now
import openprocurement.contracting.api.tests.base as base_test
from openprocurement.api.tests.base import PrefixedRequestClass
from openprocurement.contracting.api.tests.base import BaseWebTest
from openprocurement.api.tests.base import PrefixedRequestClass, BaseTenderWebTest
from openprocurement.contracting.api.tests.base import test_contract_data
from webtest import TestApp

from openprocurement.api.tests.base import test_tender_data, test_organization



Expand Down Expand Up @@ -47,8 +46,8 @@ def do_request(self, req, status=None, expect_errors=None):
return resp


class TenderResourceTest(BaseWebTest):
initial_auth = ('Basic', ('databridge', ''))
class TenderResourceTest(BaseTenderWebTest):

# ('Basic', ('broker', ''))
initial_data = test_contract_data

Expand All @@ -61,53 +60,131 @@ def setUp(self):
self.db = self.app.app.registry.db

def test_docs(self):
request_path = '/contracts'

self.app.authorization = ('Basic', ('broker', ''))
# empty tenders listing
response = self.app.get('/tenders')
self.assertEqual(response.json['data'], [])
# create tender
response = self.app.post_json('/tenders',
{"data": test_tender_data})
tender_id = self.tender_id = response.json['data']['id']
owner_token = response.json['access']['token']
# switch to active.tendering
response = self.set_status('active.tendering', {"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}})
self.assertIn("auctionPeriod", response.json['data'])
# create bid
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json('/tenders/{}/bids'.format(tender_id),
{'data': {'tenderers': [test_organization], "value": {"amount": 500}}})
# switch to active.qualification
self.set_status('active.auction', {'status': 'active.tendering'})
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(tender_id), {"data": {"id": tender_id}})
self.assertNotIn('auctionPeriod', response.json['data'])
# get awards
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.get('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token))
# get pending award
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending'][0]
# set award as active
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, owner_token), {"data": {"status": "active"}})
# get contract id
response = self.app.get('/tenders/{}'.format(tender_id))
contract_id = response.json['data']['contracts'][-1]['id']
# after stand slill period
self.app.authorization = ('Basic', ('chronograph', ''))
self.set_status('complete', {'status': 'active.awarded'})
# time travel
tender = self.db.get(tender_id)
for i in tender.get('awards', []):
i['complaintPeriod']['endDate'] = i['complaintPeriod']['startDate']
self.db.save(tender)
# sign contract
self.app.authorization = ('Basic', ('broker', ''))
self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(tender_id, contract_id, owner_token), {"data": {"status": "active"}})
# check status
self.app.authorization = ('Basic', ('broker', ''))
with open('docs/source/tutorial/example_tender.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}'.format(tender_id))
self.assertEqual(response.json['data']['status'], 'complete')

with open('docs/source/tutorial/example_contract.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/contracts/{}'.format(tender_id, response.json['data']['contracts'][0]['id']))
test_contract_data = response.json['data']

self.app.authorization = ('Basic', ('contracting', ''))
response = self.app.get('/tenders/{}/extract_credentials'.format(tender_id))
test_contract_data['owner'] = response.json['data']['owner']
test_contract_data['tender_token'] = response.json['data']['tender_token']
test_contract_data['tender_id'] = tender_id

request_path = '/contracts'
#### Exploring basic rules
#

with open('docs/source/tutorial/contracts-listing.http', 'w') as self.app.file_obj:
with open('docs/source/tutorial/contracts-listing-0.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.file_obj.write("\n")

with open('docs/source/tutorial/contract-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')

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

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

#### Creating tender
#### Sync contract
#
self.app.authorization = ('Basic', ('contracting', ''))

with open('docs/source/tutorial/contract-post-attempt-json-data.http', 'w') as self.app.file_obj:
response = self.app.post_json('/contracts?opt_pretty=1', {"data": test_contract_data})
with open('docs/source/tutorial/contract-create.http', 'w') as self.app.file_obj:
response = self.app.post_json(request_path, {"data": test_contract_data})
self.assertEqual(response.status, '201 Created')

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

tender = response.json['data']
owner_token = response.json['access']['token']
with open('docs/source/tutorial/contract-view.http', 'w') as self.app.file_obj:
response = self.app.get('/contracts/{}'.format(test_contract_data['id']))
self.assertEqual(response.status, '200 OK')


with open('docs/source/tutorial/contract-json-data-view.http', 'w') as self.app.file_obj:
response = self.app.get('/contracts/{}'.format(tender['id']))
self.assertEqual(response.status, '200 OK')

with open('docs/source/tutorial/contract-listing-no-auth.http', 'w') as self.app.file_obj:
with open('docs/source/tutorial/contracts-listing-1.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', ('broker', ''))

#### Modifying tender
#
with open('docs/source/tutorial/contract-credentials.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/contracts/{}/credentials?acc_token={}'.format(test_contract_data['id'], owner_token))
self.assertEqual(response.status, '200 OK')
contract_token = response.json['access']['token']
contract_id = test_contract_data['id']


with open('docs/source/tutorial/contract-documents.http', 'w') as self.app.file_obj:
response = self.app.get('/contracts/{}/documents?acc_token={}'.format(
contract_id, contract_token))

with open('docs/source/tutorial/upload-contract-document.http', 'w') as self.app.file_obj:
response = self.app.post('/contracts/{}/documents?acc_token={}'.format(
contract_id, contract_token), upload_files=[('file', u'contract.doc', 'content')])

with open('docs/source/tutorial/upload-contract-document-2.http', 'w') as self.app.file_obj:
response = self.app.post('/contracts/{}/documents?acc_token={}'.format(
contract_id, contract_token), upload_files=[('file', u'contract_update.doc', 'content')])

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

with open('docs/source/tutorial/upload-contract-document-3.http', 'w') as self.app.file_obj:

response = self.app.put('/contracts/{}/documents/{}?acc_token={}'.format(
contract_id, doc_id, contract_token),
upload_files=[('file', 'contract_update.doc', 'content2')])

with open('docs/source/tutorial/get-contract-document-3.http', 'w') as self.app.file_obj:

response = self.app.get('/contracts/{}/documents/{}?acc_token={}'.format(contract_id, doc_id, contract_token))

with open('docs/source/tutorial/contracts-patch.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/contracts/{}?acc_token={}'.format(contract_id, contract_token),
{"data": {"title": "New Title"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['title'], "New Title")
44 changes: 23 additions & 21 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Exploring basic rules

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

.. include:: tutorial/contracrts-listing.http
.. include:: tutorial/contracts-listing-0.http
:code:

Just invoking it reveals an empty set.

Contract is transferred from the tender system by an automated process.


.. index:: Contracts

Creating contract
Expand All @@ -26,15 +27,28 @@ Let's say that we have conducted tender and it has ``complete`` status. When the

Getting contract
----------------
Contract in the tenders system

.. include:: tutorial/example_contract.http
:code:

Let's access the URL of the created object:

.. include:: tutorial/contract-view.http
:code:

Для того щоб отримати створений обєкт майданчиком необхідно `PATCH: /contracts/{id}/credentials?acc_token={tender_token}`
id - ідентифікатор контракту
tender_token - токен тендера (використовується для генерування токена контракту)

Let's access the URL of the created object (the `Location` header of the response):
У відповіді буде access.token для контракту, який буде використовуватись для модифікації контракту

.. include:: tutorial/blank-contract-view.http
.. include:: tutorial/contract-credentials.http
:code:

Let's see what listing of contracts reveals us:

.. include:: tutorial/contract-listing-no-auth.http
.. include:: tutorial/contracts-listing-1.http
:code:

We do see the internal `id` of a contract (that can be used to construct full URL by prepending `http://api-sandbox.openprocurement.org/api/0/contracts/`) and its `dateModified` datestamp.
Expand All @@ -46,25 +60,18 @@ Modifying contract

Let's update contract by supplementing it with all other essential properties.

.. include:: tutorial/patch-items-value-periods.http
.. include:: tutorial/contracts-patch.http
:code:

We see the added properties have merged with existing contract data. Additionally, the `dateModified` property was updated to reflect the last modification datestamp.

Checking the listing again reflects the new modification date.

.. include:: tutorial/contract-listing-after-patch.http
:code:

.. index:: Document

Uploading documentation
-----------------------

Procuring entity can upload PDF files into the created contract. Uploading should
follow the :ref:`upload` rules.

.. include:: tutorial/upload-contract-notice.http
.. include:: tutorial/upload-contract-document.http
:code:

`201 Created` response code and `Location` header confirm document creation.
Expand All @@ -74,24 +81,19 @@ action:
.. include:: tutorial/contract-documents.http
:code:

The single array element describes the uploaded document. We can upload more documents:

.. include:: tutorial/upload-award-criteria.http
:code:

And again we can confirm that there are two documents uploaded.

.. include:: tutorial/contract-documents-2.http
.. include:: tutorial/upload-contract-document-2.http
:code:

In case we made an error, we can reupload the document over the older version:

.. include:: tutorial/update-award-criteria.http
.. include:: tutorial/upload-contract-document-3.http
:code:

And we can see that it is overriding the original version:

.. include:: tutorial/contract-documents-3.http
.. include:: tutorial/get-contract-document-3.http
:code:


Expand Down

0 comments on commit 62a09af

Please sign in to comment.