Code Monkey home page Code Monkey logo

backend_test's Introduction

Steps to set up the project.

  1. run " git clone https://github.com/ongraphpythondev/backend_test.git "
  2. move to the projet folder & create virtualenv using command "virtualenv venv"
  3. run "pip install -r requirements.txt".
  4. move to the project base dirctory
  5. run "python manage.py migrate"
  6. run django server "python manage.py runserver"

Now you have successfully run the server locally. You can test APIs using Postman or thunderclient

Unit Testing:

  1. You can run test using "python manage.py test" (don't need to run django server)

Assumptions:

  1. User can be seller or buyer both.
  2. User can publish the bonds, A uuid will be generated for each bond and linked to user(seller) who published the bond.
  3. Only authenticated user can access the all APIs.
  4. User can't see bonds publised by himself.
  5. User can't buy his own bond.
  6. User can't buy bond if some user buy the bond already.

Here is the list of all endpoints & their request body

  1. POST -> http://127.0.0.1:8000/api/signup

    json body:

      {
       "email":"[email protected]",
       "password":"vip12345"
       }
    

    Status: 200 OK

    Response body:

    {
      "message": "user created"
    }
    
  2. POST -> http://127.0.0.1:8000/api/login

    json body:

      {
       "email":"[email protected]",
       "password":"vip12345"
       }
    

    Status: 200 OK

    Response body:

    {
      "message": "logged in",
      "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE"
    }
    
  3. POST -> http://127.0.0.1:8000/api/publishbond

    json body:

    {
    "name":"Bondtypeorname",
    "price":31,
    "number_of_bond": 3
    }
    

    Headers:

    {
        "Accept": "application/json",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" 
    }
    

    Status: 200 OK

    Response body:

    {
      "message": "bond published",
      "uuid": "3890427a-9662-438e-a447-1e653b9a10ac"
    }
    
  4. GET -> http://127.0.0.1:8000/api/bondlist json body: None

    Headers:

     {
         "Accept": "application/json",
         "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" 
     }
    

    Status: 200 OK

    Response body:

         {
         "bonds": [
         {
           "id": "fbedc5e9-67df-47e1-9514-066341b27acc",
           "name": "Befdsffdfw",
           "price": "310.0000",
           "number_of_bond": 3,
           "seller_id": 1,
           "buyer_id": null
         },
         {
           "id": "f78ea895-9289-449b-93c0-55c17550558a",
           "name": "Befdsffdsffdfw",
           "price": "310.0000",
           "number_of_bond": 3,
           "seller_id": 2,
           "buyer_id": 3
         }
       ]
     }
    
  5. GET -> http://127.0.0.1:8000/api/listinusdollar

    json body: None

    Headers:

    {
        "Accept": "application/json",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" 
    }
    

    Status: 200 OK

    Response body:

    {
    "bonds": [
    {
      "id": "fbedc5e9-67df-47e1-9514-066341b27acc",
      "name": "Befdsffdfw",
      "price": 15.3766,
      "number_of_bond": 3,
      "seller_id": 1,
      "buyer_id": 3
    },
    {
      "id": "f78ea895-9289-449b-93c0-55c17550558a",
      "name": "Befdsffdsffdfw",
      "price": 15.3766,
      "number_of_bond": 3,
      "seller_id": 2,
      "buyer_id": 2
    },
    {
      "id": "3890427a-9662-438e-a447-1e653b9a10ac",
      "name": "Befdsffdfw",
      "price": 15.3766,
      "number_of_bond": 3,
      "seller_id": 3,
      "buyer_id": null
    }
     ]
    

    }

  6. POST -> http://127.0.0.1:8000/api/buybound

    json body:

    {
    "id":"fbedc5e9-67df-47e1-9514-066341b27acc" #uuid of bond
    }
    

    Headers:

    {
        "Accept": "application/json",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" 
    }
    

    Status: 200 OK

    Response body:

    { 'message':'bond bought successfully' }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.