def setUp(self): super(TestAuthHandler, self).setUp() set_up_db() app = Application([('/', AuthHandler)], cookie_secret=settings.COOKIE_SECRET) req = Mock() req.cookies = {} self.auth_handler = AuthHandler(app, req)
def setUp(self): super(TestCharStatusHandler, self).setUp() set_up_db() self.app = self.get_app() self.req = Mock() self.req.cookies = {} self.objects_handler = ObjectsHandler(self.app, self.req) self.auth_handler = AuthHandler(self.app, self.req) self.zonename = "defaultzone" self.zoneid = "playerinstance-%s-username" % self.zonename
def setUp(self): app = Application([('/', AuthHandler)]) req = Mock() self.auth_handler = AuthHandler(app, req) patch('authserver.UserController').start()
class TestAuthHandler(unittest.TestCase): def setUp(self): app = Application([('/', AuthHandler)]) req = Mock() self.auth_handler = AuthHandler(app, req) patch('authserver.UserController').start() def test_authenticate(self): # Mock out the User object first = Mock(return_value=Mock()) MockUser = Mock() MockUser.query.filter_by().first = first # Test with patch.object(authserver, 'User', MockUser): result = self.auth_handler.authenticate("username", "password") self.assertTrue(result) def test_authenticate_invalid_password(self): '''There is a good username and password in the database. But we give a real username, and a bad password. We should not be allowed to log in.''' username = "******" password = "******" # Mock out the User object MockUser = Mock() first = Mock(return_value=None) MockUser.get = first # Test with patch.object(authserver, 'User', MockUser): result = self.auth_handler.authenticate(username, password) self.assertFalse(result) def test_set_admin(self): user = "******" MockAdmin = Mock() MockAdmin.__iter__ = Mock(return_value=iter([user])) mock_set_secure_cookie = Mock() with patch.object(settings, 'ADMINISTRATORS', MockAdmin): with patch.object(self.auth_handler, 'set_secure_cookie', mock_set_secure_cookie): self.auth_handler.set_admin(user) mock_set_secure_cookie.assert_called_once_with('admin', 'true') def test_set_admin_not_administrator(self): # Mock auth_handler.clear_cookie user = "******" MockAdmin = Mock() MockAdmin.__iter__ = Mock(return_value=iter([])) mock_clear_cookie = Mock() with patch.object(settings, 'ADMINISTRATORS', MockAdmin): with patch.object(self.auth_handler, 'clear_cookie', mock_clear_cookie): self.auth_handler.set_admin(user) mock_clear_cookie.assert_called_once_with('admin') def test_set_current_user(self): user = "******" mock_set_secure_cookie = Mock() with patch.object(self.auth_handler, 'set_secure_cookie', mock_set_secure_cookie): self.auth_handler.set_current_user(user) mock_set_secure_cookie.assert_called_once_with("user", user, domain=None) def test_set_current_user_with_none(self): user = None mock_clear_cookie = Mock() with patch.object(self.auth_handler, 'clear_cookie', mock_clear_cookie): self.auth_handler.set_current_user(user) mock_clear_cookie.assert_called_once_with("user")