0
0
Djangoframework~10 mins

Task results and status in Django - Interactive Code Practice

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'
AClient
BRequestFactory
CTestCase
DSimpleTestCase
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TestCase instead of Client
Using RequestFactory which is different
Forgetting to import anything
2fill in blank
medium

Complete the code to check if a test response status code is 200 (OK).

Django
self.assertEqual(response.[1], 200)
Drag options to blanks, or click blank then click option'
Astatus_code
Bstatus
Ccode
Dhttp_status
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.status instead of response.status_code
Using response.code which does not exist
3fill in blank
hard

Fix the error in the test method to correctly check for a redirect status.

Django
self.assertEqual(response.[1], 302)
Drag options to blanks, or click blank then click option'
Aredirect_code
Bstatus
Cstatus_code
Dhttp_redirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent attributes like redirect_code
Using status instead of status_code
4fill in blank
hard

Fill both blanks to assert the response contains the text 'Welcome' and has status 200.

Django
self.assertContains(response, [1])
self.assertEqual(response.[2], 200)
Drag options to blanks, or click blank then click option'
A'Welcome'
Bstatus_code
Cstatus
D'Hello'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute for status code
Using wrong text string in assertContains
5fill in blank
hard

Fill all three blanks to check the response is a redirect to '/login/' with status 302.

Django
self.assertEqual(response.[1], 302)
self.assertEqual(response.[2], '/login/')
self.assertTrue(response.[3])
Drag options to blanks, or click blank then click option'
Astatus_code
Burl
Chas_header('Location')
Dredirect_url
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names for URL or status
Not checking for the 'Location' header