-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from django-ve/2025_upgrades
Added views test case
- Loading branch information
Showing
3 changed files
with
57 additions
and
3 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.contrib.auth.models import User | ||
|
||
class HelloWorldViewTests(TestCase): | ||
def test_hello_world_view(self): | ||
""" | ||
Test the hello world view returns a 200 status code and the correct content. | ||
""" | ||
response = self.client.get(reverse('index')) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Hello, world!\n") | ||
|
||
def test_admin_view(self): | ||
""" | ||
Test the admin view returns a 200 status code. | ||
""" | ||
# Create a superuser | ||
User.objects.create_superuser(username='admin', email='[email protected]', password='adminpass') | ||
# Log in the superuser | ||
self.client.login(username='admin', password='adminpass') | ||
# Access the admin view | ||
response = self.client.get(reverse('admin:index')) | ||
self.assertEqual(response.status_code, 200) |