Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
therealmarv committed Jan 31, 2017
2 parents d289d56 + b7586c6 commit 1adddd1
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 73 deletions.
23 changes: 23 additions & 0 deletions doc/api.rst
Expand Up @@ -2133,3 +2133,26 @@ Gives you the cookie policy for your PYBOSSA
"template": "help/cookies_policy.html",
"title": "Help: Cookies Policy"
}
Help terms of use
~~~~~~~~~~~~~~~~~
**Endpoint: /help/terms-of-use**
*Allowed methods*: **GET**
**GET**
Gives you the terms of use for your PYBOSSA
* **content**: Simplified HTML of rendered terms of use.
* **template**: The Jinja2 template that could be rendered.
* **title**: the title for the endpoint.
**Example output**
.. code-block:: python
{
"content": "<html><body><p>Terms of use text</p></body></html>"
"template": "help/tos.html",
"title": "Help: Terms of Use"
}
9 changes: 6 additions & 3 deletions pybossa/jobs.py
Expand Up @@ -355,6 +355,7 @@ def warm_cache(): # pragma: no cover
import pybossa.cache.users as cached_users
import pybossa.cache.project_stats as stats
from pybossa.util import rank
from pybossa.core import user_repo

def warm_project(_id, short_name, featured=False):
if _id not in projects_cached:
Expand Down Expand Up @@ -393,10 +394,12 @@ def warm_project(_id, short_name, featured=False):
users = cached_users.get_leaderboard(app.config['LEADERBOARD'])
for user in users:
# print "Getting stats for %s" % user['name']
print user_repo
u = user_repo.get_by_name(user['name'])
cached_users.get_user_summary(user['name'])
cached_users.projects_contributed_cached(user['id'])
cached_users.published_projects_cached(user['id'])
cached_users.draft_projects_cached(user['id'])
cached_users.projects_contributed_cached(u.id)
cached_users.published_projects_cached(u.id)
cached_users.draft_projects_cached(u.id)

return True

Expand Down
91 changes: 45 additions & 46 deletions pybossa/model/event_listeners.py
Expand Up @@ -44,16 +44,15 @@ def add_blog_event(mapper, conn, target):
sql_query = ('select name, short_name, info from project \
where id=%s') % target.project_id
results = conn.execute(sql_query)
obj = dict(id=target.project_id,
name=None,
short_name=None,
info=None,
action_updated='Blog')
obj = dict(action_updated='Blog')
tmp = dict()
for r in results:
obj['name'] = r.name
obj['short_name'] = r.short_name
# TODO: add only public info
# obj['info'] = r.info
tmp['id'] = target.project_id
tmp['name'] = r.name
tmp['short_name'] = r.short_name
tmp['info'] = r.info
tmp = Project().to_public_json(tmp)
obj.update(tmp)
update_feed(obj)
# Notify volunteers
mail_queue.enqueue(notify_blog_users,
Expand All @@ -64,10 +63,13 @@ def add_blog_event(mapper, conn, target):
@event.listens_for(Project, 'after_insert')
def add_project_event(mapper, conn, target):
"""Update PYBOSSA feed with new project."""
obj = dict(id=target.id,
tmp = dict(id=target.id,
name=target.name,
short_name=target.short_name,
action_updated='Project')
info=target.info)
obj = dict(action_updated='Project')
tmp = Project().to_public_json(tmp)
obj.update(tmp)
update_feed(obj)


Expand All @@ -77,16 +79,15 @@ def add_task_event(mapper, conn, target):
sql_query = ('select name, short_name, info from project \
where id=%s') % target.project_id
results = conn.execute(sql_query)
obj = dict(id=target.project_id,
name=None,
short_name=None,
info=None,
action_updated='Task')
obj = dict(action_updated='Task')
tmp = dict()
for r in results:
obj['name'] = r.name
obj['short_name'] = r.short_name
# TODO: add only public info
# obj['info'] = r.info
tmp['id'] = target.project_id
tmp['name'] = r.name
tmp['short_name'] = r.short_name
tmp['info'] = r.info
tmp = Project().to_public_json(tmp)
obj.update(tmp)
update_feed(obj)


Expand All @@ -104,15 +105,15 @@ def add_user_contributed_to_feed(conn, user_id, project_obj):
where id=%s') % user_id
results = conn.execute(sql_query)
for r in results:
obj = dict(id=user_id,
tmp = dict(id=user_id,
name=r.name,
fullname=r.fullname,
# TODO: update with only public items.
#info=r.info,
project_name=project_obj['name'],
project_short_name=project_obj['short_name'],
action_updated='UserContribution')
update_feed(obj)
info=r.info)
tmp = User().to_public_json(tmp)
tmp['project_name'] = project_obj['name']
tmp['project_short_name'] = project_obj['short_name']
tmp['action_updated'] = 'UserContribution'
update_feed(tmp)


def is_task_completed(conn, task_id):
Expand Down Expand Up @@ -186,30 +187,28 @@ def on_taskrun_submit(mapper, conn, target):
sql_query = ('select name, short_name, published, webhook, info from project \
where id=%s') % target.project_id
results = conn.execute(sql_query)
project_obj = dict(id=target.project_id,
name=None,
short_name=None,
published=False,
info=None,
webhook=None,
action_updated='TaskCompleted')
tmp = dict()
for r in results:
project_obj['name'] = r.name
project_obj['short_name'] = r.short_name
project_obj['published'] = r.published
# TODO: update with public data
# project_obj['info'] = r.info
# project_obj['webhook'] = r.webhook
tmp['name'] = r.name
tmp['short_name'] = r.short_name
_published = r.published
tmp['info'] = r.info
_webhook = r.webhook
project_obj['id'] = target.project_id
tmp['id'] = target.project_id

project_public = dict()
project_public.update(Project().to_public_json(tmp))
project_public['action_updated'] = 'TaskCompleted'

add_user_contributed_to_feed(conn, target.user_id, project_obj)
if is_task_completed(conn, target.task_id) and project_obj['published']:
add_user_contributed_to_feed(conn, target.user_id, project_public)
if is_task_completed(conn, target.task_id) and _published:
update_task_state(conn, target.task_id)
update_feed(project_obj)
update_feed(project_public)
result_id = create_result(conn, target.project_id, target.task_id)
project_obj['webhook'] = _webhook
push_webhook(project_obj, target.task_id, result_id)
project_private = dict()
project_private.update(project_public)
project_private['webhook'] = _webhook
push_webhook(project_private, target.task_id, result_id)


@event.listens_for(Blogpost, 'after_insert')
Expand Down
10 changes: 8 additions & 2 deletions pybossa/view/help.py
Expand Up @@ -43,13 +43,19 @@ def api():
@blueprint.route('/license')
def license():
"""Render help/license page."""
return render_template('help/license.html', title='Help: Licenses')
response = dict(template='help/license.html',
title='Help: Licenses')
return handle_content_type(response)


@blueprint.route('/terms-of-use')
def tos():
"""Render help/terms-of-use page."""
return render_template('help/tos.html', title='Help: Terms of Use')
cleaned_up_content = Document(render_template('help/tos.html')).summary()
response = dict(template='help/tos.html',
content=cleaned_up_content,
title='Help: Terms of Use')
return handle_content_type(response)


@blueprint.route('/cookies-policy')
Expand Down
1 change: 0 additions & 1 deletion test/test_activity_update.py
Expand Up @@ -74,7 +74,6 @@ def test_taskrun_creation(self):
task_run = TaskRunFactory.create()
update_feed = get_update_feed()
err_msg = "It should be the same task_run"
assert update_feed[0]['id'] == task_run.user.id, err_msg
assert update_feed[0]['name'] == task_run.user.name, err_msg
assert update_feed[0]['fullname'] == task_run.user.fullname, err_msg
assert update_feed[0]['project_name'] == task_run.project.name, err_msg
Expand Down
13 changes: 13 additions & 0 deletions test/test_jobs/test_project_stats.py
Expand Up @@ -17,9 +17,12 @@
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.

from pybossa.jobs import get_project_jobs, create_dict_jobs, get_project_stats
from pybossa.jobs import warm_cache
from default import Test, with_context
from factories import ProjectFactory
from factories import UserFactory
from factories import TaskRunFactory
from factories import TaskFactory


class TestProjectsStats(Test):
Expand Down Expand Up @@ -79,3 +82,13 @@ def test_get_project_jobs_for_non_pro_users(self):

err_msg = "There should be only 0 jobs"
assert len(jobs) == 0, err_msg

@with_context
def test_warm_project(self):
"""Test JOB warm_project works."""
project = ProjectFactory.create()
task = TaskFactory.create(n_answers=1)
for i in range(0,30):
TaskRunFactory.create(project=project, task=task)
res = warm_cache()
assert res, res
82 changes: 61 additions & 21 deletions test/test_model/test_event_listeners.py
Expand Up @@ -39,32 +39,38 @@ def test_add_blog_event(self, mock_queue, mock_update_feed):
target = MagicMock()
target.id = 1
target.project_id = 1
tmp = MagicMock()
tmp.name = 'name'
tmp.short_name = 'short_name'
tmp.info = dict()
tmp = Project(id=1, name='name', short_name='short_name',
info=dict(container=1, thumbnail="avatar.png"))
conn.execute.return_value = [tmp]
add_blog_event(None, conn, target)
mock_queue.enqueue.assert_called_with(notify_blog_users,
blog_id=target.id,
project_id=target.project_id)
assert mock_update_feed.called
obj = tmp.to_public_json()
obj['action_updated'] = 'Blog'
mock_update_feed.assert_called_with(obj)

@with_context
@patch('pybossa.model.event_listeners.update_feed')
def test_add_project_event(self, mock_update_feed):
"""Test add_project_event is called."""
conn = MagicMock()
target = MagicMock()
target.id = 1
target.project_id = 1
tmp = MagicMock()
tmp.name = 'name'
tmp.short_name = 'short_name'
tmp.info = dict()
tmp = Project(id=1, name='name', short_name='short_name',
info=dict(container=1, thumbnail="avatar.png"))
target.id = tmp.id
target.project_id = tmp.id
target.name = tmp.name
target.short_name = tmp.short_name
target.info = tmp.info

conn.execute.return_value = [tmp]
add_project_event(None, conn, target)
assert mock_update_feed.called
obj = tmp.to_public_json()
obj['action_updated'] = 'Project'
mock_update_feed.assert_called_with(obj)

@with_context
@patch('pybossa.model.event_listeners.update_feed')
Expand All @@ -74,29 +80,63 @@ def test_add_task_event(self, mock_update_feed):
target = MagicMock()
target.id = 1
target.project_id = 1
tmp = MagicMock()
tmp.name = 'name'
tmp.short_name = 'short_name'
tmp.info = dict()
tmp = Project(id=1, name='name', short_name='short_name',
info=dict(container=1, thumbnail="avatar.png"))
conn.execute.return_value = [tmp]
add_task_event(None, conn, target)
assert mock_update_feed.called
obj = tmp.to_public_json()
obj['action_updated'] = 'Task'
mock_update_feed.assert_called_with(obj)

@with_context
@patch('pybossa.model.event_listeners.push_webhook')
@patch('pybossa.model.event_listeners.create_result', return_value=1)
@patch('pybossa.model.event_listeners.update_task_state')
@patch('pybossa.model.event_listeners.is_task_completed', return_value=True)
@patch('pybossa.model.event_listeners.add_user_contributed_to_feed')
@patch('pybossa.model.event_listeners.update_feed')
def test_add_user_event(self, mock_update_feed):
"""Test add_user_event is called."""
def test_on_taskrun_submit_event(self, mock_update_feed,
mock_add_user,
mock_is_task,
mock_update_task,
mock_create_result,
mock_push):
"""Test on_taskrun_submit is called."""
conn = MagicMock()
target = MagicMock()
target.id = 1
target.project_id = 1
tmp = MagicMock()
tmp.name = 'name'
tmp.short_name = 'short_name'
tmp.info = dict()
target.task_id = 2
target.user_id = 3
tmp = Project(id=1, name='name', short_name='short_name',
info=dict(container=1, thumbnail="avatar.png"),
published=True,
webhook='http://localhost.com')
conn.execute.return_value = [tmp]
add_user_event(None, conn, target)
on_taskrun_submit(None, conn, target)
obj = tmp.to_public_json()
obj['action_updated'] = 'TaskCompleted'
mock_add_user.assert_called_with(conn, target.user_id, obj)
mock_update_task.assert_called_with(conn, target.task_id)
mock_update_feed.assert_called_once_with(obj)
obj_with_webhook = tmp.to_public_json()
obj_with_webhook['webhook'] = tmp.webhook
obj_with_webhook['action_updated'] = 'TaskCompleted'
mock_push.assert_called_with(obj_with_webhook, target.task_id, 1)


@with_context
@patch('pybossa.model.event_listeners.update_feed')
def test_add_user_event(self, mock_update_feed):
"""Test add_user_event is called."""
conn = MagicMock()
user = User(name="John", fullname="John")
add_user_event(None, conn, user)
assert mock_update_feed.called
obj = user.to_public_json()
obj['action_updated'] = 'User'
mock_update_feed.assert_called_with(obj)

@with_context
@patch('pybossa.model.event_listeners.create_result')
Expand Down

0 comments on commit 1adddd1

Please sign in to comment.