~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_distribution.py

  • Committer: Stuart Bishop
  • Date: 2011-11-14 07:51:26 UTC
  • mfrom: (14291 devel)
  • mto: This revision was merged to the branch mainline in revision 14299.
  • Revision ID: stuart.bishop@canonical.com-20111114075126-8jhoq57i2qphmch1
Merged rocketfuel into trivial.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
__metaclass__ = type
7
7
 
 
8
import datetime
 
9
 
8
10
from lazr.lifecycle.snapshot import Snapshot
 
11
import pytz
9
12
import soupmatchers
10
13
from storm.store import Store
11
14
from testtools import ExpectedException
12
15
from testtools.matchers import (
 
16
    MatchesAll,
13
17
    MatchesAny,
14
18
    Not,
15
19
    )
 
20
import transaction
16
21
from zope.component import getUtility
17
22
from zope.security.interfaces import Unauthorized
18
23
from zope.security.proxy import removeSecurityProxy
32
37
    IDistribution,
33
38
    IDistributionSet,
34
39
    )
 
40
from lp.registry.interfaces.oopsreferences import IHasOOPSReferences
35
41
from lp.registry.interfaces.person import IPersonSet
36
42
from lp.registry.interfaces.series import SeriesStatus
37
43
from lp.registry.tests.test_distroseries import (
46
52
    login_person,
47
53
    person_logged_in,
48
54
    TestCaseWithFactory,
 
55
    WebServiceTestCase,
49
56
    )
50
57
from lp.testing.matchers import Provides
51
58
from lp.testing.views import create_initialized_view
214
221
            Unauthorized,
215
222
            setattr, distro, "package_derivatives_email", "foo")
216
223
 
 
224
    def test_implements_interfaces(self):
 
225
        # Distribution fully implements its interfaces.
 
226
        distro = removeSecurityProxy(self.factory.makeDistribution())
 
227
        expected_interfaces = [
 
228
            IHasOOPSReferences,
 
229
            ]
 
230
        provides_all = MatchesAll(*map(Provides, expected_interfaces))
 
231
        self.assertThat(distro, provides_all)
 
232
 
217
233
 
218
234
class TestDistributionCurrentSourceReleases(
219
235
    TestDistroSeriesCurrentSourceReleases):
342
358
        self.distribution = self.factory.makeDistribution(name="boobuntu")
343
359
 
344
360
    def test_snapshot(self):
345
 
        """Snapshots of products should not include marked attribues.
 
361
        """Snapshots of distributions should not include marked attribues.
346
362
 
347
363
        Wrap an export with 'doNotSnapshot' to force the snapshot to not
348
364
        include that attribute.
528
544
            distro.translation_focus = new_series
529
545
            distro.translationgroup = new_group
530
546
            distro.translationpermission = TranslationPermission.CLOSED
 
547
 
 
548
 
 
549
class TestWebService(WebServiceTestCase):
 
550
 
 
551
    def test_oops_references_matching_distro(self):
 
552
        # The distro layer provides the context restriction, so we need to
 
553
        # check we can access context filtered references - e.g. on question.
 
554
        oopsid = "OOPS-abcdef1234"
 
555
        distro = self.factory.makeDistribution()
 
556
        question = self.factory.makeQuestion(
 
557
            title="Crash with %s" % oopsid, target=distro)
 
558
        transaction.commit()
 
559
        ws_distro = self.wsObject(distro, distro.owner)
 
560
        now = datetime.datetime.now(tz=pytz.utc)
 
561
        day = datetime.timedelta(days=1)
 
562
        self.failUnlessEqual(
 
563
            [oopsid.upper()],
 
564
            ws_distro.findReferencedOOPS(start_date=now - day, end_date=now))
 
565
        self.failUnlessEqual(
 
566
            [],
 
567
            ws_distro.findReferencedOOPS(
 
568
                start_date=now + day, end_date=now + day))
 
569
 
 
570
    def test_oops_references_different_distro(self):
 
571
        # The distro layer provides the context restriction, so we need to
 
572
        # check the filter is tight enough - other contexts should not work.
 
573
        oopsid = "OOPS-abcdef1234"
 
574
        self.factory.makeQuestion(title="Crash with %s" % oopsid)
 
575
        distro = self.factory.makeDistribution()
 
576
        transaction.commit()
 
577
        ws_distro = self.wsObject(distro, distro.owner)
 
578
        now = datetime.datetime.now(tz=pytz.utc)
 
579
        day = datetime.timedelta(days=1)
 
580
        self.failUnlessEqual(
 
581
            [],
 
582
            ws_distro.findReferencedOOPS(start_date=now - day, end_date=now))