N
N
nurzhannogerbek2017-09-11 15:31:34
Django
nurzhannogerbek, 2017-09-11 15:31:34

How to fix a bug in a Django project test?

Hello! Please help me figure it out.
I'm trying to write a unit test in my django project. I didn’t write tests before, I wrote a kind of simple test. I want to understand why the following test gives an error and how to fix it?
tests.py:

class DasboardTestCase(TestCase):
    def test_login(self):
        # Create client
        client = Client()

        # Get login page
        response = client.get('/administration/login/')

        # Check response code
        self.assertEquals(response.status_code, 200)

        # Check login in response
        self.assertTrue('/administration/login/' in response.content)

LOG:
FAIL: test_login (slider.tests.DashboardViewTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/nurzhan/CA/administration/tests.py", line 16, in test_login
    self.assertTrue('/administration/login/' in response.content)
AssertionError: False is not true

URLs.py:
from django.contrib.auth import views as authentication_views

urlpatterns = [
    # Administration Login
    url(r'^login/$',
        authentication_views.login,
        {
            'template_name': 'administration/login.html',
            'authentication_form': AdministrationAuthenticationForm,
            'extra_context': {
                'next': reverse_lazy('administration:dashboard')
            },
            'redirect_authenticated_user': True
        },
        name='administration_login'),

    # Administration Logout
    url(r'^logout/$',
        authentication_views.logout,
        {
            'next_page': reverse_lazy('home')
        },
        name='administration_logout'),
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2017-09-11
@nurzhannogerbek

Well so obviously the condition
is not fulfilled. Did you look at the contents of response.content?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question