SlideShare a Scribd company logo
1 of 18
Download to read offline
Django	
                                	


                                      	
  
             @torufurukawa	
  (#bucho)
Django	
                  	

•  manage.py	
  test	
  
•  Fixtures	
  
•  Clinet
manage.py	
  test	
$	
  python	
  manage.py	
  test	
  -­‐-­‐help	
  
Usage:	
  manage.py	
  test	
  [options]	
  [appname	
  ...]	
  


Runs	
  the	
  test	
  suite	
  for	
  the	
  specified	
  
applications,	
  or	
  the	
  entire	
  site	
  if	
  no	
  
apps	
  are	
  specified.	
  
<app>/tests.py	
                                                 	
from	
  django.test	
  import	
  TestCase	
  
from	
  myapp	
  import	
  extract	
  

class	
  ExtractTest(TestCase):	
  
	
  	
  def	
  test	
  (self):	
  
	
  	
  	
  	
  self.assertEqual(	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  extract(u'       ',u'   '),	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  u'      ')	
  
manage.py	
  test	
                                                                            	
$	
  python	
  manage.py	
  test	
  
Creating	
  test	
  database	
  'default’…	
  
           	
  
...........	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
Ran	
  17	
  tests	
  in	
  0.419s	
  

OK	
  
$	
  
manage.py	
  test	
  myapp.MyTest	
   	
  
                                  	

$	
  python	
  manage.py	
  test	
  bucho	
  

                                                       	

$	
  python	
  manage.py	
  test	
  bucho.TestShow	

                                                	
  
$	
  cat	
  testdata.json	
  	
  
[	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "pk":	
  1,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  "model":	
  "api.systemstatus",	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  "fields":	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "corner":	
  "2",	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "mode":	
  "1",	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "quesQon_id":	
  null	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  },	
  
                                   	
  
]	
  
manage.py	
  dumpdata	
   	
  
                                      	
$	
  python	
  manage.py	
  dumpdata	
  
[{"pk":	
  1,	
  "model":	
  "api.systemstatus",	
  "fields":	
  
     {"corner":	
  "0",	
  "mode":	
  "0",	
  "quesQon_id":	
  
     76}}	
  …..	
  ]	
  
                                   	
             .                	

$	
  python	
  manage.py	
  dumpdata	
  app	
  
$	
  python	
  manage.py	
  dumpdata	
  app.MyModel	
  
fixtures	
                         	
  
                                                             	
Class	
  MyTest(TestCase):	
  
	
  	
  	
  	
  fixtures	
  =	
  [‘mydata.json’]	
  
                                                      	
	
  	
  	
  	
  def	
  test_xxx(self):	
  
	
  	
  	
  	
  	
  	
  	
  	
  …	
  
SQLite	
  3	
                              	
  
                                                                  	
#	
  se_ngs_test.py	
  
DATABASES	
  =	
  {	
  
	
  	
  	
  	
  'default':	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  'ENGINE':	
  'sqlite3',	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  'NAME':	
  ':memory:',	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  …	
  
	
  	
  	
  	
  }	
  
}	
  
view	
                                                                                 	
  Client	
>>>	
  help(Client)	
  
Help	
  on	
  class	
  Client	
  in	
  module	
  django.test.client:	
  

class	
  Client(__builQn__.object)	
  
	
  |	
  	
  A	
  class	
  that	
  can	
  act	
  as	
  a	
  client	
  for	
  tesQng	
  purposes.	
  
	
  |	
  	
  	
  
	
  |	
  	
  It	
  allows	
  the	
  user	
  to	
  compose	
  GET	
  and	
  POST	
  requests,	
  and	
  
	
  |	
  	
  obtain	
  the	
  response	
  that	
  the	
  server	
  gave	
  to	
  those	
  requests.	
  
	
  …	
  
	
  |	
  	
  Client	
  objects	
  are	
  stateful	
  -­‐	
  they	
  will	
  retain	
  cookie	
  (and	
  
	
  |	
  	
  thus	
  session)	
  details	
  for	
  the	
  lifeQme	
  of	
  the	
  Client	
  instance.	
  
Client.get(	
  )	
                     client.post(	
  )	
class	
  MyTest(TestCase):	
  
	
  	
  def	
  test_get(self):	
  
	
  	
  	
  	
  res	
  =	
  self.client.get(‘/foo’)	
  
	
  	
  	
  	
  self.assertEqual(res.status_code,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  200)	
  
                                                                                         	
	
  	
  def	
  test_post(self):	
  
	
  	
  	
  	
  	
  res	
  =	
  self.client.post(	
  
       	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ‘/bar’,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {‘key’:’value’})	
  
	
  	
  	
  	
  	
  …
 
                                                       	

Client.session	
                  Django	
                         	
  
                                                                     	
TestCase.assertTemplateUsed	
  
                                        	
  
TestCase.assertFormError	
                      	
  
                                                            	
  
TestCase.assertRedirects	
                                                	
  
Django	
                           	
•  manage.py	
  test	
                 	
  
•  Fixtures	
              	
  
•  Client	
   view	
  

More Related Content

What's hot

Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
louieuser
 
Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)
Oliver Klee
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
Rubyc Slides
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5
Juriy Zaytsev
 

What's hot (20)

Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
 
Pytest: escreva menos, teste mais
Pytest: escreva menos, teste maisPytest: escreva menos, teste mais
Pytest: escreva menos, teste mais
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
OPM Recipe designer notes
OPM Recipe designer notesOPM Recipe designer notes
OPM Recipe designer notes
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
 
Testing orm based code
Testing orm based codeTesting orm based code
Testing orm based code
 
PL/SQL Unit Testing Can Be Fun!
PL/SQL Unit Testing Can Be Fun!PL/SQL Unit Testing Can Be Fun!
PL/SQL Unit Testing Can Be Fun!
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
 
JUnit
JUnitJUnit
JUnit
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
 

Similar to Django

Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
Erik Rose
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
Yi-Huan Chan
 
Slaven tomac unit testing in angular js
Slaven tomac   unit testing in angular jsSlaven tomac   unit testing in angular js
Slaven tomac unit testing in angular js
Slaven Tomac
 
Testing for Pragmatic People
Testing for Pragmatic PeopleTesting for Pragmatic People
Testing for Pragmatic People
davismr
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Lohika_Odessa_TechTalks
 

Similar to Django (20)

Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven TomacJavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
E2E testing con nightwatch.js - Drupalcamp Spain 2018
E2E testing con nightwatch.js  - Drupalcamp Spain 2018E2E testing con nightwatch.js  - Drupalcamp Spain 2018
E2E testing con nightwatch.js - Drupalcamp Spain 2018
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Scala test
Scala testScala test
Scala test
 
Scala test
Scala testScala test
Scala test
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Slaven tomac unit testing in angular js
Slaven tomac   unit testing in angular jsSlaven tomac   unit testing in angular js
Slaven tomac unit testing in angular js
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Browser testing with nightwatch.js
Browser testing with nightwatch.jsBrowser testing with nightwatch.js
Browser testing with nightwatch.js
 
Testing for Pragmatic People
Testing for Pragmatic PeopleTesting for Pragmatic People
Testing for Pragmatic People
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
 

More from Toru Furukawa

おまえらこのライブラリ使ってないの? m9 (2013-07)
おまえらこのライブラリ使ってないの? m9	(2013-07)おまえらこのライブラリ使ってないの? m9	(2013-07)
おまえらこのライブラリ使ってないの? m9 (2013-07)
Toru Furukawa
 
Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012
Toru Furukawa
 
Python 3.3 チラ見
Python 3.3 チラ見Python 3.3 チラ見
Python 3.3 チラ見
Toru Furukawa
 

More from Toru Furukawa (11)

Twitter 広告と API を組み合わせたインタラクティブなキャンペーン
 Twitter 広告と API を組み合わせたインタラクティブなキャンペーン Twitter 広告と API を組み合わせたインタラクティブなキャンペーン
Twitter 広告と API を組み合わせたインタラクティブなキャンペーン
 
My client wanted their apps synced, and I made it with Go
My client wanted their apps synced, and I made it with GoMy client wanted their apps synced, and I made it with Go
My client wanted their apps synced, and I made it with Go
 
Introduction to Python 3.4 as of beta 1
Introduction to Python 3.4 as of beta 1Introduction to Python 3.4 as of beta 1
Introduction to Python 3.4 as of beta 1
 
Test Failed, Then...
Test Failed, Then...Test Failed, Then...
Test Failed, Then...
 
おまえらこのライブラリ使ってないの? m9 (2013-07)
おまえらこのライブラリ使ってないの? m9	(2013-07)おまえらこのライブラリ使ってないの? m9	(2013-07)
おまえらこのライブラリ使ってないの? m9 (2013-07)
 
Mock and patch
Mock and patchMock and patch
Mock and patch
 
Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012
 
Python 3.3 チラ見
Python 3.3 チラ見Python 3.3 チラ見
Python 3.3 チラ見
 
Python32 pyhackathon-201011
Python32 pyhackathon-201011Python32 pyhackathon-201011
Python32 pyhackathon-201011
 
Python 2.7
Python 2.7Python 2.7
Python 2.7
 
BPStudy#34 導入
BPStudy#34 導入BPStudy#34 導入
BPStudy#34 導入
 

Recently uploaded

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 

Django

  • 1. Django     @torufurukawa  (#bucho)
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Django   •  manage.py  test   •  Fixtures   •  Clinet
  • 7. manage.py  test $  python  manage.py  test  -­‐-­‐help   Usage:  manage.py  test  [options]  [appname  ...]   Runs  the  test  suite  for  the  specified   applications,  or  the  entire  site  if  no   apps  are  specified.  
  • 8. <app>/tests.py   from  django.test  import  TestCase   from  myapp  import  extract   class  ExtractTest(TestCase):      def  test  (self):          self.assertEqual(                          extract(u' ',u' '),                            u' ')  
  • 9. manage.py  test   $  python  manage.py  test   Creating  test  database  'default’…     ...........   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   Ran  17  tests  in  0.419s   OK   $  
  • 10. manage.py  test  myapp.MyTest     $  python  manage.py  test  bucho   $  python  manage.py  test  bucho.TestShow  
  • 11. $  cat  testdata.json     [          {                  "pk":  1,                    "model":  "api.systemstatus",                    "fields":  {                          "corner":  "2",                            "mode":  "1",                            "quesQon_id":  null                  }          },     ]  
  • 12. manage.py  dumpdata     $  python  manage.py  dumpdata   [{"pk":  1,  "model":  "api.systemstatus",  "fields":   {"corner":  "0",  "mode":  "0",  "quesQon_id":   76}}  …..  ]   . $  python  manage.py  dumpdata  app   $  python  manage.py  dumpdata  app.MyModel  
  • 13. fixtures     Class  MyTest(TestCase):          fixtures  =  [‘mydata.json’]          def  test_xxx(self):                  …  
  • 14. SQLite  3     #  se_ngs_test.py   DATABASES  =  {          'default':  {                  'ENGINE':  'sqlite3',                    'NAME':  ':memory:',                    …          }   }  
  • 15. view    Client >>>  help(Client)   Help  on  class  Client  in  module  django.test.client:   class  Client(__builQn__.object)    |    A  class  that  can  act  as  a  client  for  tesQng  purposes.    |        |    It  allows  the  user  to  compose  GET  and  POST  requests,  and    |    obtain  the  response  that  the  server  gave  to  those  requests.    …    |    Client  objects  are  stateful  -­‐  they  will  retain  cookie  (and    |    thus  session)  details  for  the  lifeQme  of  the  Client  instance.  
  • 16. Client.get(  )   client.post(  ) class  MyTest(TestCase):      def  test_get(self):          res  =  self.client.get(‘/foo’)          self.assertEqual(res.status_code,                                            200)      def  test_post(self):            res  =  self.client.post(                        ‘/bar’,                              {‘key’:’value’})            …
  • 17.   Client.session Django     TestCase.assertTemplateUsed     TestCase.assertFormError       TestCase.assertRedirects    
  • 18. Django   •  manage.py  test     •  Fixtures     •  Client   view