Postman Service Internship Assignment
Re Twitter Assignment - complete with all basic, extended and extra credit functionalities.
Postman Collection of all the endpoints with valid request/responses
https://documenter.getpostman.com/view/3851689/RzZ6HL3A
The whole APP hosted on Google Cloud
https://postman-221411.appspot.com
The coverage report on Google Cloud: https://postman-221411.appspot.com/reports/index.html
The project is a set of APIs made with the Django Framework in Python language. MongoDB database is used for storing information, MLab is used to provide Database-as-a-Service on hosted project. Redis in-memory data structure store is used as a cache store for session management, RedisLabs is used to provide it on hostel project.
To run the project locally, firstly the user must either: Have a local instance of Mongod Server ( Port: 27017 ) and Redis Server ( Port: 6379 ) running on standard ports on local machine. Both should not have authentication enabled. If auth settings are to be put, in retwitter/settings.py kindly add the same.
-
Clone the repo https://github.com/sid22/retwitter.git
-
Command:
cd/retwitter
-
Make a virtual environment
python3 -m venv env
and activate itsource env/bin/activate
-
Install the dependencies
pip install -r requirements.txt
-
Run it
python manage.py runserver
-
(Optional ) To run tests
python manage.py test --verbosity 3
User registration with unique username and password.
No bounds on username or password. Response has a token, which is then used further on to authenticate/authorize the user.
Route: user/#
Method: POST
User login with unique username and password.
Response has a token, which is then used further on to authenticate/authorize the user.
Route: user/#
Method: POST
User logout with server generated token.
Response has no token only acknowledgement of logout.
Route: user/logout
Method: GET/POST
Generally all endpoints below require a valid token to be present in Request Header with key as 'Authorization' and token value can be obtained with login/#.
If empty token, no header the following error response will come, status code 401.
{
"Error": "Token not valid, please login to get a valid token first"
}
The user identified in the token follows the user passed.
Route: user/follow
Headers: Authorization {{ Token }}
Request Body:
follow_name: {{ username of user to follow }}
Method:/POST
Will throw error on empty username, if the username is already being followed.
The user identified in the token unfollows the user passed
Route: user/unfollow
Headers: Authorization {{ Token }}
Request Body:
unfollow_name: {{ username of user to unfollow }}
Method:/POST
Will throw error on empty username, if the username is already being not followed.
The user identified in the token creates a tweet with the text passed
Route: tweet/create
Headers: Authorization {{ Token }}
Request Body:
tweet_text: {{ text for the tweet }}
Method:/POST
The text will be capped at 140 characters ( including spaces ), same for replies and threads.
Will throw error on empty tweet_text also.
The user identified in the token is used to check authorization for delete.
Route: tweet/{{tweet_id}}
Headers: Authorization {{ Token }}
Methods: 1: GET The response will be the tweet info of tweet with the tweet_id passed
- DELETE The response will be an affirmation of the deleted tweet if the user is authorized to do it.
Will throw error if user not authorized.
I have used primarily python's unittest module and Django's Test Client to test the handler functions and endpoints respectively.
The coverage reports for the same have also been generated and are present in the /docs folder in the main repo.
The reports are hosted on Github pages and can be seen Coverage Report
The project has also been integrated with Travis CI system to automate testing and keep a build status.
Currently the coverage of tests is 88%.
Travis Builds can be seen Travis Builds
To run all tests locally
python manage.py test --verbosity 3
To run tests for account component only
python manage.py test account/ --verbosity 3
To run tests for tweet component only
python manage.py test tweets/ --verbosity 3
To run all tests and fresh generate a coverage report ( in /docs folder )
python getcoverage.py
The user identified in the token 'likes' the tweet whose id is passed. If the user has previously liked the same tweet, he will 'unlike' it. Hitting the endpoint again will again make the user 'like' the tweet.
Route: tweet/emotion/{{tweet_id}}
Headers: Authorization {{ Token }}
Method:/POST
The user identified in the token 'retweets' the tweet whose id is passed. A retweet will have similar model as a tweet, but will also have certain flags like
is_retweet: True
The original tweet which has been retweeted will also update with a retweet_count increase, retweet_users list will have id of user who has retweeted the tweet and list of id's of all retweets.
Deleting a retweet will correspondingly update the fields of original tweet also.
Route: tweet/retweet/{{tweet_id}}
Headers: Authorization {{ Token }}
Method:/POST™
The user identified in the token 'replies' to the tweet whose id is passed. A reply will be treated similar to a tweet object. It will the following flag.
is_reply: True
The original tweet which has been replied to will also update with a replies_count increase and the replies list of id's of all replies.
Deleting a retweet will correspondingly update the fields of original tweet also.
Route: tweet/reply/{{tweet_id}}
Headers: Authorization {{ Token }}
Request Body:
reply_text: {{ text for the tweet }}
Method:/POST
The user identified in the token creates a thread of tweets. The tweets is a thread will have
"is_threaded": True
Each 'thread' will also be given a thread id linking all tweets.
Route: tweet/thread/
Headers: Authorization {{ Token }}
Request Body:
thread_count: {{ int value of number of tweets }},
tweet_text_1: {{ text 1 }},
--
--
tweet_text_i: {{ text i }}
Method:/POST
Response will have the thread_id and list of all tweets in the thread.
To view a thread as one with all tweets:
Route: tweet/thread/{{ thread_id }}
Headers: Authorization {{ Token }}
Method:/POST