Beispiel #1
0
    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()))
Beispiel #2
0
    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()))
Beispiel #3
0
    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)
Beispiel #4
0
    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()))
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
    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, '')
Beispiel #8
0
    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)
Beispiel #9
0
    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)
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    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)
Beispiel #15
0
    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)
Beispiel #16
0
    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)
Beispiel #17
0
    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)
Beispiel #18
0
    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)
Beispiel #19
0
    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)
Beispiel #20
0
    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)
Beispiel #21
0
    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)
Beispiel #22
0
    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)
Beispiel #23
0
    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)
Beispiel #24
0
    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)
Beispiel #25
0
    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)
Beispiel #26
0
    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)
Beispiel #27
0
    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)
Beispiel #28
0
    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)
Beispiel #29
0
    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)
Beispiel #30
0
    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)
Beispiel #31
0
 def test_renew_session_force(self):
     app = Tipfy()
     user = User.create('my_username', 'my_id')
     user.renew_session(force=True, max_age=86400)
Beispiel #32
0
 def test_renew_session_force(self):
     app = Tipfy()
     user = User.create('my_username', 'my_id')
     user.renew_session(force=True, max_age=86400)
Beispiel #33
0
    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')
Beispiel #34
0
    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")
Beispiel #35
0
    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)
Beispiel #36
0
    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')
Beispiel #37
0
    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)
Beispiel #38
0
 def test_unicode(self):
     user_1 = User(username='******', auth_id='test', session_id='test')
     self.assertEqual(unicode(user_1), u'Calvin')
Beispiel #39
0
    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)
Beispiel #40
0
 def test_str(self):
     user_1 = User(username='******', auth_id='test', session_id='test')
     self.assertEqual(str(user_1), u'Hobbes')