Share
Embed
Introduction à LiveServerTestCase (In French)
Talk given at DjangoCon Toulouse 2012 (http://rencontres.django-fr.org/2012/tolosa/)
Julien Phalip
November 24, 2012
Transcript
55 slides
-
CONNECTED PERSONAL OBJECTS 5/2012 C’est qui lui? ‣ Globetrotter ‣
Utilise Django depuis 2007 ‣ Core-développeur depuis 2011 ‣ Tweete à @julienphalip -
CONNECTED PERSONAL OBJECTS 5/2012 Tests: méthode traditionnelle from django.test import
TestCase class SuperTests(TestCase): def test_bonjour(self): r = self.client.get('/bonjour') self.assertTrue('Bonjour' in r.content) -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase Base de données TestCase Code
de l’application THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application MockRequest THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application MockRequest THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application MockRequest HttpResponse THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application MockRequest HttpResponse THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.TestCase “Faux” client http (self.client) Base
de données TestCase Code de l’application MockRequest HttpResponse THREAD DJANGO -
CONNECTED PERSONAL OBJECTS 5/2012 ... une méthode incomplète ‣ Pas
de “vraies” requêtes http -
CONNECTED PERSONAL OBJECTS 5/2012 ... une méthode incomplète ‣ Pas
de “vraies” requêtes http ‣ Pas de tests d’interface utilisateur -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase LiveServerTestCase Code de l’application THREAD
DJANGO #2 THREAD DJANGO #1 Serveur http -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http LiveServerTestCase Code
de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase “Vrai” client http Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 django.test.LiveServerTestCase Base de données LiveServerTestCase http
python-requests Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 + ou ou django.test.LiveServerTestCase Base de
données LiveServerTestCase http Code de l’application THREAD DJANGO #2 THREAD DJANGO #1 Serveur http wsgi -
CONNECTED PERSONAL OBJECTS 5/2012 from django.test import LiveServerTestCase from selenium.webdriver.firefox.webdriver
import WebDriver class SuperTests(LiveServerTestCase): LiveServerTestCase: avec Selenium -
CONNECTED PERSONAL OBJECTS 5/2012 from django.test import LiveServerTestCase from selenium.webdriver.firefox.webdriver
import WebDriver class SuperTests(LiveServerTestCase): LiveServerTestCase: avec Selenium @classmethod def setUpClass(cls): cls.selenium = WebDriver() super(MySeleniumTests, cls).setUpClass() @classmethod def tearDownClass(cls): cls.selenium.quit() super(MySeleniumTests, cls).tearDownClass() -
CONNECTED PERSONAL OBJECTS 5/2012 from django.test import LiveServerTestCase from selenium.webdriver.firefox.webdriver
import WebDriver class SuperTests(LiveServerTestCase): LiveServerTestCase: avec Selenium @classmethod def setUpClass(cls): cls.selenium = WebDriver() super(MySeleniumTests, cls).setUpClass() @classmethod def tearDownClass(cls): cls.selenium.quit() super(MySeleniumTests, cls).tearDownClass() -
CONNECTED PERSONAL OBJECTS 5/2012 LiveServerTestCase: avec Selenium from django.test import
LiveServerTestCase from selenium.webdriver.firefox.webdriver import WebDriver class SuperTests(LiveServerTestCase): ... def test_bonjour(self): self.selenium.get(self.live_server_url + '/bonjour') self.selenium.find_element_by_id('btn-ok').click() -
CONNECTED PERSONAL OBJECTS 5/2012 Autres cas d’utilisation ‣ Tests d’APIs
REST avec python-requests. (suggéré par Steve Lacy @sklacy) -
CONNECTED PERSONAL OBJECTS 5/2012 Autres cas d’utilisation ‣ Tests d’APIs
REST avec python-requests. (suggéré par Steve Lacy @sklacy) ‣ r = requests.get(self.live_server_url + '/api/user/1/') -
CONNECTED PERSONAL OBJECTS 5/2012 Autres cas d’utilisation ‣ Tests d’APIs
REST avec python-requests. (suggéré par Steve Lacy @sklacy) ‣ r = requests.get(self.live_server_url + '/api/user/1/') ‣ self.assertEqual(r.json, {u'username': u'john.doe', u'email': '[email protected]'}) -
CONNECTED PERSONAL OBJECTS 5/2012 Autres cas d’utilisation ‣ Tests d’APIs
REST avec python-requests. (suggéré par Steve Lacy @sklacy) ‣ r = requests.get(self.live_server_url + '/api/user/1/') ‣ self.assertEqual(r.json, {u'username': u'john.doe', u'email': '[email protected]'}) ‣ Tests d’authentification Facebook ou Twitter, avec Selenium. (suggéré par Samuel Sutch @ssutch) -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. ‣ Intégration frontend/backend. -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. ‣ Intégration frontend/backend. ‣ fun ! -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. ‣ Intégration frontend/backend. ‣ fun ! ‣ ... mais à utiliser avec modération -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. ‣ Intégration frontend/backend. ‣ fun ! ‣ ... mais à utiliser avec modération ‣ Plus lent, surtout avec Selenium. -
CONNECTED PERSONAL OBJECTS 5/2012 En conclusion... ‣ LiveServerTestCase c’est top
! ‣ Protocole http complet. ‣ Intégration frontend/backend. ‣ fun ! ‣ ... mais à utiliser avec modération ‣ Plus lent, surtout avec Selenium. ‣ À utiliser pour les fonctionnalités critiques et pour augmenter la couverture des tests. -
Merci ! @julienphalip http:/ /odopod.com http:/ /julienphalip.com à Toulibre, la
Django Software Foundation et tous les organisateurs et participants de DjangoCon Toulouse.