test_project_publish.py
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2015 SF Isle of Man Limited
#
# PyBossa is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa. If not, see <http://www.gnu.org/licenses/>.
from mock import patch
from default import db
from factories import ProjectFactory, TaskFactory, UserFactory
from helper import web
from pybossa.repositories import UserRepository
from pybossa.repositories import ProjectRepository
from pybossa.view.projects import render_template
project_repo = ProjectRepository(db)
user_repo = UserRepository(db)
class TestProjectPublicationView(web.Helper):
def setUp(self):
super(TestProjectPublicationView, self).setUp()
self.owner = UserFactory.create(email_addr='a@a.com')
self.owner.set_password('1234')
user_repo.save(self.owner)
self.project = ProjectFactory.create(owner=self.owner, published=False)
self.signin(email='a@a.com', password='1234')
@patch('pybossa.view.projects.ensure_authorized_to')
def test_it_checks_permissions_over_project(self, fake_auth):
post_resp = self.app.get('/project/%s/publish' % self.project.short_name)
get_resp = self.app.post('/project/%s/publish' % self.project.short_name)
call_args = fake_auth.call_args_list
assert fake_auth.call_count == 2, fake_auth.call_count
assert call_args[0][0][0] == 'publish', call_args[0]
assert call_args[0][0][1].id == self.project.id, call_args[0]
assert call_args[1][0][0] == 'publish', call_args[1]
assert call_args[1][0][1].id == self.project.id, call_args[1]
@patch('pybossa.view.projects.render_template', wraps=render_template)
def test_it_renders_template_when_get(self, fake_render):
TaskFactory.create(project=self.project)
resp = self.app.get('/project/%s/publish' % self.project.short_name)
call_args = fake_render.call_args_list
assert call_args[0][0][0] == 'projects/publish.html', call_args[0]
assert call_args[0][1]['project'].id == self.project.id, call_args[0]
def test_it_changes_project_to_published_after_post(self):
TaskFactory.create(project=self.project)
resp = self.app.post('/project/%s/publish' % self.project.short_name,
follow_redirects=True)
project = project_repo.get(self.project.id)
assert resp.status_code == 200, resp.status_code
assert project.published == True, project
@patch('pybossa.view.projects.auditlogger')
def test_it_logs_the_event_in_auditlog(self, fake_logger):
TaskFactory.create(project=self.project)
resp = self.app.post('/project/%s/publish' % self.project.short_name,
follow_redirects=True)
assert fake_logger.log_event.called, "Auditlog not called"