~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/browser/tests/test_distribution_views.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-12 16:06:12 UTC
  • mfrom: (14134.2.6 bug-872715)
  • Revision ID: launchpad@pqm.canonical.com-20111012160612-m9kkf1exifsazgxo
[r=gmb][bug=872715] Get rid of builder-related fields from
 distribution:+configure-translations page and ensure TranslationsAdmin can
 modify all the relevant attributes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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):
 
25
        # No fields other than translation fields are shown
 
26
        # in the distribution translation settings form view.
 
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):
 
39
        # Unprivileged users cannot access distribution translation settings
 
40
        # page Distribution:+configure-translations.
 
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
 
50
        # launchpad.TranslationsAdmin privileges on it, meaning they
 
51
        # can access Distribution:+configure-translations page.
 
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):
 
63
        # Distribution owner of a particular distribution has
 
64
        # launchpad.TranslationsAdmin privileges on it, meaning they
 
65
        # can access Distribution:+configure-translations page.
 
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)