0
0
Djangoframework~10 mins

Why testing Django apps matters - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Django test client.

Django
from django.test import [1]
Drag options to blanks, or click blank then click option'
ATestCase
BClient
CHttpResponse
Dmodels
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TestCase instead of Client
Importing models by mistake
2fill in blank
medium

Complete the code to define a test case class inheriting from Django's test case.

Django
class MyTest([1]):
    pass
Drag options to blanks, or click blank then click option'
AClient
BView
CModel
DTestCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using Client as base class
Using Model or View instead
3fill in blank
hard

Fix the error in the test method name to make it run automatically.

Django
def [1](self):
    self.assertEqual(1 + 1, 2)
Drag options to blanks, or click blank then click option'
Atest_addition
Baddition_test
Ccheck_addition
Drun_addition
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting method name with 'test_'
Using other prefixes
4fill in blank
hard

Fill both blanks to create a test that checks the home page status code.

Django
def test_home_page(self):
    response = self.client.[1]('/')
    self.assertEqual(response.[2], 200)
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cstatus_code
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using post instead of get
Checking content instead of status_code
5fill in blank
hard

Fill all three blanks to write a test that creates a user and checks its username.

Django
def test_create_user(self):
    user = User.objects.[1](username='alice')
    self.assertEqual(user.[2], 'alice')
    self.assertTrue(user.[3]())
Drag options to blanks, or click blank then click option'
Acreate
Busername
Cis_active
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of create
Checking wrong attributes