Commit 167c5888 authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

cours 7 ok :)

parent d62dad47
Pipeline #13063 failed with stage
in 7 seconds
......@@ -2,24 +2,25 @@
author:
- Sébastien Bonnegent
title: Django par la pratique 7/7
lang: fr
---
# QCM !
- 10 mn
- de 13h20 à 13h30
# Départ
## Support
- cours7.html
## Pour démarrer
http://bonnegent.pages.insa-rouen.fr/cours_django/
## Préparation
### L'ancien
~~~
~~~bash
$ git pull
$ cd fwm6
$ pipenv --rm
$ cp -r fwm7 fwm7-tmp
$ cd !$
~~~
### Le nouveau
~~~
$ cd fwm7
$ pipenv install --dev
~~~
Ou utilisation de Ubiquity:
21e91007264de7e0dd7e5123634366b9
## Au programme
- indentation
......@@ -31,18 +32,19 @@ $ pipenv install --dev
## Black
~~~
$ pipenv run black --diff .
$ pipenv run black .
$ pip3 install --user black
$ black --diff .
$ black .
~~~
# Tests
## Lancement
* https://docs.djangoproject.com/fr/2.2/topics/testing/tools/
* https://docs.djangoproject.com/fr/3.2/topics/testing/tools/
### Commandes
~~~
$ pipenv run ./manage.py test
$ python3 ./manage.py test
System check identified no issues (0 silenced).
----------------------------------------------------------------------
......@@ -58,13 +60,13 @@ OK
### Prérequis
~~~
$ pipenv install --dev pytest-django
$ pip3 install --user pytest-django
~~~
## Pytest
### Configuration
~~~
$ cat pytest.ini
$ cat pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = conf.settings
python_files = tests.py test_*.py *_tests.py
......@@ -72,7 +74,7 @@ python_files = tests.py test_*.py *_tests.py
### Lancement
~~~
$ pipenv run pytest -v
$ pytest -v
~~~
## Prérequis
......@@ -94,7 +96,7 @@ def test_home_anon(client):
assert response.status_code == 302
~~~
> $ pipenv run pytest -v
> $ pytest -v
## Accès admin
### webui/tests.py
......@@ -104,7 +106,7 @@ def test_an_admin_view(admin_client):
assert response.status_code == 200
~~~
> $ pipenv run pytest -v
> $ pytest -v
## URLs simples
### webui/tests.py
......@@ -123,7 +125,7 @@ def test_urls_simple(admin_client):
assert response.status_code == 200
~~~
> $ pipenv run pytest -v
> $ pytest -v
## URLS simple v2
### webui/tests.py
......@@ -193,7 +195,7 @@ def test_nb_regles_parefeu(admin_user, parefeu1):
## Modèle
* un parefeu ne peut être son modèle
* https://docs.djangoproject.com/en/2.2/ref/forms/validation/
* https://docs.djangoproject.com/fr/3.2/ref/forms/validation/
### webui/tests.py
~~~python
......@@ -244,20 +246,20 @@ class Parefeu(AvecNom):
### Prérequis
~~~
$ pipenv install --dev pytest-xdist
$ pip3 install --user pytest-xdist
~~~
### Lancement
~~~
$ pipenv run pytest -n 4
$ pytest -n 4
~~~
## Performance
~~~
$ pipenv run pytest
$ pytest
10 passed in 1.70s
$ pipenv run pytest -n 4
$ pytest -n 4
10 passed in 1.98s
~~~
......@@ -267,13 +269,12 @@ $ pipenv run pytest -n 4
* ne pas utiliser le runserver !
~~~
$ pipenv run ./manage.py collectstatic
$ pipenv run ./manage.py check --deploy
$ ./manage.py collectstatic
$ ./manage.py check --deploy
~~~
### pipenv
* export PIPENV_VENV_IN_PROJECT="yes"
* répertoire .venv
* création du dossier .venv
## Apache/httpd
### django.conf
......@@ -300,7 +301,7 @@ WSGIPythonPath "/opt/fwm/.venv"
Require all granted
</Directory>
WSGIDaemonProcess fwm python-path=/opt/fwm:/opt/fwm/.venv/lib/python3.6/site-packages processes=2 threads=15 display-name=%{GROUP}
WSGIDaemonProcess fwm python-path=/opt/fwm:/opt/fwm/.venv/lib/python3.7/site-packages processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup fwm
WSGIScriptAlias / /opt/fwm/conf/wsgi.py
......@@ -312,4 +313,3 @@ WSGIPythonPath "/opt/fwm/.venv"
</VirtualHost>
~~~
# QCM !
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment