[Answered ]-Django-nose test case gives assertion error when run from management command

2👍

It looks like it’s not inheriting the base test class, so it’s not calling the setup method prior to your test. I would recommend inheriting from Django’s TestCase class, as per the Django documentation on testing. In this case, it would look like this:

# write code to test the views.
from django.test import Client
import unittest

# import nose for tests.
import nose.tools as noz

class TestSettings(unittest.TestCase):
    """ test the nose test related setup """

    def setUp(self):  # Note that the unittest requires this to be setUp and not setup
        self.client = Client()

    def testTestUser(self):
        """ Tests if the django user 'test' is setup properly."""
        # login the test user
        response = self.client.login(username=u'test', password=u'test')    
        noz.assert_equal(response, True)

0👍

Are you creating a user with username test and password test for your tests? Or loading fixtures? I bet not.

When you are using the shell you are logging in against the database in your settings.py. When you are in a test you are using your test database, which is empty at the beginning of every test, so there are no users.

In setUp you could create a user

from django.contrib.auth.models import User
User.objects.create('test', 'test@test.com', 'test')

As @Kevin London pointed out too

your setup command should be

setUp, but I don’t think that has much to do with it since each TestCase has a client by default.

Leave a comment