python - Django testing not getting connected to the database -
i newbie django. in first django app, testing 1 of view check login. here view:
from testprjct.testapp.forms import loginform_form django.contrib import auth def check_login(request): if request.method == 'post': form = loginform_form(request.post) if request.post , form.is_valid(): username = request.post.get('username', '') password = request.post.get('password', '') # hard-coding credentials here testing user = auth.authenticate(username = 'test123', password = 'qwerty') if user not none , user.is_active: auth.login(request, user) .....
this view working fine when running server , trying login front-end. failing when executing test case view. here test code view:
from testprjct.testapp.models import loginform class viewtests(testcase): def setup(self): loginform.objects.create(username='test123', password='qwerty') def test_login(self): response = self.client.get('/login/') self.assertequal(response.status_code, 200) response = self.client.post('/login/', {"username": "test123", "password": "qwerty"}) print response self.assertequal(response.status_code, 302)
this returns 200 status_code (not redirecting success page) giving message login details invalid.
same issue when testing forgot password link in login page. works fine front-end when valid email-id provided. test case gives me error message email-id doesnt have associated user account, though providing same email-id gave in front-end.
any suggestions please? have spent lot of time on trying figure out issue.
django sets new database testing, doesn't access existing data. need create data need in test itself, or in setup
method.
Comments
Post a Comment