python - Django test client: login doesn't work -


i'm having trouble logging in test @login_required views in django test cases.

i have customuser model looks this:

class customuser(abstractbaseuser, permissionsmixin):     email = models.emailfield('email address', max_length=254, unique=true)     username = models.charfield('username', max_length=30, blank=true)     is_active = models.booleanfield('active', default=false, help_text='designates whether user should treated approved.')     objects = customusermanager()     username_field = 'email' 

here's test case:

class viewtests(testcase):     def test_create_user(self):         u = customuser.objects.create_superuser("u@u.ca","p")         u.is_active = true         u.save()     def test_add_project(self):         self.client.login(username="u@u.ca", password="p")         response = self.client.get(reverse('add-project'), {}, follow=true) 

the user created correctly , self.client.login() works, response redirect login page.

i can create user, log in correctly , use view in browser. how can test client same?

each test method runs own transaction rolled @ end of test. data created in 1 test not available in test. login not work because user not exist/was never created. if need common test data tests can put in test case setup.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -