def test_login_page_can_post_a_request(self): request = HttpRequest() request.method = 'POST' request.POST['user_id'] = '1' request.POST['acc_type_id'] = '1' request.POST['password'] = USER_1_PASS response = login_view(request) self.assertIn('ログイン中です', response.content.decode())
def test_login_page_returns_correct_html(self): request = HttpRequest() response = login_view(request) expected_html = render_to_string('login.html') # expected_htmlは、フォームオブジェクトの所が表示されない。 # render_to_string()でテンプレートタグの部分をどう扱うのか。 # cf. 「TDD with Python」p.43 self.assertEqual(response.content.decode(), expected_html)
def test_django_test(self): request = HttpRequest() response = login_view(request) self.assertTrue(response.content.startswith(b'<html>')) self.assertIn(b'<title>Login</title>', response.content) self.assertTrue(response.content.strip().endswith(b'</html>'))