Exemple #1
0
    def _test_get_breadth_first_task(self, user=None, external_uid=None):
        self.del_task_runs()
        if user:
            short_name = 'xyzuser'
        else:
            short_name = 'xyznouser'

        category = db.session.query(Category).get(1)
        project = Project(short_name=short_name, name=short_name,
              description=short_name, category=category)
        owner = db.session.query(User).get(1)

        project.owner = owner
        task = Task(project=project, state='0', info={})
        task2 = Task(project=project, state='0', info={})
        task.project = project
        task2.project = project
        db.session.add(project)
        db.session.add(task)
        db.session.add(task2)
        db.session.commit()
        taskid = task.id
        projectid = project.id
        # give task2 a bunch of runs
        for idx in range(2):
            self._add_task_run(project, task2)

        # now check we get task without task runs as anonymous user
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == taskid, out

        # now check we get task without task runs as a user
        owner = db.session.query(User).get(1)
        out = pybossa.sched.get_breadth_first_task(projectid, owner.id)
        assert out.id == taskid, out

        # now check we get task without task runs as a external uid
        out = pybossa.sched.get_breadth_first_task(projectid,
                                                   external_uid=external_uid)
        assert out.id == taskid, out


        # now check that offset works
        out1 = pybossa.sched.get_breadth_first_task(projectid)
        out2 = pybossa.sched.get_breadth_first_task(projectid, offset=1)
        assert out1.id != out2.id, out

        # asking for a bigger offset (max 10)
        out2 = pybossa.sched.get_breadth_first_task(projectid, offset=11)
        assert out2 is None, out

        self._add_task_run(project, task)
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == taskid, out

        # now add 2 more taskruns. We now have 3 and 2 task runs per task
        self._add_task_run(project, task)
        self._add_task_run(project, task)
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == task2.id, out
Exemple #2
0
    def _test_get_breadth_first_task(self, user=None):
        self.del_task_runs()
        if user:
            short_name = 'xyzuser'
        else:
            short_name = 'xyznouser'

        category = db.session.query(Category).get(1)
        project = Project(short_name=short_name,
                          name=short_name,
                          description=short_name,
                          category=category)
        owner = db.session.query(User).get(1)

        project.owner = owner
        task = Task(project=project, state='0', info={})
        task2 = Task(project=project, state='0', info={})
        task.project = project
        task2.project = project
        db.session.add(project)
        db.session.add(task)
        db.session.add(task2)
        db.session.commit()
        taskid = task.id
        projectid = project.id
        # give task2 a bunch of runs
        for idx in range(2):
            self._add_task_run(project, task2)

        # now check we get task without task runs as anonymous user
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == taskid, out

        # now check we get task without task runs as a user
        owner = db.session.query(User).get(1)
        out = pybossa.sched.get_breadth_first_task(projectid, owner.id)
        assert out.id == taskid, out

        # now check that offset works
        out1 = pybossa.sched.get_breadth_first_task(projectid)
        out2 = pybossa.sched.get_breadth_first_task(projectid, offset=1)
        assert out1.id != out2.id, out

        # asking for a bigger offset (max 10)
        out2 = pybossa.sched.get_breadth_first_task(projectid, offset=11)
        assert out2 is None, out

        self._add_task_run(project, task)
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == taskid, out

        # now add 2 more taskruns. We now have 3 and 2 task runs per task
        self._add_task_run(project, task)
        self._add_task_run(project, task)
        out = pybossa.sched.get_breadth_first_task(projectid)
        assert out.id == task2.id, out
Exemple #3
0
    def test_all(self):
        """Test MODEL works"""
        username = u'test-user-1'
        user = User(name=username, fullname=username, email_addr=username)
        info = {
            'total': 150,
            'long_description': 'hello world'}
        project = Project(
            name=u'My New Project',
            short_name=u'my-new-app',
            description=u'description',
            info=info)
        category = Category(name=u'cat', short_name=u'cat', description=u'cat')
        project.category = category
        project.owner = user
        task_info = {
            'question': 'My random question',
            'url': 'my url'}
        task = Task(info=task_info)
        task_run_info = {'answer': u'annakarenina'}
        task_run = TaskRun(info=task_run_info)
        task.project = project
        task_run.task = task
        task_run.project = project
        task_run.user = user
        db.session.add_all([user, project, task, task_run])
        db.session.commit()
        project_id = project.id

        db.session.remove()

        project = db.session.query(Project).get(project_id)
        assert project.name == u'My New Project', project
        # year would start with 201...
        assert project.created.startswith('201'), project.created
        assert project.long_tasks == 0, project.long_tasks
        assert project.hidden == 0, project.hidden
        assert project.time_estimate == 0, project
        assert project.time_limit == 0, project
        assert project.calibration_frac == 0, project
        assert project.bolt_course_id == 0
        assert len(project.tasks) == 1, project
        assert project.owner.name == username, project
        out_task = project.tasks[0]
        assert out_task.info['question'] == task_info['question'], out_task
        assert out_task.quorum == 0, out_task
        assert out_task.state == "ongoing", out_task
        assert out_task.calibration == 0, out_task
        assert out_task.priority_0 == 0, out_task
        assert len(out_task.task_runs) == 1, out_task
        outrun = out_task.task_runs[0]
        assert outrun.info['answer'] == task_run_info['answer'], outrun
        assert outrun.user.name == username, outrun
Exemple #4
0
    def test_all(self):
        """Test MODEL works"""
        username = u'test-user-1'
        user = User(name=username, fullname=username, email_addr=username)
        info = {'total': 150, 'long_description': 'hello world'}
        project = Project(name=u'My New Project',
                          short_name=u'my-new-app',
                          description=u'description',
                          info=info)
        category = Category(name=u'cat', short_name=u'cat', description=u'cat')
        project.category = category
        project.owner = user
        task_info = {'question': 'My random question', 'url': 'my url'}
        task = Task(info=task_info)
        task_run_info = {'answer': u'annakarenina'}
        task_run = TaskRun(info=task_run_info)
        task.project = project
        task_run.task = task
        task_run.project = project
        task_run.user = user
        db.session.add_all([user, project, task, task_run])
        db.session.commit()
        project_id = project.id

        db.session.remove()

        project = db.session.query(Project).get(project_id)
        assert project.name == u'My New Project', project
        # year would start with 201...
        assert project.created.startswith('201'), project.created
        assert project.long_tasks == 0, project.long_tasks
        assert project.hidden == 0, project.hidden
        assert project.time_estimate == 0, project
        assert project.time_limit == 0, project
        assert project.calibration_frac == 0, project
        assert project.bolt_course_id == 0
        assert len(project.tasks) == 1, project
        assert project.owner.name == username, project
        out_task = project.tasks[0]
        assert out_task.info['question'] == task_info['question'], out_task
        assert out_task.quorum == 0, out_task
        assert out_task.state == "ongoing", out_task
        assert out_task.calibration == 0, out_task
        assert out_task.priority_0 == 0, out_task
        assert len(out_task.task_runs) == 1, out_task
        outrun = out_task.task_runs[0]
        assert outrun.info['answer'] == task_run_info['answer'], outrun
        assert outrun.user.name == username, outrun