Test the unit using Python Django.test.Client

Asked 2 years ago, Updated 2 years ago, 107 views

I would like to test the web page I made using the class client for unit test provided by Jango.

from django.conf import settings
from django.test import Client
settings.configure()

c = Client()
response = c.get('/')
print response.status_code
response = c.post('/login/', {'user_id':'test', 'user_pw':'testing'})
print response.status_code

The test code was made as follows. However, when I run the test, the error AttributeError: 'module' object has no attribute 'ROOT_URLCONF' occurs.

What should I do in this case?

python-2.7 django unit-testing

2022-09-22 19:49

1 Answers

from django.test import TestCase, Client

class ExampleTestCase(TestCase):
    def setUp(self):

    def test_your_test(self):
        c = Client()
        response = c.get('/')    
        print response.status_code
        response = c.post('/login/', {'user_id':'test', 'user_pw':'testing'})
        print response.status_code


I want to run it as python./manage.py test.

django test case note page: https://docs.djangoproject.com/en/2.0/topics/testing/overview/


2022-09-22 19:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.