REST API project for a basic poll application applied CI and TDD. This project is managed by Travis CI.
- Learn how to design REST API in Python
- Learn how to make good test
- Learn how CI/CD works
- Understand Django structure
/polls/
/polls/<pk>/
/polls/<pk>/choices/
/polls/<pk>/choices/<choice_pk>/
/polls/<pk>/choices/<choice_pk/vote/
/login/
-
Clone this repository
$ git clone git@github.com:Choi-Sung-Hoon/Django_API.git
-
Move to the cloned repository
$ cd Django_API
-
Create a virtual environment
$ virtualenv django Using base prefix '/usr' New python executable in /home/ubuntu/Django_API/django/bin/python3.6 Also creating executable in /home/ubuntu/Django_API/django/bin/python Installing setuptools, pip, wheel... done.
-
Activate the virtual environment
$ source django/bin/activate
-
Install pip packages required
(django)$ pip install -r requirements.txt
-
Move to Django project directory
(django)$ cd pollsapi
-
Build database for the project
(django)$ python manage.py migrate Operations to perform: Apply all migrations: admin, auth, authtoken, contenttypes, polls, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying authtoken.0001_initial... OK Applying authtoken.0002_auto_20160226_1747... OK Applying polls.0001_initial... OK Applying sessions.0001_initial... OK
-
Create admin account
(django)$ python manage.py createsuperuser Username (leave blank to use 'ubuntu'): admin Email address: Password: Superuser created successfully.
-
Run server and expose it to the outside
(django)$ python manage.py runserver 0.0.0.0:8000 Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). January 24, 2020 - 17:35:02 Django version 3.0.2, using settings 'pollsapi.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
-
Access to the server and sign in as an admin. (IP address is hidden for security)
https://***.***.***.***:8000/
-
Once you have signed in, you can access to the endpoints like:
https://***.***.***.***:8000/polls/
-
Move to the cloned repository
$ cd Django_API
-
Activate the virtual environment
$ source django/bin/activate
-
Move to Django project directory
(django)$ cd pollsapi
-
Run the tests
(django)$ python manage.py test Creating test database for alias 'default'... System check identified no issues (0 silenced). .......... ---------------------------------------------------------------------- Ran 14 tests in 5.913s OK Destroying test database for alias 'default'...
-
/polls/
-
/polls/<pk>/
-
/polls/<pk>/choices/
-
/polls/<pk>/choices/<choice_pk>/
-
/polls/<pk>/choices/<choice_pk/vote/
-
/login/