コード例 #1
0
    def test_newtask_extends_expiration(self):
        """Test API project new_task extends expiration"""
        project = ProjectFactory.create()
        project.set_password('the_password')
        project_repo.save(project)
        TaskFactory.create_batch(2, project=project, info={'question': 'answer'})
        user = UserFactory.create()

        url = '/project/%s/password?api_key=%s' % (project.short_name, user.api_key)
        data = dict(password='******')
        res = self.app.post(url, data=data)

        c, v, e = get_pwd_cookie(project.short_name, res)

        assert c
        self.app.set_cookie('/', c, v)

        now = datetime.utcnow()
        url = '/api/project/%s/newtask?api_key=%s' % (project.id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 200, res
        task = json.loads(res.data)
        assert task['info'].get('question') == 'answer'

        c, v, new_exp = get_pwd_cookie(project.short_name, res)
        assert e - now < timedelta(minutes=35)
        assert new_exp - now > timedelta(minutes=55)
        assert new_exp - now < timedelta(minutes=65)
コード例 #2
0
    def test_newtask_expired_cookie(self):
        """Test API project new_task expired cookie"""
        project = ProjectFactory.create(info={'timeout': 60})
        project.set_password('the_password')
        project_repo.save(project)
        TaskFactory.create_batch(2, project=project, info={'question': 'answer'})
        user = UserFactory.create()

        # simulate sending expired cookies
        with patch.dict(self.flask_app.config, {'PASSWD_COOKIE_TIMEOUT': -1}):
            url = '/project/%s/password?api_key=%s' % (project.short_name, user.api_key)
            data = dict(password='******')
            res = self.app.post(url, data=data)

            c, v, e = get_pwd_cookie(project.short_name, res)

            assert c
            self.app.set_cookie('/', c, v)
            res = self.app.post(url, data=data)
            c, v, e = get_pwd_cookie(project.short_name, res)

            assert c

            url = '/project/%s/newtask?api_key=%s' % (project.short_name, user.api_key)
            res = self.app.get(url)
            assert res.status_code == 302
            headers = {'Content-Type': 'application/json'}
            res = self.app.get(url, headers=headers)
            next_url = json.loads(res.data)['next']
            print next_url
            headers = {'Authorization': user.api_key}
            res = self.app.get(next_url, headers=headers)

            assert 'Enter the password to contribute to this project' in res.data, res.data
コード例 #3
0
ファイル: test_newtask_passwd.py プロジェクト: rlarus/pybossa
    def test_newtask_expired_cookie(self):
        """Test API project new_task expired cookie"""
        project = ProjectFactory.create(info={'timeout': 60})
        project.set_password('the_password')
        project_repo.save(project)
        TaskFactory.create_batch(2,
                                 project=project,
                                 info={'question': 'answer'})
        user = UserFactory.create()

        # simulate sending expired cookies
        with patch.dict(self.flask_app.config, {'PASSWD_COOKIE_TIMEOUT': -1}):
            url = '/project/%s/password?api_key=%s' % (project.short_name,
                                                       user.api_key)
            data = dict(password='******')
            res = self.app.post(url, data=data)

            c, v, e = get_pwd_cookie(project.short_name, res)

            assert c
            self.app.set_cookie('/', c, v)
            res = self.app.post(url, data=data)
            c, v, e = get_pwd_cookie(project.short_name, res)

            assert c

            url = '/project/%s/newtask?api_key=%s' % (project.short_name,
                                                      user.api_key)
            res = self.app.get(url, follow_redirects=True)
            assert 'Enter the password to contribute to this project' in res.data, res.data
コード例 #4
0
    def test_newtask_extends_expiration_by_timeout(self):
        """Test API project new_task extends expiration according to timeout"""
        project = ProjectFactory.create(
            info={
                'timeout':
                120 * 60,
                'data_classification':
                dict(input_data="L4 - public", output_data="L4 - public")
            })
        project.set_password('the_password')
        project_repo.save(project)
        TaskFactory.create_batch(2,
                                 project=project,
                                 info={'question': 'answer'})
        user = UserFactory.create()

        url = '/project/%s/password?api_key=%s' % (project.short_name,
                                                   user.api_key)
        data = dict(password='******')
        res = self.app.post(url, data=data)

        c, v, e = get_pwd_cookie(project.short_name, res)

        assert c
        self.app.set_cookie('/', c, v)

        now = datetime.utcnow()
        url = '/api/project/%s/newtask?api_key=%s' % (project.id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 200, (res, res.data)
        task = json.loads(res.data)
        assert task['info'].get('question') == 'answer'

        c, v, new_exp = get_pwd_cookie(project.short_name, res)
        assert new_exp - now > timedelta(minutes=115)
        assert new_exp - now < timedelta(minutes=125)
コード例 #5
0
    def test_get_task_user_pwd(self):
        """Get a list of tasks."""
        project = ProjectFactory.create()
        tasks = []
        project.set_password('hello')
        project_repo.save(project)
        num_task = 2
        tmp = TaskFactory.create_batch(num_task, project=project)
        for t in tmp:
            tasks.append(t)

        user = UserFactory.create()

        # no password - get a specific task
        url = '/api/task/%d?api_key=%s' % (tmp[0].id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 403, res.data
        data = json.loads(res.data)

        # no password - no task is returned
        url = '/api/task?project_id=%s&limit=100&all=1&api_key=%s' % (
            project.id, user.api_key)
        res = self.app.get(url)
        data = json.loads(res.data)
        assert len(data) == 0, len(data)

        url = '/project/%s/password?api_key=%s' % (project.short_name,
                                                   user.api_key)
        data = dict(password='******')
        res = self.app.post(url, data=data)
        c, v, r = get_pwd_cookie(project.short_name, res)

        self.app.set_cookie('/', c, v)

        # get a specific task
        url = '/api/task/%d?api_key=%s' % (tmp[0].id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 200, res.data
        data = json.loads(res.data)
        assert data['info'] == tmp[0].info, data

        # get a list of tasks
        url = '/api/task?project_id=%s&limit=100&all=1&api_key=%s' % (
            project.id, user.api_key)
        res = self.app.get(url)
        data = json.loads(res.data)
        assert len(data) == num_task, len(data)
コード例 #6
0
ファイル: test_newtask_passwd.py プロジェクト: rlarus/pybossa
    def test_newtask(self):
        """Test API project new_task method and authentication"""
        project = ProjectFactory.create()
        project.set_password('the_password')
        project_repo.save(project)
        TaskFactory.create_batch(2,
                                 project=project,
                                 info={'question': 'answer'})
        user = UserFactory.create()

        # anonymous
        # test getting a new task
        res = self.app.get('/api/project/%s/newtask' % project.id)
        assert res, res
        task = json.loads(res.data)
        assert 'error' in task['info'], 'No anonymous contributors'

        # as a real user, no password
        url = '/api/project/%s/newtask?api_key=%s' % (project.id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 403, res
        task = json.loads(res.data)
        assert task['exception_msg'] == 'No project password provided'

        url = '/project/%s/password?api_key=%s' % (project.short_name,
                                                   user.api_key)
        data = dict(password='******')
        res = self.app.post(url, data=data)

        c, v, e = get_pwd_cookie(project.short_name, res)

        assert c
        self.app.set_cookie('/', c, v)

        url = '/api/project/%s/newtask?api_key=%s' % (project.id, user.api_key)
        res = self.app.get(url)
        assert res.status_code == 200, res
        task = json.loads(res.data)
        assert task['info'].get('question') == 'answer'