Exemple #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()))
Exemple #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()))
Exemple #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)
Exemple #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()))
Exemple #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)
Exemple #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)
Exemple #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, '')
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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')
Exemple #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")
Exemple #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)
Exemple #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')
Exemple #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)
Exemple #38
0
 def test_unicode(self):
     user_1 = User(username='******', auth_id='test', session_id='test')
     self.assertEqual(unicode(user_1), u'Calvin')
Exemple #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)
Exemple #40
0
 def test_str(self):
     user_1 = User(username='******', auth_id='test', session_id='test')
     self.assertEqual(str(user_1), u'Hobbes')