Django dirty draft
New Project (inside project folder)
virtualenv -p python3.7 backend
cd backend
source bin/activate
pip install django
Django-admin startproject core
cd core
#Migrate the models
Python manage.py makemigrations
Python manage.py migrate
Python manage.py createsuperuser
python manage.py runserver
python manage.py startapp
Fix migrations problems
python manage.py showmigrations
python manage.py migrate --fake core zero
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete
python manage.py makemigrations
python manage.py migrate --fake-initial
setUpandtearDown: These are functions to be executed before (setUp) and after (tearDown) in each unit test. These are very useful for fixtures.setUpClassandtearDownClass: In an analogous way of setUp and tearDown, these functions are executed before (setUpClass) and after (tearDownClass) during the whole test case. This means that it is executed only once for a test case. Since they’re used by Django to make important configurations, if you overwrite these methods in your test case class, don’t forget to call thesuperimplementation inside the functions.setUpTestData: this function can be used to have a class-level atomic block to define data for the whole test case. That means that this function automatically rollbacks the changes in the database after the finalization of all the unit tests in the test case. This is mainly used to load data to your test database.- Assert methods: Django has the set of assert methods from unittest, and has another one created for the framework. These methods, such as
assertEqual,assertIsNone,assertTrue, etc, can be used in the unit test to check the different conditions that have to be met. For example, in the unit test of login, you can assert that the response has a status code of 200 because you want to make sure that if the data is sent correctly, then your application has to return the response with that code.
You can dump your database into a fixture and then load that from your test database:
python manage.py dumpdata --format=json main.TestData > test_data.json
assertRaises(exception, callable, *args, **kwds)postgres=# create database mydb;
postgres=# create user myuser with encrypted password 'mypass';
postgres=# grant all privileges on database mydb to myuser;
sudo -u user_name psql db_name
To reset the password if you have forgotten:
ALTER USER user_name WITH PASSWORD 'new_password';
Commentaires
Enregistrer un commentaire