我已經在app.yaml中測試webapp2的:需要登錄不承認
handlers:
- url: /.*
script: app.application
secure: always
login: required
以下運行時我使用這個testrunner由谷歌所建議的測試。
class SearchTest(unittest.TestCase):
def setUp(self):
# Set up app simulator
app = webapp2.WSGIApplication([('/search', search.Search)], debug=True)
self.testapp = webtest.TestApp(app)
# Google testbed
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_user_stub()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
# Disable caching to prevent data from leaking between tests
ndb.get_context().set_cache_policy(False)
def testNotLoggedin(self):
# Test user is redirected to login when not logged in
assert not users.get_current_user()
response = self.testapp.get('/search')
self.assertEqual(response.status_int, 302)
assert response.headers['Location']
testNotLoggedIn以200!= 302失敗。因此,即使需要登錄,用戶仍然可以訪問。這使我認爲app.yaml在測試中不被識別?
如何確認app.yaml被識別並且用戶需要登錄?
我相信這些規則是在調度程序到達您的應用程序之前處理的。如果不啓動dev_appserver的實例並通過HTTP測試該服務器,沒有好的方法來測試它。 –
雖然在testrunner我鏈接到它看起來像你導入dev_appserver ... – Jonathan