Source code for trustpoint.tests.test_views.test_index_view
"""Tests for the IndexView class."""fromdjango.contrib.auth.modelsimportUserfromdjango.testimportRequestFactory,TestCasefromdjango.urlsimportresolve,reversefromhome.viewsimportIndexView
[docs]classTestIndexView(TestCase):"""Test cases for the IndexView."""
[docs]defsetUp(self)->None:"""Set up test environment, including a test user and request factory."""self.user=User.objects.create_user(username='testuser',password='password')# noqa: S106self.factory=RequestFactory()
[docs]deftest_index_view_redirection_authenticated(self)->None:"""Test that IndexView redirects an authenticated user to the expected URL."""request=self.factory.get('/')request.user=self.userview=IndexView.as_view()response=view(request)assertresponse.status_code==302,'Response should return status 302 for temporary redirection.'# noqa: PLR2004expected_url=reverse('home:dashboard')assertresponse.url==expected_url,f"IndexView should redirect to '{expected_url}'."
[docs]deftest_index_view_url_resolves_correctly(self)->None:"""Test that the IndexView resolves to the correct view class."""view=resolve(reverse('home:index'))assertview.func.view_class==IndexView,'The resolved view should be IndexView.'