- Notifications
You must be signed in to change notification settings - Fork0
Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)
License
duduknecmi/Build_Backend_REST_API_with_Python_and_Django
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)
The advanced course on how to Build a Backend REST API using Python, Django (2.0), Django REST Framework (3.9), Docker, Travis CI, Postgres and Test Driven Development!
The original course content was created byMark Winterbottom.
- User authentication
- Creating objects
- Filtering and sorting objects
- Uploading and viewing images
- Setup a project with Docker and Docker-Compose
- Configure Travis-CI to automatically run linting and unit tests
- Write unit tests using the Django Test Framework
- Apply best practice principles including Test Driven Development
- Handle uploading media files with Django
- Customize the Django admin
- Configure a Postgres database
Changing the project interpreter in the PyCharm project settings
- In theSettings/Preferences dialog (Ctrl+Alt+S), selectProject | Project Interpreter.
- Expand the list of the available interpreters and click theShow All link.
- Select the target interpreter. When PyCharm stops supporting any of the outdated Python versions, the corresponding project interpreter is marked as unsupported.
- The Python interpreter name specified in theName field, becomes visible in the list of available interpreters. ClickOK to apply the changes.
For more info pleasecheck here
PyCharm - Choosing Your Testing Framework
- Open the Settings/Preferences dialog, and under the node Tools, click the pagePython Integrated Tools.
- On this page, click theDefault Test Runner field.
- Choose the desired test runner:
For more info please seeEnable Pytest for you project
Setting up Python3 virtual environment on Windows machine
- open CMD
- navigate to project directory, for example:
cd C:\Users\superadmin\Desktop\Python\CodinGame
- run following command:
pip install virtualenv
- run following command:
virtualenv venv --python=python
Setting up Python3 virtual environment on Linx (Ubuntu) machine
- Installpip first
sudo apt-get install python3-pip
- Then installvirtualenv using pip3
sudo pip3 install virtualenv
- Now create a virtual environment
virtualenv venv
you can use any name insted ofvenv
- You can also use a Python interpreter of your choice:
virtualenv -p /usr/bin/python2.7 venv
- Active your virtual environment:
source venv/bin/activate- Using fish shell:
source venv/bin/activate.fish- To deactivate:
deactivate
- Create virtualenv using Python3:
virtualenv -p python3 myenv
- Instead of using virtualenv you can use this command in Python3:
python3 -m venv myenv
Activate Virtual Environment
In a newly created virtualenv there will be a bin/activate shell script. For Windows systems, activation scripts are provided for CMD.exe and Powershell.
- Open Terminal
- Run: \path\to\env\Scripts\activate
Auto generate requirements.txt
Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once.
Use pip’s freeze command to generate a requirements.txt file for your project:
pip freeze> requirements.txtIf you save this in requirements.txt, you can follow this guide:PyCharm - Manage dependencies using requirements.txt, or you can:
pip install -r requirements.txt
error: RPC failed; curl 56 Recv failure: Connection was reset
- Open Git Bash
- Run: "git config --global http.postBuffer 157286400"
How to fix in case .gitignore is ignored by Git
Even if you haven't tracked the files so far, Git seems to be able to "know" about them even after you add them to .gitignore
NOTE:
- First commit your current changes, or you will lose them.
- Then run the following commands from the top folder of your Git repository:
git rm -r --cached.git add.git commit -m"fixed untracked files"
How to generate Allure report with history trends (Windows OS)
Step by step:
- Run tests from pytest using following arguments: -v --alluredir=allure-results
- Copy '.\allure-report\history' folder into '.\allure-results\history'
- Run: allure generate .\allure-results\ -o .\allure-report\ --clean
- Following output should appear: Report successfully generated to .\allure-report
- Run: allure open .\allure-report\
Sphinx Documentation Set Up
Step by step:
Create docs directory
Open cmd > Go to docs directory
cmd > Run: sphinx-quickstart.Note: run with default answers
Go to docs/conf.py
Uncomment following lines:
importosimportsyssys.path.insert(0,os.path.abspath('.'))
- Update extensions list as following:
extensions= ['sphinx.ext.todo','sphinx.ext.viewcode','sphinx.ext.autodoc']
- Update template as following:
html_theme='sphinx_rtd_theme'
- Update sys.path.insert as following:
sys.path.insert(0,os.path.abspath('..'))
- Go to docs/index.rst > add modules, see example below:
.. toctree:: :maxdepth: 2 :caption: Contents: modules
- Open cmd > run:
sphinx-apidoc-o . ..
- cmd > Run: make html
- Install html template:
pipinstallsphinx_rtd_theme
Auto-Generated Python Documentation with Sphinx
Step by step:
- Open CMD
- Go to docs directory
- Run: make clean
- Run: make html
About
Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Python97.9%
- Dockerfile2.1%


