Merge pull request #37 from bigchaindb/develop

release 0.1.1
This commit is contained in:
Rodolphe Marques 2016-02-15 10:48:53 +01:00
commit 2a025448b2
17 changed files with 210 additions and 112 deletions

View File

@ -1,14 +1,22 @@
sudo: required sudo: required
language: python language: python
python: 3.5 python:
- 3.4
services: - 3.5
- docker
before_install: before_install:
- pip install codecov - source /etc/lsb-release
- docker-compose build - echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee -a /etc/apt/sources.list.d/rethinkdb.list
- wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
- sudo apt-get update -qq
script: docker-compose run --rm bigchain py.test -v --cov=bigchaindb install:
- sudo apt-get install rethinkdb
- pip install -e .[test]
- pip install codecov
before_script: rethinkdb --daemon
script: py.test -v --cov=bigchaindb
after_success: codecov after_success: codecov

View File

@ -1,6 +1,9 @@
# BigchainDB # BigchainDB
[![Build Status](https://travis-ci.org/bigchaindb/bigchaindb.svg?branch=develop)](https://travis-ci.org/bigchaindb/bigchaindb) [![PyPI](https://img.shields.io/pypi/v/bigchaindb.svg)](https://pypi.python.org/pypi/BigchainDB)
[![Travis branch](https://img.shields.io/travis/bigchaindb/bigchaindb/develop.svg)](https://travis-ci.org/bigchaindb/bigchaindb)
[![Codecov branch](https://img.shields.io/codecov/c/github/bigchaindb/bigchaindb/develop.svg)](https://codecov.io/github/bigchaindb/bigchaindb?branch=develop)
[![Documentation Status](https://readthedocs.org/projects/bigchaindb/badge/?version=develop)](http://bigchaindb.readthedocs.org/en/develop/?badge=develop)
## Documentation ## Documentation
@ -8,8 +11,9 @@ Documentation is available at https://bigchaindb.readthedocs.org/
## Getting started ## Getting started
#### Install RethinkDB on Ubuntu ### Install RethinkDB
#### On Ubuntu
```sh ```sh
# install rethinkdb https://rethinkdb.com/docs/install/ubuntu/ # install rethinkdb https://rethinkdb.com/docs/install/ubuntu/
$ source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list $ source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
@ -21,12 +25,15 @@ $ sudo apt-get install rethinkdb
$ rethinkdb $ rethinkdb
``` ```
#### Install BigchainDB #### On other platforms
To install RethinkDB on other platform, please refer to [the official documentation](https://rethinkdb.com/docs/install/).
### Install BigchainDB
```sh ```sh
$ pip install bigchaindb $ pip install bigchaindb
``` ```
#### Running BigchainDB ### Running BigchainDB
Currently BigchainDB only supports Python 3.4+ Currently BigchainDB only supports Python 3.4+

View File

@ -7,6 +7,7 @@ import rapidjson
from datetime import datetime from datetime import datetime
import bigchaindb import bigchaindb
import bigchaindb.config_utils
from bigchaindb import exceptions from bigchaindb import exceptions
from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair

View File

@ -5,12 +5,11 @@ import logging
import rethinkdb as r import rethinkdb as r
import bigchaindb import bigchaindb
from bigchaindb import exceptions
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DatabaseAlreadyExistsException(Exception):
pass
def get_conn(): def get_conn():
'''Get the connection to the database.''' '''Get the connection to the database.'''
@ -24,15 +23,11 @@ def init():
dbname = bigchaindb.config['database']['name'] dbname = bigchaindb.config['database']['name']
if r.db_list().contains(dbname).run(conn): if r.db_list().contains(dbname).run(conn):
raise DatabaseAlreadyExistsException('Database `{}` already exists'.format(dbname)) raise exceptions.DatabaseAlreadyExists('Database `{}` already exists'.format(dbname))
logger.info('Create:') logger.info('Create:')
logger.info(' - database `%s`', dbname) logger.info(' - database `%s`', dbname)
try: r.db_create(dbname).run(conn)
r.db_create(dbname).run(conn)
except r.ReqlOpFailedError as e:
logger.info(e.message)
return
logger.info(' - tables') logger.info(' - tables')
# create the tables # create the tables
@ -83,7 +78,7 @@ def drop(assume_yes=False):
logger.info('Drop database `%s`', dbname) logger.info('Drop database `%s`', dbname)
r.db_drop(dbname).run(conn) r.db_drop(dbname).run(conn)
logger.info('Done.') logger.info('Done.')
except r.ReqlOpFailedError as e: except r.ReqlOpFailedError:
logger.info(e.message) raise exceptions.DatabaseDoesNotExist('Database `{}` does not exist'.format(dbname))
else: else:
logger.info('Drop aborted') logger.info('Drop aborted')

View File

@ -19,3 +19,9 @@ class InvalidHash(Exception):
class InvalidSignature(Exception): class InvalidSignature(Exception):
"""Raised if there was an error checking the signature for a particular operation""" """Raised if there was an error checking the signature for a particular operation"""
class DatabaseAlreadyExists(Exception):
"""Raised when trying to create the database but the db is already there"""
class DatabaseDoesNotExist(Exception):
"""Raised when trying to delete the database but the db is not there"""

View File

@ -12,7 +12,7 @@ rethinkdb-data:
- /data - /data
command: "true" command: "true"
bigchain: bigchaindb:
build: . build: .
volumes: volumes:
- ./:/usr/src/app/ - ./:/usr/src/app/
@ -20,4 +20,4 @@ bigchain:
- rethinkdb - rethinkdb
environment: environment:
BIGCHAIN_DATABASE_HOST: rethinkdb BIGCHAIN_DATABASE_HOST: rethinkdb
command: bigchain start command: bigchaindb start

View File

@ -15,14 +15,13 @@ Table of Contents
installing installing
getting-started getting-started
admin admin
contributing
faq
release-notes
software-architecture
cryptography cryptography
models models
json-serialization json-serialization
developer-interface developer-interface
contributing
faq
release-notes
Indices and Tables Indices and Tables

View File

@ -1,64 +1,62 @@
# Installing BigchainDB # Installing BigchainDB
BigchainDB works on top of [rethinkDB](http://rethinkdb.com/) server. In order to use We're developing BigchainDB on Ubuntu 14.04, but it should work on any OS that runs RethinkDB Server and Python 3.4+. (BigchainDB is built on top of RethinkDB Server.)
BigchainDB we first need to install rethinkDB server.
##### Installing and running rethinkDB server on Ubuntu >= 12.04 ## Install and Run RethinkDB Server
Rethinkdb provides binaries for all major distros. For ubuntu we only need to The RethinkDB documentation has instructions for how to install RethinkDB Server on a variety of operating systems. Do that (using their instructions for your OS): [Install RethinkDB Server](http://rethinkdb.com/docs/install/).
add the [RethinkDB repository](http://download.rethinkdb.com/apt/) to our list
of repositories and install via `apt-get`
```shell
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt
$DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install rethinkdb
```
For more information, rethinkDB provides [detailed
instructions](http://rethinkdb.com/docs/install/) on how to install in a variety
of systems.
RethinkDB does not require any special configuration. To start rethinkdb server
just run this command on the terminal.
RethinkDB Server doesn't require any special configuration. You can run it by opening a Terminal and entering:
```shell ```shell
$ rethinkdb $ rethinkdb
``` ```
##### Installing and running BigchainDB ## Install Python 3.4+
BigchainDB is distributed as a python package. Installing is simple using `pip`
If you don't already have it, then you should [install Python 3.4+](https://www.python.org/downloads/) (maybe in a virtual environment, so it doesn't conflict with other Python projects you're working on).
## Install BigchainDB
BigchainDB has some OS-level dependencies. In particular, you need to install the OS-level dependencies for the Python **cryptography** package. Instructions for installing those dependencies on your OS can be found in the [cryptography package documentation](https://cryptography.io/en/latest/installation/).
On Ubuntu 14.04, we found that the following was enough (YMMV):
```shell
$ sudo apt-get update
$ sudo apt-get install libffi-dev g++ libssl-dev
```
With OS-level dependencies installed, you can install BigchainDB with `pip` or from source.
### How to Install BigchainDB with `pip`
BigchainDB is distributed as a Python package on PyPI. Installing is simple using `pip`:
```shell ```shell
$ pip install bigchaindb $ pip install bigchaindb
``` ```
After installing BigchainDB we can run it with: ### How to Install BigchainDB from Source
BigchainDB is in its early stages and being actively developed on its [GitHub repository](https://github.com/bigchaindb/bigchaindb). Contributions are highly appreciated.
Clone the public repository:
```shell ```shell
$ bigchaindb start $ git clone git@github.com:bigchaindb/bigchaindb.git
``` ```
During the first run BigchainDB takes care of configuring a single node Install from the source:
environment.
##### Installing from source
BigchainDB is in its early stages and being actively developed on its [GitHub
repository](https://github.com/BigchainDB/bigchaindb). Contributions are highly
appreciated.
Clone the public repository
```shell
$ git clone git@github.com:BigchainDB/bigchaindb.git
```
Install from the source
```shell ```shell
$ python setup.py install $ python setup.py install
``` ```
##### Installing with Docker ### How to Install BigchainDB Using Docker
Coming soon... Coming soon...
## Run BigchainDB
After installing BigchainDB, run it with:
```shell
$ bigchaindb start
```
During its first run, BigchainDB takes care of configuring a single node environment.

View File

@ -1,3 +1,7 @@
# Release Notes # Release Notes
This section has the release notes for each version of BigchainDB. You can find a list of all BigchainDB releases and release notes on GitHub at:
[https://github.com/bigchaindb/bigchaindb/releases](https://github.com/bigchaindb/bigchaindb/releases)
We also have [a roadmap document in bigchaindb/ROADMAP.md](https://github.com/bigchaindb/bigchaindb/blob/develop/ROADMAP.md).

View File

@ -1,6 +0,0 @@
Test
====
This is a test page.
This is a test sentence.

View File

@ -1 +0,0 @@
-r requirements/common.txt

View File

@ -1,9 +0,0 @@
-r common.txt
pytest==2.8.2
pytest-cov
coverage
codecov
pep8
pyflakes
pylint

View File

@ -1,12 +0,0 @@
rethinkdb==2.2.0.post1
pysha3==0.3
pytz==2015.7
repoze.lru==0.6
fake-factory==0.5.3
tornado==4.3
cryptography==1.2.1
statsd==3.2.1
python-rapidjson==0.0.6
logstats==0.2.1
base58==0.2.2
bitcoin==1.1.42

View File

@ -6,9 +6,19 @@ For full docs visit https://bigchaindb.readthedocs.org
""" """
from setuptools import setup from setuptools import setup
tests_require = [
'pytest',
'coverage',
'pep8',
'pyflakes',
'pylint',
'pytest',
'pytest-cov',
]
setup( setup(
name='BigchainDB', name='BigchainDB',
version='0.0.0', version='0.1.1',
description='BigchainDB: A Scalable Blockchain Database', description='BigchainDB: A Scalable Blockchain Database',
long_description=__doc__, long_description=__doc__,
url='https://github.com/BigchainDB/bigchaindb/', url='https://github.com/BigchainDB/bigchaindb/',
@ -37,7 +47,6 @@ setup(
'rethinkdb==2.2.0.post1', 'rethinkdb==2.2.0.post1',
'pysha3==0.3', 'pysha3==0.3',
'pytz==2015.7', 'pytz==2015.7',
'tornado==4.3',
'cryptography==1.2.1', 'cryptography==1.2.1',
'statsd==3.2.1', 'statsd==3.2.1',
'python-rapidjson==0.0.6', 'python-rapidjson==0.0.6',
@ -46,5 +55,6 @@ setup(
'bitcoin==1.1.42', 'bitcoin==1.1.42',
], ],
setup_requires=['pytest-runner'], setup_requires=['pytest-runner'],
tests_require=['pytest'], tests_require=tests_require,
extras_require={'test': tests_require},
) )

View File

@ -25,8 +25,6 @@ def setup_database(request):
r.db_create('bigchain_test').run() r.db_create('bigchain_test').run()
except r.ReqlOpFailedError as e: except r.ReqlOpFailedError as e:
if e.message == 'Database `bigchain_test` already exists.': if e.message == 'Database `bigchain_test` already exists.':
print(e.message)
print('Deleting `bigchain_test` database.')
r.db_drop('bigchain_test').run() r.db_drop('bigchain_test').run()
r.db_create('bigchain_test').run() r.db_create('bigchain_test').run()
else: else:
@ -52,7 +50,12 @@ def setup_database(request):
def fin(): def fin():
print('Deleting `bigchain_test` database') print('Deleting `bigchain_test` database')
get_conn().repl() get_conn().repl()
r.db_drop('bigchain_test').run() try:
r.db_drop('bigchain_test').run()
except r.ReqlOpFailedError as e:
if e.message != 'Database `bigchain_test` does not exist.':
raise
print('Finished deleting `bigchain_test`') print('Finished deleting `bigchain_test`')
request.addfinalizer(fin) request.addfinalizer(fin)
@ -62,8 +65,12 @@ def setup_database(request):
def cleanup_tables(request): def cleanup_tables(request):
def fin(): def fin():
get_conn().repl() get_conn().repl()
r.db('bigchain_test').table('bigchain').delete().run() try:
r.db('bigchain_test').table('backlog').delete().run() r.db('bigchain_test').table('bigchain').delete().run()
r.db('bigchain_test').table('backlog').delete().run()
except r.ReqlOpFailedError as e:
if e.message != 'Database `bigchain_test` does not exist.':
raise
request.addfinalizer(fin) request.addfinalizer(fin)

98
tests/db/test_utils.py Normal file
View File

@ -0,0 +1,98 @@
import builtins
import pytest
import rethinkdb as r
import bigchaindb
from bigchaindb.db import utils
from .conftest import setup_database as _setup_database
# Since we are testing database initialization and database drop,
# we need to use the `setup_database` fixture on a function level
@pytest.fixture(scope='function', autouse=True)
def setup_database(request):
_setup_database(request)
def test_init_creates_db_tables_and_indexes():
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures so we need to remove it
r.db_drop(dbname).run(conn)
utils.init()
assert r.db_list().contains(dbname).run(conn) == True
assert r.db(dbname).table_list().contains('backlog', 'bigchain').run(conn) == True
assert r.db(dbname).table('bigchain').index_list().contains(
'block_timestamp',
'block_number').run(conn) == True
assert r.db(dbname).table('backlog').index_list().contains(
'transaction_timestamp',
'assignee__transaction_timestamp').run(conn) == True
def test_init_fails_if_db_exists():
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname) == True
with pytest.raises(bigchaindb.exceptions.DatabaseAlreadyExists):
utils.init()
def test_drop_interactively_drops_the_database_when_user_says_yes(monkeypatch):
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname).run(conn) == True
monkeypatch.setattr(builtins, 'input', lambda x: 'y')
utils.drop()
assert r.db_list().contains(dbname).run(conn) == False
def test_drop_programmatically_drops_the_database_when_assume_yes_is_true(monkeypatch):
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname).run(conn) == True
utils.drop(assume_yes=True)
assert r.db_list().contains(dbname).run(conn) == False
def test_drop_interactively_does_not_drop_the_database_when_user_says_no(monkeypatch):
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
print(r.db_list().contains(dbname).run(conn))
assert r.db_list().contains(dbname).run(conn) == True
monkeypatch.setattr(builtins, 'input', lambda x: 'n')
utils.drop()
assert r.db_list().contains(dbname).run(conn) == True
def test_drop_non_existent_db_raises_an_error():
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname).run(conn) == True
utils.drop(assume_yes=True)
with pytest.raises(bigchaindb.exceptions.DatabaseDoesNotExist):
utils.drop(assume_yes=True)

View File

@ -1,7 +0,0 @@
[tox]
skipsdist = true
envlist = py35
[testenv]
commands = py.test -v --cov=bigchaindb
deps = -rrequirements/ci.txt