Skip to content

Commit

Permalink
Test that the views that require a login redirect to the login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhiek187 committed Sep 25, 2021
1 parent 70a6d0c commit 46e6f72
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions stockhelper/stockapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def send_post_request(self):
return self.client.post(reverse("stockapp:detail", args=("PRU",)),
json.dumps(p_copy), content_type="application/json")

def test_redirect_without_login(self):
# Check that the view redirects to the login screen if the user isn't logged in
response = self.client.get(reverse("stockapp:detail", args=("Pru",)))
self.assertEqual(response.status_code, 302)

def test_view_renders(self):
# Check that the view renders properly
self.client.login(username=USERNAME, password=PASSWORD)
Expand Down Expand Up @@ -268,6 +273,11 @@ def setUp(self):
self.user = get_user_model().objects.create_user(
username=USERNAME, password=PASSWORD)

def test_redirect_without_login(self):
# Check that the view redirects to the login screen if the user isn't logged in
response = self.client.get(reverse("stockapp:portfolio"))
self.assertEqual(response.status_code, 302)

def test_view_renders(self):
# Check that the view renders properly
self.client.login(username=USERNAME, password=PASSWORD)
Expand Down Expand Up @@ -332,6 +342,11 @@ def setUp(self):
self.user = get_user_model().objects.create_user(
username=USERNAME, password=PASSWORD)

def test_redirect_without_login(self):
# Check that the view redirects to the login screen if the user isn't logged in
response = self.client.get(reverse("stockapp:balance"))
self.assertEqual(response.status_code, 302)

def test_view_renders(self):
# Check that the view renders properly
self.client.login(username=USERNAME, password=PASSWORD)
Expand All @@ -347,6 +362,11 @@ def setUp(self):
self.user = get_user_model().objects.create_user(
username=USERNAME, password=PASSWORD)

def test_redirect_without_login(self):
# Check that the view redirects to the login screen if the user isn't logged in
response = self.client.get(reverse("stockapp:prices"))
self.assertEqual(response.status_code, 302)

def test_view_renders(self):
# Check that the view renders properly
self.client.login(username=USERNAME, password=PASSWORD)
Expand Down

0 comments on commit 46e6f72

Please sign in to comment.