def test_list_users(self): with app.test_client() as client: resp = client.get("/users") html = resp.get_data(as_text=True) self.assertEqual(resp.status_code, 200) self.assertIn('Pinky Buggy', html)
def test_show_Edit_user(self): with app.test_client() as client: resp = client.get(f"/users/{self.user_id}") html = resp.get_data(as_text=True) self.assertEqual(resp.status_code, 200) self.assertIn('<p>Pinky Buggy</p>', html)
def test_add_user(self): with app.test_client() as client: d = {"first_name": "Pinky", "last_name": "Buggy"} resp = client.post("/users/new", data=d, follow_redirects=True) html = resp.get_data(as_text=True) self.assertEqual(resp.status_code, 200) self.assertIn('<p>Pinky Buggy</p>', html)
def test_home(self): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200) self.assertEqual(response.data, b'Hello World!')
def test_other(self): tester = app.test_client(self) response = tester.get('a', content_type='html/text') self.assertEqual(response.status_code, 404) self.assertTrue(b'does not exist' in response.data)
def test_hello(): response = app.test_client().get('/') assert response.status_code == 200 assert response.data == b'Docker, App1!'
def setup_class(self): """测试开始时候执行, 用来做准备工作,一般用来初始化资源。""" app.config['TESTING'] = True # 这将会使得处理请求时的错误捕捉失效,以便于 您在进行对应用发出请求的测试时获得更好的错误反馈。 # 测试客户端将会给我们一个通向应用的简单接口,我们可以激发 对向应用发送请求的测试,并且此客户端也会帮我们记录 Cookie 的 动态。 self.app = app.test_client()