0
0
Djangoframework~10 mins

TestCase and SimpleTestCase 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 class used for database tests.

Django
from django.test import [1]
Drag options to blanks, or click blank then click option'
ALiveServerTestCase
BSimpleTestCase
CClient
DTestCase
Attempts:
3 left
💡 Hint
Common Mistakes
Importing SimpleTestCase instead of TestCase for database tests.
2fill in blank
medium

Complete the code to import the Django test class used for tests without database access.

Django
from django.test import [1]
Drag options to blanks, or click blank then click option'
ASimpleTestCase
BTestCase
CStaticLiveServerTestCase
DRequestFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using TestCase when database is not needed, which slows tests.
3fill in blank
hard

Fix the error in the test class declaration to correctly use SimpleTestCase.

Django
class MyTests([1]):
    def test_example(self):
        self.assertEqual(1 + 1, 2)
Drag options to blanks, or click blank then click option'
ATestCase
BSimpleTestCase
Cunittest.TestCase
DLiveServerTestCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using TestCase unnecessarily when no database is needed.
4fill in blank
hard

Fill both blanks to create a test method that uses Django's test client to get the home page.

Django
class HomePageTests([1]):
    def test_home_page_status(self):
        response = self.client.[2]('/')
        self.assertEqual(response.status_code, 200)
Drag options to blanks, or click blank then click option'
ATestCase
BSimpleTestCase
Cget
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using SimpleTestCase, which does not set up the database.
Using post instead of get for a simple page load.
5fill in blank
hard

Fill all three blanks to create a SimpleTestCase that checks if a utility function returns True.

Django
from django.test import [1]

def is_even(n):
    return n % 2 == 0

class UtilityTests([2]):
    def test_is_even(self):
        self.assert[3](is_even(4))
Drag options to blanks, or click blank then click option'
ASimpleTestCase
BTestCase
CTrue
DTrueEqual
Attempts:
3 left
💡 Hint
Common Mistakes
Using TestCase unnecessarily.
Using incorrect assertion method name.