I want to test the reachability of home page of a demo app.
So I do this:
from django.test import TestCase
class TestHomePageView(TestCase):
def test_reachable_home(self):
response = self.client.get('/home/')
self.assertEqual(response.status_code, 200)
and the views.py
from django.shortcuts import render
def home_view(request):
return render(request, 'home.html', {})
home.html is a simple one:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
Hi, circleci and django
</body>
</html>
and urls.py:
from django.contrib import admin
from django.urls import path
from demo_app.views import home_view
urlpatterns = [
path('admin/', admin.site.urls),
path('home/', home_view)
]
It's a really simple demo app.
What I am curious is "Why I can test the status code without running django server?" Just simply $ python manage.py test without $ python manage.py runserver
and get the test result:
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.
----------------------------------------------------------------------
Ran 1 test in 0.011s
OK
Destroying test database for alias 'default'...
Any idea or suggestion is welcome, thanks.
Aucun commentaire:
Enregistrer un commentaire