python - Unit test to assertRedirects of login? -


i have custom login page admin in django project. trying write unit-test raise error. after successful login django redirect user other page (dashboard page). in unit test dont work assertredirects. how fix problem?

print reverse('administration:dashboard') return me /administration/ have strange error. can whats wrong did?

tests.py:

class administrationviewtestcase(testcase):     def setup(self):         self.client = client()      def test_administration_login(self):         response = self.client.get(             reverse('administration:administration_login'),             follow=true         )         self.assertequals(response.status_code, 200)          title = "login"         self.asserttrue(title in response.content)          user = user.objects.create(             username='user', password=make_password('password')         )         self.asserttrue(user)          logged_in = self.client.login(username='user', password="password")         self.asserttrue(logged_in)          response = self.client.post(             reverse('administration:administration_login')         )         self.assertequal(response.status_code, 302)          self.assertredirects(             response,             expected_url=reverse('administration:dashboard'),             status_code=302,             target_status_code=200         ) 

error:

traceback (most recent call last):   file "/home/nurzhan/ca/administration/tests.py", line 41, in test_administration_login     target_status_code=200   file "/srv/envs/py27/lib/python2.7/site-packages/django/test/testcases.py", line 324, in assertredirects     % (path, redirect_response.status_code, target_status_code) assertionerror: couldn't retrieve redirection page '/accounts/profile/': response code 404 (expected 200) 

urls.py of app:

urlpatterns = [     # administration dashboard     url(r'^$',         login_required(             login_url=reverse_lazy('administration:administration_login'))         (dashboardview.as_view()),         name='dashboard'),      # 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'), ] 

urls.py of project:

urlpatterns = [     # administration page     url(r'^administration/',         include('administration.urls', namespace='administration')), ] 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -