Skip to content

Commit

Permalink
Merge pull request #16 from kukirokuk/a679817978969388_assets_docs
Browse files Browse the repository at this point in the history
Fix tutorial
  • Loading branch information
leits committed May 22, 2018
2 parents f2a2947 + 7c88f0c commit ed5d7f6
Show file tree
Hide file tree
Showing 21 changed files with 1,231 additions and 509 deletions.
26 changes: 25 additions & 1 deletion docs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from uuid import uuid4
from copy import deepcopy

from openregistry.assets.core.tests.base import DumpsTestAppwebtest, PrefixedRequestClass
from openregistry.assets.bounce.tests.base import BaseAssetWebTest
from openregistry.assets.bounce.tests.json_data import test_asset_bounce_data


class AssetResourceTest(BaseAssetWebTest):
Expand All @@ -14,6 +16,9 @@ def setUp(self):
self.app.authorization = ('Basic', ('broker', ''))
self.couchdb_server = self.app.app.registry.couchdb_server
self.db = self.app.app.registry.db
self.initial_data = deepcopy(test_asset_bounce_data)
self.app.app.registry.docservice_url = 'http://localhost'
docservice = True

def test_docs_tutorial(self):
request_path = '/?opt_pretty=1'
Expand All @@ -39,6 +44,10 @@ def test_docs_tutorial(self):
#
with open('docs/source/tutorial/asset-post-2pc.http', 'w') as self.app.file_obj:
response = self.app.post_json(request_path, {"data": self.initial_data})
asset = response.json['data']
self.resource_id = asset['id']
self.token = response.json['access']['token']
self.access_header = {'X-Access-Token': str(self.token)}
self.assertEqual(response.status, '201 Created')

asset_id = response.json['data']['id']
Expand Down Expand Up @@ -100,7 +109,22 @@ def test_docs_tutorial(self):
response = self.app.get(request_path)
self.assertEqual(response.status, '200 OK')


# Add cancellationDetails document
test_document_data = {
# 'url': self.generate_docservice_url(),
'title': u'укр.doc',
'hash': 'md5:' + '0' * 32,
'format': 'application/msword',
'documentType': 'cancellationDetails'
}
test_document_data['url'] = self.generate_docservice_url()
with open('docs/source/tutorial/add_cancellation_document.http', 'w') as self.app.file_obj:
response = self.app.post_json('/{}/documents'.format(asset['id']),
headers=self.access_header,
params={'data': test_document_data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')

with open('docs/source/tutorial/delete-asset.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/{}?acc_token={}'.format(asset_id, owner_token),
{'data': {"status": "deleted"}})
Expand Down
4 changes: 4 additions & 0 deletions docs/source/assets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Getting list of all assets

**Example request**:

.. sourcecode:: http

GET /api/0/assets HTTP/1.0
Host: lb.api-sandbox.registry.ea2.openprocurement.net

**Example response**:

Expand Down
54 changes: 36 additions & 18 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ Exploring basic rules

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

***************
.. literalinclude:: tutorial/asset-listing.http
:language: javascript

Just invoking it reveals empty set.

Now let's attempt creating some asset:

***************
.. literalinclude:: tutorial/asset-post-attempt.http
:language: javascript

Error states that the only accepted Content-Type is `application/json`.

Let's satisfy the Content-type requirement:

***************
.. literalinclude:: tutorial/asset-post-attempt-json.http
:language: javascript

Error states that no `data` has been found in JSON body.

Expand All @@ -33,9 +36,11 @@ Creating asset

Let's create asset with the minimal (only required) data set:

***************
.. literalinclude:: tutorial/asset-post-2pc.http
:language: javascript

***************
.. literalinclude:: tutorial/asset-patch-2pc.http
:language: javascript

Success! Now we can see that new object was created. Response code is `201`
and `Location` response header reports the location of the created object. The
Expand All @@ -47,28 +52,32 @@ created with `pending` status.

Let's access the URL of the created object (the `Location` header of the response):

***************
.. literalinclude:: tutorial/blank-asset-view.http
:language: javascript

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

Let's see what listing of assets reveals us:

***************
.. literalinclude:: tutorial/initial-asset-listing.http
:language: javascript

We do see the internal `id` of a asset (that can be used to construct full URL by prepending `***************`) and its `dateModified` datestamp.
We do see the internal `id` of a asset (that can be used to construct full URL by prepending `http://lb.api-sandbox.registry.ea2.openprocurement.net/api/<api_version>/assets/`) and its `dateModified` datestamp.

The previous asset contained only required fields. Let's try creating asset with more data
(asset has status `created`):

***************
.. literalinclude:: tutorial/create-second-asset.http
:language: javascript

And again we have `201 Created` response code, `Location` header and body with extra `id`, `assetID`, and `dateModified` properties.

Let's check what asset registry contains:

***************
.. literalinclude:: tutorial/listing-with-some-assets.http
:language: javascript

And indeed we have 2 assets now.

Expand All @@ -77,33 +86,42 @@ Modifying Asset

Let's update asset description:

***************
.. literalinclude:: tutorial/patch-asset.http
:language: javascript

.. XXX body is empty for some reason (printf fails)
We see the added properies have merged with existing asset data. Additionally, the `dateModified` property was updated to reflect the last modification datestamp.

Checking the listing again reflects the new modification date:

***************
.. literalinclude:: tutorial/asset-listing-after-patch.http
:language: javascript

Deleting Asset
--------------

Let's delete asset:
Let's delete asset. First you need to add canellationDetails document:

***************
.. literalinclude:: tutorial/add_cancellation_document.http
:language: javascript

You see that the documentType: cancellationDetails is needed for the asset to be deleted.
And now asset can be easily deleted:

.. literalinclude:: tutorial/delete-asset.http
:language: javascript

Integration with lots
---------------------


***************
.. literalinclude:: tutorial/attached-to-lot-asset-view.http
:language: javascript


***************
.. literalinclude:: tutorial/detached-from-lot-asset-view.http
:language: javascript


***************
.. literalinclude:: tutorial/complete-asset-view.http
:language: javascript
36 changes: 36 additions & 0 deletions docs/source/tutorial/add_cancellation_document.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
POST /api/2.4/assets/5c8cd4c766c74f60b25b2b9cdbfb8ef7/documents HTTP/1.0
Authorization: Basic YnJva2VyOg==
Content-Length: 350
Content-Type: application/json
Host: lb.api-sandbox.registry.ea2.openprocurement.net
X-Access-Token: f9954df58b5c4f40a7ba11f1eae6063c
DATA:
{
"data": {
"url": "http://localhost/get/d569aea176a947e5abaf289e583cf96b?KeyID=9f887607&Signature=b4DgGl2WRakYWuEwJAZGbjbvN3Bu3cslLQJmcwXZzO%2FstWuhw75ZouJ5R7qEOU46OvwnAA1TO0s%2FRFWHAHOBBw%3D%3D",
"title": "укр.doc",
"format": "application/msword",
"hash": "md5:00000000000000000000000000000000",
"documentType": "cancellationDetails"
}
}

Response: 201 Created
Content-Type: application/json
Location: http://lb.api-sandbox.registry.ea2.openprocurement.net/api/2.4/assets/5c8cd4c766c74f60b25b2b9cdbfb8ef7/documents/c793551c2cdd483f89ac60d7ce36bc76
X-Content-Type-Options: nosniff
{
"data": {
"dateModified": "2018-05-22T13:40:23.403225+03:00",
"hash": "md5:00000000000000000000000000000000",
"format": "application/msword",
"url": "http://localhost/get/d569aea176a947e5abaf289e583cf96b?KeyID=9f887607&Signature=z3YrEXB8FwIR3ulRtu4lPjsEqD5kHKlH8rrCRG9kvJE6Ph%252Bjg%2FKou%252BxAsAhtlxFcKtYoAi8wMn0c1hf126IQDA%253D%253D",
"author": "asset_owner",
"documentOf": "asset",
"datePublished": "2018-05-22T13:40:23.403197+03:00",
"documentType": "cancellationDetails",
"title": "укр.doc",
"id": "c793551c2cdd483f89ac60d7ce36bc76"
}
}

18 changes: 8 additions & 10 deletions docs/source/tutorial/asset-listing-after-patch.http
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
GET /api/0.1/assets?opt_pretty=1 HTTP/1.0
GET /api/2.4/assets?opt_pretty=1 HTTP/1.0
Authorization: Basic YnJva2VyOg==
Host: lb.api-sandbox.registry.ea.openprocurement.net
Host: lb.api-sandbox.registry.ea2.openprocurement.net


200 OK
Response: 200 OK
Content-Type: application/json
X-Content-Type-Options: nosniff

{
"next_page": {
"path": "/api/0.1/assets?offset=2017-08-16T18%3A36%3A14.133838%2B03%3A00",
"uri": "http://lb.api-sandbox.registry.ea.openprocurement.net/api/0.1/assets?offset=2017-08-16T18%3A36%3A14.133838%2B03%3A00",
"offset": "2017-08-16T18:36:14.133838+03:00"
"path": "/api/2.4/assets?offset=2018-05-22T13%3A39%3A54.510132%2B03%3A00",
"uri": "http://lb.api-sandbox.registry.ea2.openprocurement.net/api/2.4/assets?offset=2018-05-22T13%3A39%3A54.510132%2B03%3A00",
"offset": "2018-05-22T13:39:54.510132+03:00"
},
"data": [
{
"id": "f7d85ded1544424d82a3473f9467f80f",
"dateModified": "2017-08-16T18:36:14.133838+03:00"
"id": "5c8cd4c766c74f60b25b2b9cdbfb8ef7",
"dateModified": "2018-05-22T13:39:54.510132+03:00"
}
]
}
Expand Down
12 changes: 5 additions & 7 deletions docs/source/tutorial/asset-listing.http
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
GET /api/0.1/assets HTTP/1.0
GET /api/2.4/assets?opt_pretty=1 HTTP/1.0
Authorization: Basic YnJva2VyOg==
Host: lb.api-sandbox.registry.ea.openprocurement.net
Host: lb.api-sandbox.registry.ea2.openprocurement.net


200 OK
Response: 200 OK
Content-Type: application/json
X-Content-Type-Options: nosniff

{
"next_page": {
"path": "/api/0.1/assets?offset=",
"uri": "http://lb.api-sandbox.registry.ea.openprocurement.net/api/0.1/assets?offset=",
"path": "/api/2.4/assets?offset=",
"uri": "http://lb.api-sandbox.registry.ea2.openprocurement.net/api/2.4/assets?offset=",
"offset": ""
},
"data": []
Expand Down

0 comments on commit ed5d7f6

Please sign in to comment.