def test_browse_tasks_returns_pct_status(self): """Test CACHE PROJECTS browse_tasks returns also the completion percentage of each task""" project = ProjectFactory.create() task = TaskFactory.create(project=project, info={}, n_answers=4) count, cached_tasks = cached_projects.browse_tasks(project.id, {}) # 0 if no task runs assert cached_tasks[0].get('pct_status') == 0, cached_tasks[0].get( 'pct_status') TaskRunFactory.create(task=task) count, cached_tasks = cached_projects.browse_tasks(project.id, {}) # Gets updated with new task runs assert cached_tasks[0].get('pct_status') == 0.25, cached_tasks[0].get( 'pct_status') TaskRunFactory.create_batch(3, task=task) count, cached_tasks = cached_projects.browse_tasks(project.id, {}) # To a maximum of 1 assert cached_tasks[0].get('pct_status') == 1.0, cached_tasks[0].get( 'pct_status') TaskRunFactory.create(task=task) count, cached_tasks = cached_projects.browse_tasks(project.id, {}) # And it does not go over 1 (that is 100%!!) assert cached_tasks[0].get('pct_status') == 1.0, cached_tasks[0].get( 'pct_status')
def test_browse_tasks_returns_pct_status(self): """Test CACHE PROJECTS browse_tasks returns also the completion percentage of each task""" project = ProjectFactory.create() task = TaskFactory.create( project=project, info={}, n_answers=4) cached_task = cached_projects.browse_tasks(project.id)[0] # 0 if no task runs assert cached_task.get('pct_status') == 0, cached_task.get('pct_status') TaskRunFactory.create(task=task) cached_task = cached_projects.browse_tasks(project.id)[0] # Gets updated with new task runs assert cached_task.get('pct_status') == 0.25, cached_task.get('pct_status') TaskRunFactory.create_batch(3, task=task) cached_task = cached_projects.browse_tasks(project.id)[0] # To a maximum of 1 assert cached_task.get('pct_status') == 1.0, cached_task.get('pct_status') TaskRunFactory.create(task=task) cached_task = cached_projects.browse_tasks(project.id)[0] # And it does not go over 1 (that is 100%!!) assert cached_task.get('pct_status') == 1.0, cached_task.get('pct_status')
def warm_project(_id, short_name, featured=False): if _id not in projects_cached: cached_projects.get_project(short_name) cached_projects.n_tasks(_id) n_task_runs = cached_projects.n_task_runs(_id) cached_projects.overall_progress(_id) cached_projects.last_activity(_id) cached_projects.n_completed_tasks(_id) cached_projects.n_volunteers(_id) cached_projects.browse_tasks(_id) if n_task_runs >= 1000 or featured: # print ("Getting stats for %s as it has %s task runs" % # (short_name, n_task_runs)) stats.get_stats(_id, app.config.get('GEO')) projects_cached.append(_id)
def get_project_stats(_id, short_name): # pragma: no cover """Get stats for project.""" import pybossa.cache.projects as cached_projects import pybossa.cache.project_stats as stats from flask import current_app cached_projects.get_project(short_name) cached_projects.n_tasks(_id) cached_projects.n_task_runs(_id) cached_projects.overall_progress(_id) cached_projects.last_activity(_id) cached_projects.n_completed_tasks(_id) cached_projects.n_volunteers(_id) cached_projects.browse_tasks(_id) stats.get_stats(_id, current_app.config.get('GEO'))
def test_browse_tasks_returns_no_tasks(self): """Test CACHE PROJECTS browse_tasks returns an empty list if a project has no tasks""" project = ProjectFactory.create() browse_tasks = cached_projects.browse_tasks(project.id) assert browse_tasks == [], browse_tasks
def test_browse_tasks_returns_no_tasks(self): """Test CACHE PROJECTS browse_tasks returns an empty list if a project has no tasks""" project = ProjectFactory.create() count, browse_tasks = cached_projects.browse_tasks(project.id, {}) assert browse_tasks == [], browse_tasks
def test_browse_tasks_returns_all_tasks(self): """Test CACHE PROJECTS browse_tasks returns a list with all the tasks from a given project""" project = ProjectFactory.create() TaskFactory.create_batch(2, project=project) browse_tasks = cached_projects.browse_tasks(project.id) assert len(browse_tasks) == 2, browse_tasks
def test_browse_completed(self): project = ProjectFactory.create() task = TaskFactory.create(project=project, info={}, n_answers=2) TaskRunFactory.create_batch(3, task=task) count, cached_tasks = cached_projects.browse_tasks( project.id, {'pcomplete_to': 100}) assert count == 1 assert cached_tasks[0]['id'] == task.id
def test_browse_tasks_returns_all_tasks(self): """Test CACHE PROJECTS browse_tasks returns a list with all the tasks from a given project""" project = ProjectFactory.create() TaskFactory.create_batch(2, project=project) count, browse_tasks = cached_projects.browse_tasks(project.id, {}) assert len(browse_tasks) == 2, browse_tasks
def test_browse_tasks_returns_required_attributes(self): """Test CACHE PROJECTS browse_tasks returns a list with objects with the required task attributes""" project = ProjectFactory.create() task = TaskFactory.create( project=project, info={}) attributes = ('id', 'n_answers') cached_task = cached_projects.browse_tasks(project.id)[0] for attr in attributes: assert cached_task.get(attr) == getattr(task, attr), attr
def test_browse_tasks_returns_required_attributes(self): """Test CACHE PROJECTS browse_tasks returns a list with objects with the required task attributes""" project = ProjectFactory.create() task = TaskFactory.create(project=project, info={}) attributes = ('id', 'n_answers') cached_task = cached_projects.browse_tasks(project.id)[0] for attr in attributes: assert cached_task.get(attr) == getattr(task, attr), attr