예제 #1
0
파일: sqlite.py 프로젝트: pvanderlinden/lux
    def _new_credentials(self):
        username = test.randomname()
        password = test.randomname()

        credentials = {'username': username, 'password': password}

        email = '%s@%s.com' % (username, test.randomname())
        user = yield from self.create_superuser(username, email, password)
        self.assertEqual(user.username, username)
        self.assertNotEqual(user.password, password)
        return credentials
예제 #2
0
 def test_redis_cache(self):
     self.assertEqual(self.cache.name, 'redis')
     key = test.randomname()
     self.assertEqual(self.cache.get_json(key), None)
     data = {'name': 'pippo', 'age': 4}
     self.assertEqual(self.cache.set_json(key, data), None)
     self.assertEqual(self.cache.get_json(key), data)
예제 #3
0
파일: cache.py 프로젝트: pvanderlinden/lux
 def test_get_json(self):
     cache = self.app.cache_server
     self.assertEqual(cache.name, 'redis')
     key = test.randomname()
     self.assertEqual(cache.set(key, '{bad-json}'), None)
     self.assertEqual(cache.get_json(key), None)
     self.assertEqual(cache.get(key), b'{bad-json}')
예제 #4
0
파일: sqlite.py 프로젝트: pvanderlinden/lux
    def _new_credentials(self):
        username = test.randomname()
        password = test.randomname()

        credentials = {
            'username': username,
            'password': password
        }

        email = '%s@%s.com' % (username, test.randomname())
        user = yield from self.create_superuser(username,
                                                email,
                                                password)
        self.assertEqual(user.username, username)
        self.assertNotEqual(user.password, password)
        return credentials
예제 #5
0
파일: sqlite.py 프로젝트: pvanderlinden/lux
    def test_permissions(self):
        '''Test permission models
        '''
        odm = self.app.odm()

        with odm.begin() as session:
            user = odm.user(username=test.randomname())
            group = odm.group(name='staff')
            session.add(user)
            session.add(group)
            group.users.append(user)

        self.assertTrue(user.id)
        self.assertTrue(group.id)

        groups = user.groups
        self.assertTrue(group in groups)

        with odm.begin() as session:
            # add goup to the session
            session.add(group)
            permission = odm.permission(name='admin',
                                        description='Can access the admin',
                                        policy={})
            group.permissions.append(permission)
예제 #6
0
 def test_get_json(self):
     cache = self.app.cache_server
     self.assertEqual(cache.name, 'redis')
     key = test.randomname()
     self.assertEqual(cache.set(key, '{bad-json}'), None)
     self.assertEqual(cache.get_json(key), None)
     self.assertEqual(cache.get(key), b'{bad-json}')
예제 #7
0
파일: test_cache.py 프로젝트: quantmind/lux
 def test_redis_cache(self):
     self.assertEqual(self.cache.name, 'redis')
     key = test.randomname()
     self.assertEqual(self.cache.get_json(key), None)
     data = {'name': 'pippo', 'age': 4}
     self.assertEqual(self.cache.set_json(key, data), None)
     self.assertEqual(self.cache.get_json(key), data)
예제 #8
0
파일: sqlite.py 프로젝트: pvanderlinden/lux
    def _signup(self):
        request = yield from self.client.get('/signup')
        self.assertEqual(request.response.status_code, 200)
        username = test.randomname(prefix='u-')
        password = test.randomname()
        email = '%s@%s.com' % (username, test.randomname())

        data = {'username': username,
                'password': password,
                'password_repeat': password,
                'email': email}
        request = yield from self.client.post('/authorizations/signup',
                                              body=data,
                                              content_type='application/json')
        self.assertEqual(request.response.status_code, 201)
        return self.json(request.response)
예제 #9
0
    def test_permissions(self):
        '''Test permission models
        '''
        odm = self.app.odm()

        with odm.begin() as session:
            user = odm.user(username=test.randomname())
            group = odm.group(name='staff')
            session.add(user)
            session.add(group)
            group.users.append(user)

        self.assertTrue(user.id)
        self.assertTrue(group.id)

        groups = user.groups
        self.assertTrue(group in groups)

        with odm.begin() as session:
            # add goup to the session
            session.add(group)
            permission = odm.permission(name='admin',
                                        description='Can access the admin',
                                        policy={})
            group.permissions.append(permission)
예제 #10
0
파일: sqlite.py 프로젝트: pvanderlinden/lux
    def _signup(self):
        request = yield from self.client.get('/signup')
        self.assertEqual(request.response.status_code, 200)
        username = test.randomname(prefix='u-')
        password = test.randomname()
        email = '%s@%s.com' % (username, test.randomname())

        data = {
            'username': username,
            'password': password,
            'password_repeat': password,
            'email': email
        }
        request = yield from self.client.post('/authorizations/signup',
                                              body=data,
                                              content_type='application/json')
        self.assertEqual(request.response.status_code, 201)
        return self.json(request.response)
예제 #11
0
 async def test_start_project(self):
     command = self.fetch_command('start_project')
     self.assertTrue(command.help)
     name = test.randomname('sp')
     target = None
     try:
         target = await command([name])
         self.assertTrue(path.isdir(target))
     finally:
         if target:
             shutil.rmtree(target)
예제 #12
0
 async def test_start_project(self):
     command = self.fetch_command('start_project')
     self.assertTrue(command.help)
     name = test.randomname('sp')
     target = None
     try:
         target = await command([name])
         self.assertTrue(path.isdir(target))
     finally:
         if target:
             shutil.rmtree(target)
예제 #13
0
파일: utils.py 프로젝트: quantmind/lux
    def _new_credentials(self, username=None, superuser=False, active=True):
        with self.app.models.begin_session() as session:
            username = username or test.randomname()
            password = username
            email = '*****@*****.**' % username

            user = session.auth.create_user(
                session, username=username, email=email,
                password=password, first_name=username,
                active=active, superuser=superuser)
            self.assertTrue(user.id)
            self.assertEqual(user.first_name, username)
            self.assertEqual(user.is_superuser(), superuser)
            self.assertEqual(user.is_active(), active)
        return {'username': username, 'password': password}
예제 #14
0
 def test_startproject(self):
     command = self.fetch_command('start_project')
     self.assertTrue(command.help)
     name = test.randomname('sp')
     target = None
     try:
         command([name])
         target = command.target
         self.assertTrue(path.isdir(target))
         # TODO: fix this in travis
         # self.assertTrue(path.isfile(path.join(target, 'manage.py')))
         # self.assertTrue(path.isfile(path.join(target, 'Gruntfile.js')))
         # self.assertTrue(path.isdir(path.join(target, name)))
     finally:
         if target:
             shutil.rmtree(target)
예제 #15
0
파일: commands.py 프로젝트: victor3rc/lux
 def test_startproject(self):
     command = self.fetch_command('start_project')
     self.assertTrue(command.help)
     name = test.randomname('sp')
     target = None
     try:
         command([name])
         target = command.target
         self.assertTrue(path.isdir(target))
         # TODO: fix this in travis
         # self.assertTrue(path.isfile(path.join(target, 'manage.py')))
         # self.assertTrue(path.isfile(path.join(target, 'Gruntfile.js')))
         # self.assertTrue(path.isdir(path.join(target, name)))
     finally:
         if target:
             shutil.rmtree(target)
예제 #16
0
파일: sqlite.py 프로젝트: victor3rc/lux
    def test_create_superuser_command_and_login(self):
        username = test.randomname()
        email = '*****@*****.**' % username
        password = '******'
        data = {'username': username,
                'password': password}
        user = yield from self.create_superuser(username, email, password)
        self.assertEqual(user.username, username)
        self.assertNotEqual(user.password, password)

        request = yield from self.client.get('/login')
        response = request.response
        self.assertEqual(response.status_code, 200)
        token = self.authenticity_token(self.bs(response))
        self.assertTrue(token)
        data.update(token)
        cookie = self.cookie(response)
        self.assertTrue(cookie)
        #
        # Login with csrf token and cookie, It should work
        request = yield from self.client.post('/api/authorizations',
                                              content_type='application/json',
                                              body=data,
                                              cookie=cookie)
        response = request.response
        self.assertEqual(response.status_code, 200)
        data = self.json(response)
        self.assertTrue(data)
        cookie2 = self.cookie(response)
        # The cookie has changed
        self.assertNotEqual(cookie, cookie2)
        #
        request = yield from self.client.get('/', cookie=cookie2)
        response = request.response
        self.assertEqual(response.status_code, 200)
        user = request.cache.user
        self.assertTrue(user.is_authenticated())
        cookie3 = self.cookie(response)
        # The cookie has changed
        self.assertEqual(cookie3, None)
        #
        request = yield from self.client.get('/login', cookie=cookie2)
        response = request.response
        self.assertEqual(response.status_code, 302)
        return cookie2
예제 #17
0
    def test_create_superuser_command_and_login(self):
        username = test.randomname()
        email = '*****@*****.**' % username
        password = '******'
        data = {'username': username, 'password': password}
        user = yield from self.create_superuser(username, email, password)
        self.assertEqual(user.username, username)
        self.assertNotEqual(user.password, password)

        request = yield from self.client.get('/login')
        response = request.response
        self.assertEqual(response.status_code, 200)
        token = self.authenticity_token(self.bs(response))
        self.assertTrue(token)
        data.update(token)
        cookie = self.cookie(response)
        self.assertTrue(cookie)
        #
        # Login with csrf token and cookie, It should work
        request = yield from self.client.post('/api/authorizations',
                                              content_type='application/json',
                                              body=data,
                                              cookie=cookie)
        response = request.response
        self.assertEqual(response.status_code, 201)
        data = self.json(response)
        self.assertTrue(data.get('token'))
        cookie2 = self.cookie(response)
        # The cookie has changed
        self.assertNotEqual(cookie, cookie2)
        #
        request = yield from self.client.get('/', cookie=cookie2)
        response = request.response
        self.assertEqual(response.status_code, 200)
        user = request.cache.user
        self.assertTrue(user.is_authenticated())
        cookie3 = self.cookie(response)
        # The cookie has changed
        self.assertEqual(cookie3, None)
        #
        request = yield from self.client.get('/login', cookie=cookie2)
        response = request.response
        self.assertEqual(response.status_code, 302)
        return cookie2
예제 #18
0
    def _new_credentials(self, username=None, superuser=False, active=True):
        backend = self.app.auth_backend
        request = self.app.wsgi_request()

        username = username or test.randomname()
        password = username
        email = '*****@*****.**' % username

        user = backend.create_user(request,
                                   username=username,
                                   email=email,
                                   password=password,
                                   first_name=username,
                                   active=active)
        self.assertTrue(user.id)
        self.assertEqual(user.first_name, username)
        self.assertEqual(user.is_superuser(), superuser)
        self.assertEqual(user.is_active(), active)
        return {'username': username, 'password': password}
예제 #19
0
파일: __init__.py 프로젝트: quantrocket/lux
 def _random_token(self, *args, **kwargs):
     return {'access_token': test.randomname('', 20)}
예제 #20
0
파일: __init__.py 프로젝트: quantmind/lux
 def _random_token(self, *args, **kwargs):
     return {'access_token': test.randomname('', 20)}