~launchpad-pqm/launchpad/devel

7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
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
"""Test Archive software center agent celebrity."""
5
6
from zope.component import getUtility
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
7
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
8
from canonical.launchpad.webapp.authorization import check_permission
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
9
from canonical.testing.layers import LaunchpadFunctionalLayer
13130.1.12 by Curtis Hovey
Sorted imports.
10
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
11
from lp.soyuz.interfaces.archivesubscriber import IArchiveSubscriberSet
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
12
from lp.testing import (
13
    login,
14
    login_person,
15
    TestCaseWithFactory,
16
    )
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
17
18
19
class TestArchivePrivacy(TestCaseWithFactory):
20
    layer = LaunchpadFunctionalLayer
21
22
    def setUp(self):
23
        super(TestArchivePrivacy, self).setUp()
7675.732.2 by Steve Kowalik
* Add a missing section to the security adapter for .Append
24
        self.ppa = self._makePrivateArchive()
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
25
        self.ppa.commercial = True
7675.744.9 by Steve Kowalik
* Correct a typo in test_archive_agent.
26
        self.agent = getUtility(ILaunchpadCelebrities).software_center_agent
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
27
        self.joe = self.factory.makePerson(name='joe')
28
7675.732.2 by Steve Kowalik
* Add a missing section to the security adapter for .Append
29
    def _makePrivateArchive(self):
30
        ppa = self.factory.makeArchive()
31
        login('admin@canonical.com')
32
        ppa.buildd_secret = 'blah'
33
        ppa.private = True
34
        return ppa
35
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
36
    def test_check_permission(self):
37
        """The software center agent has the relevant permissions for a
38
        commercial archive, but not a private one.
39
        """
40
        login_person(self.agent)
41
        self.assertEqual(
42
            check_permission('launchpad.View', self.ppa), True)
43
        self.assertEqual(
44
            check_permission('launchpad.Append', self.ppa), True)
45
46
    def test_check_permission_private(self):
7675.732.2 by Steve Kowalik
* Add a missing section to the security adapter for .Append
47
        ppa = self._makePrivateArchive()
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
48
        login_person(self.agent)
49
        self.assertEqual(check_permission('launchpad.View', ppa), False)
50
        self.assertEqual(check_permission('launchpad.Append', ppa), False)
51
52
    def test_add_subscription(self):
53
        login_person(self.agent)
54
        self.ppa.newSubscription(self.joe, self.agent)
55
        subscription = getUtility(
56
            IArchiveSubscriberSet).getBySubscriber(
57
            self.joe, archive=self.ppa).one()
58
        self.assertEqual(subscription.registrant, self.agent)
59
        self.assertEqual(subscription.subscriber, self.joe)
60
7675.744.1 by Steve Kowalik
* Rename .getPrivateSourcesList() to .getArchiveSubscriptionURL(), and shift
61
    def test_getArchiveSubscriptionURL(self):
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
62
        login_person(self.agent)
7675.744.1 by Steve Kowalik
* Rename .getPrivateSourcesList() to .getArchiveSubscriptionURL(), and shift
63
        sources = self.joe.getArchiveSubscriptionURL(self.agent, self.ppa)
7675.732.1 by Steve Kowalik
* Add the software-center-agent celebrity.
64
        authtoken = self.ppa.getAuthToken(self.joe).token
65
        url = self.ppa.archive_url.split('http://')[1]
66
        new_url = "http://joe:%s@%s" % (authtoken, url)
67
        self.assertEqual(sources, new_url)