-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
from django.test import TestCase | ||
from django.contrib.auth import get_user_model | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
# Create your tests here. | ||
|
||
class ViewTest(TestCase): | ||
def setUp(self): | ||
self.email = "test@project-novis.org" | ||
self.password = "top_secret" | ||
|
||
self.user = get_user_model().objects.create_user(email=self.email, password=self.password) | ||
self.client = Client() | ||
|
||
def test_views_anonymous(self): | ||
views = ( | ||
('index', dict(), 200), | ||
('version', dict(), 200), | ||
('healthz', dict(), 200), | ||
('readiness', dict(), 200), | ||
('robots', dict(), 200), | ||
) | ||
|
||
for view, kwargs, status_code in views: | ||
with self.subTest(i=view): | ||
response = self.client.get(reverse(view, kwargs=kwargs)) | ||
self.assertEqual(response.status_code, status_code) | ||
|
||
def test_views_logged_in(self): | ||
views = ( | ||
('index', dict(), 200), | ||
('version', dict(), 200), | ||
('healthz', dict(), 200), | ||
('readiness', dict(), 200), | ||
('robots', dict(), 200), | ||
) | ||
|
||
with self.subTest('User login'): | ||
logged_in = self.client.login(username=self.email, password=self.password) | ||
self.assertTrue(logged_in) | ||
|
||
for view, kwargs, status_code in views: | ||
with self.subTest(i=view): | ||
response = self.client.get(reverse(view, kwargs=kwargs)) | ||
self.assertEqual(response.status_code, status_code) |