12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Tests for IFAQ"""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
from zope.component import getUtility |
|
9 |
||
14600.2.2
by Curtis Hovey
Moved webapp to lp.services. |
10 |
from lp.services.webapp.authorization import check_permission |
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
11 |
from lp.services.worlddata.interfaces.language import ILanguageSet |
12 |
from lp.testing import ( |
|
13 |
login_person, |
|
14 |
person_logged_in, |
|
15 |
TestCaseWithFactory, |
|
16 |
)
|
|
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
17 |
from lp.testing.layers import DatabaseFunctionalLayer |
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
18 |
|
19 |
||
20 |
class TestFAQPermissions(TestCaseWithFactory): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
21 |
"""Test who can edit FAQs."""
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
22 |
|
23 |
layer = DatabaseFunctionalLayer |
|
24 |
||
25 |
def setUp(self): |
|
26 |
super(TestFAQPermissions, self).setUp() |
|
27 |
target = self.factory.makeProduct() |
|
28 |
self.owner = target.owner |
|
29 |
with person_logged_in(self.owner): |
|
30 |
self.faq = self.factory.makeFAQ(target=target) |
|
31 |
||
32 |
def addAnswerContact(self, answer_contact): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
33 |
"""Add the test person to the faq target's answer contacts."""
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
34 |
language_set = getUtility(ILanguageSet) |
35 |
answer_contact.addLanguage(language_set['en']) |
|
12959.4.21
by Curtis Hovey
Alway pass the subscribed_by argument to addAnswerContact. |
36 |
self.faq.target.addAnswerContact(answer_contact, answer_contact) |
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
37 |
|
38 |
def assertCanEdit(self, user, faq): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
39 |
"""Assert that the user can edit an FAQ."""
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
40 |
can_edit = check_permission('launchpad.Edit', faq) |
41 |
self.assertTrue(can_edit, 'User cannot edit %s' % faq) |
|
42 |
||
43 |
def assertCannotEdit(self, user, faq): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
44 |
"""Assert that the user cannot edit an FAQ."""
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
45 |
can_edit = check_permission('launchpad.Edit', faq) |
46 |
self.assertFalse(can_edit, 'User can edit edit %s' % faq) |
|
47 |
||
48 |
def test_owner_can_edit(self): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
49 |
# The owner of an FAQ target can edit its FAQs.
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
50 |
login_person(self.owner) |
51 |
self.assertCanEdit(self.owner, self.faq) |
|
52 |
||
53 |
def test_direct_answer_contact_can_edit(self): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
54 |
# A direct answer contact for an FAQ target can edit its FAQs.
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
55 |
direct_answer_contact = self.factory.makePerson() |
56 |
login_person(direct_answer_contact) |
|
57 |
self.addAnswerContact(direct_answer_contact) |
|
58 |
self.assertCanEdit(direct_answer_contact, self.faq) |
|
59 |
||
60 |
def test_indirect_answer_contact_can_edit(self): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
61 |
# A indirect answer contact (a member of a team that is an answer
|
62 |
# contact) for an FAQ target can edit its FAQs.
|
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
63 |
indirect_answer_contact = self.factory.makePerson() |
64 |
direct_answer_contact = self.factory.makeTeam() |
|
65 |
with person_logged_in(direct_answer_contact.teamowner): |
|
66 |
direct_answer_contact.addMember( |
|
67 |
indirect_answer_contact, direct_answer_contact.teamowner) |
|
68 |
self.addAnswerContact(direct_answer_contact) |
|
69 |
login_person(indirect_answer_contact) |
|
70 |
self.assertCanEdit(indirect_answer_contact, self.faq) |
|
71 |
||
72 |
def test_nonparticipating_user_cannot_edit(self): |
|
12014.2.11
by Curtis Hovey
Fixed comments and docstrings. |
73 |
# A user that is neither an owner of, or answer contact for, an
|
74 |
# FAQ target's cannot edit a its FAQs.
|
|
12014.2.7
by Curtis Hovey
Added persmission tests for IFAQ. |
75 |
nonparticipant = self.factory.makePerson() |
76 |
login_person(nonparticipant) |
|
77 |
self.assertCannotEdit(nonparticipant, self.faq) |