def test_logout_while_logged_in(self): """Logging out after being logged in should also redirect to the login page and display the logout message.""" self.client.login(username='******', password='******') response = self.client.get(reverse('spine_core:logout'), follow=True) self.assertRedirects(response, url_qs(reverse('spine_core:login'), msg='logout')) self.assertTemplateUsed(response, 'spine_core/login.html') self.assertEqual(response.context['user'].is_authenticated(), False)
def test_task_detail_page_with_unassociated_user(self): """The task detail page should redirect to the login page if the current user is not associated.""" task = Task.objects.get(name="task_2") response = self.client.get(reverse('spine_core:task', kwargs={'pk': task.id}), follow=True) self.assertEqual(response.redirect_chain[-1][1], 302) self.assertEqual(Url(response.redirect_chain[-1][0]), Url(url_qs(reverse('spine_core:login'), msg='auth', next=reverse('spine_core:task', kwargs={'pk': task.id})))) self.assertTemplateUsed(response, 'spine_core/login.html')
def dispatch(self, request, *args, **kwargs): if self.get_object() in self.model.objects.filter(**{self.filter: self.request.user}): return super(AuthDetailView, self).dispatch(request, *args, **kwargs) else: return redirect_to_login( '/{model}/{pk}/'.format( model=self.model.__name__.lower(), pk=self.kwargs['pk'], ), login_url=url_qs(reverse('spine_core:login'), msg='auth'), )
def dispatch(self, request, *args, **kwargs): if self.get_object() in self.model.objects.filter( **{self.filter: self.request.user}): return super(AuthDetailView, self).dispatch(request, *args, **kwargs) else: return redirect_to_login( '/{model}/{pk}/'.format( model=self.model.__name__.lower(), pk=self.kwargs['pk'], ), login_url=url_qs(reverse('spine_core:login'), msg='auth'), )
def test_other_restricted_page_while_not_logged_in(self): """Other restricted pages should redirect to the login page with the 'next' variable set.""" response = self.client.get(reverse('spine_core:project'), follow=True) self.assertRedirects(response, url_qs(reverse('spine_core:login'), next=reverse('spine_core:project'))) self.assertTemplateUsed(response, 'spine_core/login.html') self.assertEqual(response.context['user'].is_authenticated(), False)