Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第9章测试章节代码没有按预期执行 #32

Open
lsasln opened this issue Aug 3, 2023 · 0 comments
Open

第9章测试章节代码没有按预期执行 #32

lsasln opened this issue Aug 3, 2023 · 0 comments

Comments

@lsasln
Copy link

lsasln commented Aug 3, 2023

章节:第9章
位置:test_watchlist.py:测试认证相关功能

class WatchlistTestCase(unittest.TestCase):
    # ...
    # 测试登录保护
    def test_login_protect(self):
        response = self.client.get('/')
        data = response.get_data(as_text=True)
        self.assertNotIn('Logout', data)
......

这个测试用例不会通过,原因猜测可能是存在登录的缓存,我看了返回的html是登录过后的。于是我在前面加了个logout的方法,并且在这段代码前使用,即可通过测试:

    def logout(self):
        self.client.get('/logout')
......
    def test_login_protect(self):
        self.logout()
        response = self.client.get('/')
        data = response.get_data(as_text=True)
        self.assertNotIn('Logout', data)
        self.assertNotIn('Settings', data)
        self.assertNotIn('<form method="post">', data)
        self.assertNotIn('Delete', data)
        self.assertNotIn('Edit', data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant