Skip to content

jayantkageriofficial/todo-list-python

 
 

Repository files navigation

TODO List in Python

Build Status

Custom image

What is this?

TO DO List is a simple API project created with everything that I learned on course Do Zero ao Deploy by Cássio Botaro.

This project covers the following concepts:

  • Python environments with Pipenv
  • Test Driven Development with PyTest
  • Starting with Flask framework
  • Continuous Integration with Travis
  • Continuous Deployment with Heroku

Starting from what has been taught, I improved the API with MongoDB persistence.

Environment

API

All code was written with Python 3.6, so, for a correct running, it is recommended to install this one.

After Python installed, it is required to install all dependencies. You can use Pipenv or Virtualenv. If you are using Pipenv, use the following command to install from Pipfile:

$ pipenv install

...and active the environment:

$ pipenv shell

However, if you are using Virtualenv, you need to activate the environment and install from requirements.pip file:

$ source YOUR_ENVIRONMENT_DIRECTORY/bin/activate
$ pip install -r requirements.pip

Database

Install MongoDB in your machine and be sure MongoDB process is running.

How to run

$ python todo.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

API Endpoints:

  • GET /tasks: Return all tasks available
  • POST /tasks: Create a new task

Testing (Optional)

You can test the application using the development dependencies.

Install all development dependencies from Pipfile:

$ pipenv install --dev

Or from dev-requirements.pip file if you are using VirtualEnv:

$ pip install -r dev-requirements.pip

To debug endpoints, you can use HTTPie as following:

$ http http://127.0.0.1:5000/tasks
[
  {
    "_id": {
      "$oid": "5ad3d924e3bdea6ccf9d9d3e"
    },
    "description": "The Best Description",
    "done": false,
    "title": "The Best Title"
  },
  {
    "_id": {
      "$oid": "5ad3d8fae3bdea6c41d571f4"
    },
    "description": "The Incredible Description",
    "done": false,
    "title": "The Incredible Title"
  }
]
$ http POST http://127.0.0.1:5000/tasks title=Test description=Test
HTTP/1.0 201 CREATED
Content-Length: 123
Content-Type: application/json
Date: Mon, 16 Apr 2018 00:23:45 GMT
Server: Werkzeug/0.14.1 Python/3.6.2

{
  "_id": {
    "$oid": "5ad3ed11e3bdea06aa7afa06"
  },
  "description": "Test",
  "done": false,
  "title": "Test"
}

To run the tests, you can use PyTest as following:

$ python -m pytest
...
collected 7 items

test_todo.py .......                                                    [100%]
========================== 7 passed in 1.32 seconds ==========================

About

A simple To Do List with Python and Flask Framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.9%
  • Procfile 1.1%