14134.2.1
by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them. |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Tests for the translations views on a distroseries."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
from zope.security.interfaces import Unauthorized |
|
9 |
||
10 |
from canonical.launchpad.webapp import canonical_url |
|
11 |
from canonical.testing.layers import LaunchpadFunctionalLayer |
|
12 |
from lp.testing import ( |
|
13 |
person_logged_in, |
|
14 |
TestCaseWithFactory, |
|
15 |
)
|
|
16 |
from lp.testing.views import create_initialized_view |
|
17 |
||
18 |
||
19 |
class TestDistributionSettingsView(TestCaseWithFactory): |
|
20 |
"""Test distribution settings (+configure-translations) view."""
|
|
21 |
||
22 |
layer = LaunchpadFunctionalLayer |
|
23 |
||
24 |
def test_only_translation_fields(self): |
|
14134.2.5
by Danilo Segan
Add some comments to tests as suggested by Graham. |
25 |
# No fields other than translation fields are shown
|
26 |
# in the distribution translation settings form view.
|
|
14134.2.1
by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them. |
27 |
distribution = self.factory.makeDistribution() |
28 |
view = create_initialized_view( |
|
29 |
distribution, '+configure-translations', rootsite='translations') |
|
30 |
self.assertContentEqual( |
|
31 |
["translations_usage", |
|
32 |
"translation_focus", |
|
33 |
"translationgroup", |
|
34 |
"translationpermission", |
|
35 |
],
|
|
36 |
view.field_names) |
|
37 |
||
38 |
def test_unprivileged_users(self): |
|
14134.2.5
by Danilo Segan
Add some comments to tests as suggested by Graham. |
39 |
# Unprivileged users cannot access distribution translation settings
|
40 |
# page Distribution:+configure-translations.
|
|
14134.2.1
by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them. |
41 |
unprivileged = self.factory.makePerson() |
42 |
distribution = self.factory.makeDistribution() |
|
43 |
browser = self.getUserBrowser(user=unprivileged) |
|
44 |
url = canonical_url(distribution, view_name='+configure-translations', |
|
45 |
rootsite='translations') |
|
46 |
self.assertRaises(Unauthorized, browser.open, url) |
|
47 |
||
48 |
def test_translation_group_owner(self): |
|
49 |
# Translation group owner for a particular distribution has
|
|
14134.2.5
by Danilo Segan
Add some comments to tests as suggested by Graham. |
50 |
# launchpad.TranslationsAdmin privileges on it, meaning they
|
51 |
# can access Distribution:+configure-translations page.
|
|
14134.2.1
by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them. |
52 |
group = self.factory.makeTranslationGroup() |
53 |
distribution = self.factory.makeDistribution() |
|
54 |
with person_logged_in(distribution.owner): |
|
55 |
distribution.translationgroup = group |
|
56 |
browser = self.getUserBrowser(user=group.owner) |
|
57 |
url = canonical_url(distribution, view_name='+configure-translations', |
|
58 |
rootsite='translations') |
|
59 |
# No "Unauthorized" exception is thrown.
|
|
60 |
browser.open(url) |
|
61 |
||
62 |
def test_distribution_owner(self): |
|
14134.2.5
by Danilo Segan
Add some comments to tests as suggested by Graham. |
63 |
# Distribution owner of a particular distribution has
|
64 |
# launchpad.TranslationsAdmin privileges on it, meaning they
|
|
65 |
# can access Distribution:+configure-translations page.
|
|
14134.2.1
by Danilo Segan
Show only relevant fields for distribution translation settings and fix privileges for them. |
66 |
distribution = self.factory.makeDistribution() |
67 |
browser = self.getUserBrowser(user=distribution.owner) |
|
68 |
url = canonical_url(distribution, view_name='+configure-translations', |
|
69 |
rootsite='translations') |
|
70 |
# No "Unauthorized" exception is thrown.
|
|
71 |
browser.open(url) |