我应该如何测试这些功能?他们所做的只是渲染 html 页面并将一些对象传递给 html 页面。
def index(request):
companies = Company.objects.filter(approved = True);
return direct_to_template(request, 'home.html', {'companies': companies} );
我应该如何测试这些功能?他们所做的只是渲染 html 页面并将一些对象传递给 html 页面。
def index(request):
companies = Company.objects.filter(approved = True);
return direct_to_template(request, 'home.html', {'companies': companies} );
可以测试以下内容:
代码看起来像这样:
class TestPage(TestCase):
def setUp(self):
self.client = Client()
def test_index_page(self):
url = reverse('index')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'index.html')
self.assertContains(response, 'Company Name XYZ')