Skip to content

Latest commit

 

History

History
296 lines (188 loc) · 8.05 KB

README.md

File metadata and controls

296 lines (188 loc) · 8.05 KB

retwitter

Postman Service Internship Assignment

Python Django

Build Status

Re Twitter Assignment - complete with all basic, extended and extra credit functionalities.

Important Links:

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

Table of contents

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.


Installation

(Back to top)

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.


Setup instructions

  • Clone the repo https://github.com/sid22/retwitter.git

  • Command: cd/retwitter

  • Make a virtual environment python3 -m venv env and activate it source 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


Basic functionality

(Back to top)

#

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

Login

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

Logout

User logout with server generated token.

Response has no token only acknowledgement of logout.

Route: user/logout

Method: GET/POST


Extended functionality

(Back to top)

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"
}

Follow

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.

Unfollow

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.

Create

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.

Read Delete

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

  1. 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.

Tests

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

Extra Credit

(Back to top)

Like Unlike

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

Retweet

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™

Replies

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

Threads

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