def test_get_by_auth_id(self): user = User.create('my_username', 'my_id') user_1 = User.get_by_auth_id('my_id') self.assertEqual(isinstance(user, User), True) self.assertEqual(isinstance(user_1, User), True) self.assertEqual(str(user.key()), str(user_1.key()))
def test_get_by_username(self): user = User.create("my_username", "my_id") user_1 = User.get_by_username("my_username") self.assertEqual(isinstance(user, User), True) self.assertEqual(isinstance(user_1, User), True) self.assertEqual(str(user.key()), str(user_1.key()))
def test_create(self): user = User.create('my_username', 'my_id') self.assertEqual(isinstance(user, User), True) # Second one will fail to be created. user = User.create('my_username', 'my_id') self.assertEqual(user, None)
def test_ne(self): user_1 = User(key_name='test', username='******', auth_id='test', session_id='test') user_2 = User(key_name='test_2', username='******', auth_id='test', session_id='test') self.assertEqual((user_1 != user_2), True)
def test_eq(self): user_1 = User(key_name='test', username='******', auth_id='test', session_id='test') user_2 = User(key_name='test', username='******', auth_id='test', session_id='test') self.assertEqual(user_1, user_2) self.assertNotEqual(user_1, '')
def test_real_logout(self): user = User.create('foo', 'foo_id', auth_remember=True) app = self.get_app() request = Request.from_values('/') local.current_handler = RequestHandler(app, request) store = MultiAuthStore(local.current_handler) store.login_with_auth_id('foo_id', remember=False) response = Response() local.current_handler.session_store.save(response) request = Request.from_values('/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) local.current_handler = RequestHandler(app, request) store = MultiAuthStore(local.current_handler) self.assertNotEqual(store.user, None) self.assertEqual(store.user.username, 'foo') store.logout() response = Response() local.current_handler.session_store.save(response) request = Request.from_values('/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) local.current_handler = RequestHandler(app, request) store = MultiAuthStore(local.current_handler) #self.assertEqual(store.user, None) self.assertEqual(store.session, None)
def test_admin_required_middleware_with_user(self): os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['USER_ID'] = 'me' User.create('me', 'gae|me') class MyHandler(HomeHandler): middleware = [AdminRequiredMiddleware()] app = get_app() app.router.add(Rule('/', name='home', handler=MyHandler)) client = app.get_test_client() response = client.get('/') self.assertEqual(response.status_code, 403)
def test_real_logout(self): user = User.create('foo', 'foo_id', auth_remember=True) with self.get_app().get_test_context() as request: store = MultiAuthStore(request) store.login_with_auth_id('foo_id', remember=False) response = Response() request.session_store.save(response) with self.get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) as request: store = MultiAuthStore(request) self.assertNotEqual(store.user, None) self.assertEqual(store.user.username, 'foo') store.logout() response = Response() request.session_store.save(response) with self.get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')), }) as request: store = MultiAuthStore(request) self.assertEqual(store.session, None)
def test_admin_required_middleware_with_user(self): os.environ["USER_EMAIL"] = "*****@*****.**" os.environ["USER_ID"] = "me" User.create("me", "gae|me") class MyHandler(HomeHandler): middleware = [AdminRequiredMiddleware()] app = get_app() app.router.add(Rule("/", name="home", handler=MyHandler)) client = app.get_test_client() response = client.get("/") self.assertEqual(response.status_code, 403)
def test_renew_session(self): app = Tipfy() request = Request.from_values('/') local.current_handler = RequestHandler(app, request) user = User.create('my_username', 'my_id') user.renew_session(max_age=86400)
def test_real_logout(self): user = User.create("foo", "foo_id", auth_remember=True) with self.get_app().get_test_context() as request: store = MultiAuthStore(request) store.login_with_auth_id("foo_id", remember=False) response = Response() request.session_store.save(response) with self.get_app().get_test_context( "/", headers={"Cookie": "\n".join(response.headers.getlist("Set-Cookie"))} ) as request: store = MultiAuthStore(request) self.assertNotEqual(store.user, None) self.assertEqual(store.user.username, "foo") store.logout() response = Response() request.session_store.save(response) with self.get_app().get_test_context( "/", headers={"Cookie": "\n".join(response.headers.getlist("Set-Cookie"))} ) as request: store = MultiAuthStore(request) self.assertEqual(store.session, None)
def test_login_with_auth_id(self): with self.get_app().get_test_context() as request: store = MultiAuthStore(request) store.login_with_auth_id("foo_id", remember=False) user = User.create("foo", "foo_id", password="******") app = self.get_app() store.login_with_auth_id("foo_id", remember=True)
def test_login_with_auth_id(self): with self.get_app().get_test_context() as request: store = MultiAuthStore(request) store.login_with_auth_id('foo_id', remember=False) user = User.create('foo', 'foo_id', password='******') app = self.get_app() store.login_with_auth_id('foo_id', remember=True)
def test_admin_required_decorator_withd_user(self): os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['USER_ID'] = 'me' User.create('me', 'gae|me') class MyHandler(HomeHandler): @admin_required def get(self, **kwargs): return Response('home sweet home') app = get_app() app.router.add(Rule('/', name='home', handler=MyHandler)) client = app.get_test_client() response = client.get('/') self.assertEqual(response.status_code, 403)
def test_check_password(self): app = Tipfy() request = Request.from_values('/') local.current_handler = RequestHandler(app, request) user = User.create('my_username', 'my_id', password='******') self.assertEqual(user.check_password('foo'), True) self.assertEqual(user.check_password('bar'), False)
def test_login_with_form(self): user = User.create('foo', 'foo_id', password='******') with self.get_app().get_test_context() as request: store = MultiAuthStore(request) res = store.login_with_form('foo', 'bar', remember=True) self.assertEqual(res, True) res = store.login_with_form('foo', 'bar', remember=False) self.assertEqual(res, True)
def test_check_password(self): app = Tipfy() request = Request.from_values("/") local.current_handler = RequestHandler(app, request) user = User.create("my_username", "my_id", password="******") self.assertEqual(user.check_password("foo"), True) self.assertEqual(user.check_password("bar"), False)
def test_admin_required_decorator_withd_user(self): os.environ["USER_EMAIL"] = "*****@*****.**" os.environ["USER_ID"] = "me" User.create("me", "gae|me") class MyHandler(HomeHandler): @admin_required def get(self, **kwargs): return Response("home sweet home") app = get_app() app.router.add(Rule("/", name="home", handler=MyHandler)) client = app.get_test_client() response = client.get("/") self.assertEqual(response.status_code, 403)
def test_login_with_form(self): user = User.create("foo", "foo_id", password="******") with self.get_app().get_test_context() as request: store = MultiAuthStore(request) res = store.login_with_form("foo", "bar", remember=True) self.assertEqual(res, True) res = store.login_with_form("foo", "bar", remember=False) self.assertEqual(res, True)
def test_set_password(self): user = User.create("my_username", "my_id", password="******") self.assertEqual(isinstance(user, User), True) password = user.password user.set_password("bar") self.assertNotEqual(user.password, password) self.assertNotEqual(user.password, "bar") self.assertEqual(len(user.password.split("$")), 3)
def test_login_with_auth_id(self): app = self.get_app() request = Request.from_values('/') local.current_handler = RequestHandler(app, request) store = MultiAuthStore(local.current_handler) store.login_with_auth_id('foo_id', remember=False) user = User.create('foo', 'foo_id', password='******') app = self.get_app() store.login_with_auth_id('foo_id', remember=True)
def test_set_password(self): user = User.create('my_username', 'my_id', password='******') self.assertEqual(isinstance(user, User), True) password = user.password user.set_password('bar') self.assertNotEqual(user.password, password) self.assertNotEqual(user.password, 'bar') self.assertEqual(len(user.password.split('$')), 3)
def test_login_with_form(self): user = User.create('foo', 'foo_id', password='******') app = self.get_app() request = Request.from_values('/') local.current_handler = RequestHandler(app, request) store = MultiAuthStore(local.current_handler) res = store.login_with_form('foo', 'bar', remember=True) self.assertEqual(res, True) res = store.login_with_form('foo', 'bar', remember=False) self.assertEqual(res, True)
def test_renew_session_force(self): app = Tipfy() user = User.create('my_username', 'my_id') user.renew_session(force=True, max_age=86400)
def test_create_with_password_hash(self): user = User.create('my_username', 'my_id', password_hash='foo') self.assertEqual(isinstance(user, User), True) self.assertEqual(user.password, 'foo')
def test_create_with_password_hash(self): user = User.create("my_username", "my_id", password_hash="foo") self.assertEqual(isinstance(user, User), True) self.assertEqual(user.password, "foo")
def test_create_with_password(self): user = User.create('my_username', 'my_id', password='******') self.assertEqual(isinstance(user, User), True) self.assertNotEqual(user.password, 'foo') self.assertEqual(len(user.password.split('$')), 3)
def test_unicode(self): user_1 = User(username='******', auth_id='test', session_id='test') self.assertEqual(unicode(user_1), u'Calvin')
def test_create_with_password(self): user = User.create("my_username", "my_id", password="******") self.assertEqual(isinstance(user, User), True) self.assertNotEqual(user.password, "foo") self.assertEqual(len(user.password.split("$")), 3)
def test_str(self): user_1 = User(username='******', auth_id='test', session_id='test') self.assertEqual(str(user_1), u'Hobbes')