Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/1147/consolidate-root-urls'…
Browse files Browse the repository at this point in the history
… into feat/1531/consistent-naming
  • Loading branch information
r-marques committed Jun 14, 2017
2 parents 05a6653 + 27b1292 commit fa04899
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
47 changes: 27 additions & 20 deletions bigchaindb/web/views/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ def get(self):
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__ + '/'
]
api_v1_url = base_url() + 'api/v1/'
return flask.jsonify({
'_links': {
'docs': ''.join(docs_url),
'api_v1': api_v1_url,
'api': {
'v1': get_api_v1_info()
},
'docs': ''.join(docs_url),
'software': 'BigchainDB',
'version': version.__version__,
'public_key': bigchaindb.config['keypair']['public'],
Expand All @@ -30,19 +29,27 @@ def get(self):

class ApiV1Index(Resource):
def get(self):
api_root = base_url() + 'api/v1/'
websocket_root = base_ws_uri() + EVENTS_ENDPOINT
docs_url = [
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__,
'/http-client-server-api.html',
]
return flask.jsonify({
'_links': {
'docs': ''.join(docs_url),
'self': api_root,
'statuses': api_root + 'statuses/',
'transactions': api_root + 'transactions/',
'streams_v1': websocket_root,
},
})
return flask.jsonify(get_api_v1_info())


def get_api_v1_info():
"""
Return a dict with all the information specific for the v1 of the
api.
"""
api_root = base_url() + 'api/v1/'
websocket_root = base_ws_uri() + EVENTS_ENDPOINT
docs_url = [
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__,
'/http-client-server-api.html',
]

return {
'docs': ''.join(docs_url),
'transactions': api_root + 'transactions/',
'statuses': api_root + 'statuses/',
'assets': api_root + 'assets/',
'outputs': api_root + 'outputs/',
'streams': websocket_root
}
10 changes: 4 additions & 6 deletions docs/server/source/websocket-event-stream-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ It's a good idea to make sure that the node you're connecting with
has advertised support for the Event Stream API. To do so, send a HTTP GET
request to the node's :ref:`API Root Endpoint`
(e.g. ``http://localhost:9984/api/v1/``) and check that the
response contains a ``streams_<version>`` property in ``_links``:
response contains a ``streams`` property:

.. code:: JSON
{
"_links": {
...,
"streams_v1": "ws://example.com:9985/api/v1/streams/valid_tx",
...
}
...,
"streams": "ws://example.com:9985/api/v1/streams/valid_tx",
...
}
Expand Down
40 changes: 23 additions & 17 deletions tests/web/test_info.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
from unittest import mock

import pytest


@pytest.fixture
def api_v1_info():
docs_url = ['https://docs.bigchaindb.com/projects/server/en/vtsttst',
'/http-client-server-api.html',
]
return {
'docs': ''.join(docs_url),
'transactions': 'http://localhost/api/v1/transactions/',
'statuses': 'http://localhost/api/v1/statuses/',
'assets': 'http://localhost/api/v1/assets/',
'outputs': 'http://localhost/api/v1/outputs/',
'streams': 'ws://localhost:9985/api/v1/streams/valid_tx',
}


@mock.patch('bigchaindb.version.__short_version__', 'tst')
@mock.patch('bigchaindb.version.__version__', 'tsttst')
@mock.patch('bigchaindb.config', {'keyring': ['abc'], 'keypair': {'public': 'def'}})
def test_api_root_endpoint(client):
def test_api_root_endpoint(client, api_v1_info):
res = client.get('/')
assert res.json == {
'_links': {
'docs': 'https://docs.bigchaindb.com/projects/server/en/vtsttst/',
'api_v1': 'http://localhost/api/v1/',
'api': {
'v1': api_v1_info
},
'docs': 'https://docs.bigchaindb.com/projects/server/en/vtsttst/',
'version': 'tsttst',
'keyring': ['abc'],
'public_key': 'def',
Expand All @@ -20,17 +37,6 @@ def test_api_root_endpoint(client):

@mock.patch('bigchaindb.version.__short_version__', 'tst')
@mock.patch('bigchaindb.version.__version__', 'tsttst')
def test_api_v1_endpoint(client):
def test_api_v1_endpoint(client, api_v1_info):
res = client.get('/api/v1')
docs_url = ['https://docs.bigchaindb.com/projects/server/en/vtsttst',
'/http-client-server-api.html',
]
assert res.json == {
'_links': {
'docs': ''.join(docs_url),
'self': 'http://localhost/api/v1/',
'statuses': 'http://localhost/api/v1/statuses/',
'transactions': 'http://localhost/api/v1/transactions/',
'streams_v1': 'ws://localhost:9985/api/v1/streams/valid_tx',
}
}
assert res.json == api_v1_info

0 comments on commit fa04899

Please sign in to comment.