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.
- [Answered ]-Django – query and delete GenericForeignKey
- [Answered ]-How can a django forms.CharField generate a required input?
- [Answered ]-Get shipping address for a basket in django oscar
- [Answered ]-How to create model in Django REST with userID from authentication
- [Answered ]-Python is printing one list backwards but not the others