API has the following features:
- GET /parcels
- GET /parcels/
- PUT /parcels//status
- PUT /parcels//cancel
- PUT /parcels//destination
- PUT /parcels//presentLocation
- GET /users//in-transit
- GET /users//delivered
- GET /users//parcels
- POST /parcels
- POST /auth/signup
- POST /auth/login
pip install virtualenv
- Open new folder
- Open Terminal on this folder
- Type
git clone https://github.com/mnswaleh/api_sendit.git .
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
on postreSQL database create
- apisendit database
- apitest database
install postman
- on terminal type
pytest - all the tests should pass
on terminal: type
export FLASK_APP=run.py flask run
- Enter URL http://127.0.0.1:5000/api/v2/auth/signup
- send post request with user details eg,
{
"username": "tom",
"first_name": "thomas",
"second_name": "Kalume",
"email": "mnswaleh@gmail.com",
"gender": "male",
"location": "kakamega",
"type": "user",
"password": "Ab243677"
}
- should receive response with code 201 with success message with user details eg,
{
"message": "Signup successul!",
"user": {
"email": "mnswaleh@gmail.com",
"firstname": "thomas",
"gender": "male",
"location": "kakamega",
"secondname": "Kalume",
"type": "user",
"user_id": 1,
"username": "tom"
}
}
- Enter URL http://127.0.0.1:5000/api/v2/auth/login
- send post request with username and password eg,
{
"username": "tom",
"password": "Ab243677"
}
- should receive response with code 201 with access token eg,
{
"Message": "Login Successful!",
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NDg0NDE3NTYsIm5iZiI6MTU0ODQ0MTc1NiwianRpIjoiYjJhNWZlYjYtZjYzMC00NDBiLWIwM2MtOTA1ODcxMDQ2ZTRmIiwiZXhwIjoxNTQ4NDQyNjU2LCJpZGVudGl0eSI6WzMsInVzZXIiXSwiZnJlc2giOmZhbHNlLCJ0eXBlIjoiYWNjZXNzIn0.Uj_cZzP8fsH9ETbfg3sEk4-QAjO7NlxHwtqZkeL2i-M",
"user": [
3,
"user"
]
}
- Enter URL http://127.0.0.1:5000/api/v2/auth/signup
- send post request with admin details eg,
{
"username": "sali",
"first_name": "sharon",
"second_name": "mimo",
"email": "mnswaleh@gmail.com",
"gender": "female",
"location": "karatina",
"type": "admin",
"password": "Wbc346789"
}
- should receive response with code 201 with success message with user details eg,
{
"message": "Signup successul!",
"user": {
"email": "mnswaleh@gmail.com",
"firstname": "sharon",
"gender": "female",
"location": "karatina",
"secondname": "mimo",
"type": "admin",
"user_id": 2,
"username": "sali"
}
}
- Enter URL http://127.0.0.1:5000/api/v2/auth/login
- send post request with username and password eg,
{
"username": "tom",
"password": "Ab243677"
}
- should receive response with code 201 with access token eg,
{
"Message": "Login Successful!",
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NDg0NDE3OTgsIm5iZiI6MTU0ODQ0MTc5OCwianRpIjoiMGQwYmE0MzAtNjlhZS00Y2U1LWEwNGYtMzZlMTc4NTU0OTgwIiwiZXhwIjoxNTQ4NDQyNjk4LCJpZGVudGl0eSI6WzIsImFkbWluIl0sImZyZXNoIjpmYWxzZSwidHlwZSI6ImFjY2VzcyJ9.Mc_jfZSDq1qHZxhV_5BHtaaRc78oeDbJdGyAYa6KQTU",
"user": [
2,
"admin"
]
}S6Q1LD0r6-5F0AFyKTS_bKgfo9SL8A8QZeyVDhCY4"
}
- Login as user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels
- send post request with delivery order eg,
{
"pick_up_location": "nyahururu",
"delivery_location": "kitale",
"weight": 2,
"price": 200
}
- should receive response with code 201 and order details eg,
{
"current_location": "nyahururu",
"delivery_location": "kitale",
"pick_up_location": "nyahururu",
"price": 200,
"sender": 1,
"status": "pending",
"weight": 2
}
- Login as admin
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels
- send get request
- should receive response with code 200 and all delivery orders created eg,
{
"Delivery orders list": [
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "nyahururu",
"destination": "kitale",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "pending",
"weight": 2
}
],
"Title": "Delivery orders"
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/users/1/parcels
- send get request
- should receive response with code 200 and all delivery orders created by user with user id 1 ie,
{
"Title": "Delivery orders by user 3",
"orders": [
{
"created": "Fri, 25 Jan 2019 00:00:00 GMT",
"current_location": "nyahururu",
"destination": "kitale",
"order_no": 26,
"pickup": "nyahururu",
"price": 200,
"sender": 3,
"status": "pending",
"weight": 2
},
{
"created": "Thu, 22 Nov 2018 00:00:00 GMT",
"current_location": "nyahururu",
"destination": "kitale",
"order_no": 5,
"pickup": "nyahururu",
"price": 200,
"sender": 3,
"status": "pending",
"weight": 1
},
{
"created": "Thu, 22 Nov 2018 00:00:00 GMT",
"current_location": "nyahururu",
"destination": "kitale",
"order_no": 6,
"pickup": "nyahururu",
"price": 200,
"sender": 3,
"status": "pending",
"weight": 10
}
]
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels/1
- send get request
- should receive response with code 200 and details of order 367857 ie,
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "nyahururu",
"destination": "kitale",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "pending",
"weight": 2
}
- Login as user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels/1/cancel
- send put request
- should receive response with code 200 and details of order 1 with status as canceled ie,
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "naivasha",
"destination": "kisumu",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "canceled",
"weight": 2
}
- Login as user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels/1/destination
- send put request with desired delivery location eg,
{
"delivery_location": "kisumu"
}
- should receive response with code 200 and details of order 1 with new delivery location eg,
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "naivasha",
"destination": "kisumu",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "in transit",
"weight": 2
}
- Login as admin
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels/1/presentLocation
- send put request with current location eg,
{
"current_location": "naivasha"
}
- should receive response with code 200 and details of order 1 with new current location eg,
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "naivasha",
"destination": "kitale",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "pending",
"weight": 2
}
- Login as admin
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/parcels/1/status
- send put request with status eg,
{
"status": "in transit"
}
- should receive response with code 200 and details of order 1 with new status eg,
{
"created": "Tue, 20 Nov 2018 00:00:00 GMT",
"current_location": "naivasha",
"destination": "kitale",
"order_no": 1,
"pickup": "nyahururu",
"price": 200,
"sender": 1,
"status": "in transit",
"weight": 2
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/users/1/delivered
- send get request
- should receive response with code 200 and the number of orders of user 1 that are delivered ie,
{
"delivered": 0
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/users/1/in-transit
- send get request
- should receive response with code 200 and the number of orders of user 1 that are in transit ie,
{
"in_transit": 0
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/user/3
- send get request
- should receive response with code 200 and details of user 3 ie,
{
"email": "mnswaleh@gmail.com",
"firstname": "thomas",
"gender": "male",
"location": "kakamega",
"secondname": "Kalume",
"type": "user",
"user_id": 3,
"username": "tom"
}
- Login as admin or user
- Copy the access token and paste it as Bearer Token on headers
- Enter URL http://127.0.0.1:5000/api/v2/auth/logout
- send put request
- should receive response with code 200 and a success message ie,
{
"message": "successful logout"
}
reapet the postman tests above replacing server url http://127.0.0.1:5000 with https://api-sendit.herokuapp.com/