/testbonos

test bonos

Primary LanguagePython

testbonos

To run the example do the following steps:

$ mkdir bonos
$ cd bonos/

Tested with:

$ python -V
Python 3.5.3
$ python -V
Python 3.8.11

Should work with any python version > 3.5.3

Create the virtual environment

$ python3 -m venv venv

Activate the virtual environment

$ . venv/bin/activate

Upgrade pip and install wheel

$ pip install --upgrade pip
$ pip install wheel

Clone the git repository

$ git clone https://github.com/jboadas/testbonos

Install libraries of the example

$ cd testbonos/
$ pip install -r requirements.txt 

Create the database

$ python manage.py migrate

Run tests

$ python manage.py test

Create admin user

python manage.py createsuperuser --email admin@example.com --username admin

Run the development server

$ python manage.py runserver

Server will be available at: http://127.0.0.1:8000/

We can access the api using the Django interactive API explorer

Or using curl commands on the terminal:

View users

curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/users/

View bonds

curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/bonos/

Bond view detail

curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/bonos/4/

Publish bond to sell

curl -H 'Accept: application/json; indent=4' -u admin:password123 -F 'bono_name=ADMDOS' -F 'bono_number=5000' -F 'bono_price=9999.99' http://127.0.0.1:8000/bonos/

Buy bond (sell user/buy user need to be differents)

curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/bonos/4/comprabono/

Get bond USD price

curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/bonos/4/preciousd/