def test_before_request_handler_with_bad_auth(self): header = { 'Authorization': 'Token deadbeef', } with self.app.test_request_context(headers=header): with self.assertRaises(BadRequest): before_request_authentication()
def test_before_request_handler_successful_auth(self): with self.app.test_request_context(headers=self.auth_header): before_request_authentication() self.assertTrue(g.user.is_authenticated()) self.assertEqual(g.user.username, 'bob')
def test_before_request_handler_anonymous(self): with self.app.test_request_context(): before_request_authentication() self.assertFalse(g.user.is_authenticated())