~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-24 13:40:28 UTC
  • mfrom: (13261.5.3 dsp-vocab)
  • Revision ID: launchpad@pqm.canonical.com-20110624134028-p6bhs72xycu5uuoi
[r=jtv][bug=42298][incr] Add DistributionSourcePackageVocabulary.

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
"""Test the Distribution Source Package vocabulary."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
 
9
from canonical.testing.layers import DatabaseFunctionalLayer
 
10
from lp.registry.vocabularies import DistributionSourcePackageVocabulary
 
11
from lp.testing import TestCaseWithFactory
 
12
 
 
13
 
 
14
class TestDistributionSourcePackageVocabulary(TestCaseWithFactory):
 
15
    """Test that the DistributionSourcePackageVocabulary behaves as
 
16
    expected."""
 
17
    layer = DatabaseFunctionalLayer
 
18
 
 
19
    def setUp(self):
 
20
        super(TestDistributionSourcePackageVocabulary, self).setUp()
 
21
        self.vocabulary = DistributionSourcePackageVocabulary()
 
22
 
 
23
    def test_provides_ihugevocabulary(self):
 
24
        self.assertProvides(self.vocabulary, IHugeVocabulary)
 
25
 
 
26
    def test_toTerm_unbuilt_dsp(self):
 
27
        # If the source has no built binaries, the term's value contains a
 
28
        # string to that effect.
 
29
        dsp = self.factory.makeDistributionSourcePackage(
 
30
            sourcepackagename='foo')
 
31
        term = self.vocabulary.toTerm(dsp)
 
32
        self.assertEqual(dsp.sourcepackagename.name, term.title)
 
33
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
 
34
        self.assertEqual(expected_token, term.token)
 
35
        self.assertEqual('Not yet built.', term.value)
 
36
 
 
37
    def test_toTerm_built_single_binary(self):
 
38
        # The binary package name appears in the term's value.
 
39
        bpph = self.factory.makeBinaryPackagePublishingHistory()
 
40
        spr = bpph.binarypackagerelease.build.source_package_release
 
41
        dsp = self.factory.makeDistributionSourcePackage(
 
42
            sourcepackagename=spr.sourcepackagename,
 
43
            distribution=bpph.distroseries.distribution)
 
44
        term = self.vocabulary.toTerm(dsp)
 
45
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
 
46
        self.assertEqual(expected_token, term.token)
 
47
        self.assertEqual(bpph.binary_package_name, term.value)
 
48
 
 
49
    def test_toTerm_built_multiple_binary(self):
 
50
        # All of the binary package names appear in the term's value.
 
51
        spph = self.factory.makeSourcePackagePublishingHistory()
 
52
        spr = spph.sourcepackagerelease
 
53
        das = self.factory.makeDistroArchSeries(
 
54
            distroseries=spph.distroseries)
 
55
        expected_names = []
 
56
        for i in xrange(20):
 
57
            bpb = self.factory.makeBinaryPackageBuild(
 
58
                source_package_release=spr, distroarchseries=das)
 
59
            bpr = self.factory.makeBinaryPackageRelease(build=bpb)
 
60
            expected_names.append(bpr.name)
 
61
            self.factory.makeBinaryPackagePublishingHistory(
 
62
                binarypackagerelease=bpr, distroarchseries=das)
 
63
        dsp = spr.distrosourcepackage
 
64
        term = self.vocabulary.toTerm(dsp)
 
65
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
 
66
        self.assertEqual(expected_token, term.token)
 
67
        self.assertEqual(', '.join(expected_names), term.value)
 
68
 
 
69
    def test_searchForTerms_None(self):
 
70
        # Searching for nothing gets you that.
 
71
        results = self.vocabulary.searchForTerms()
 
72
        self.assertIs(None, results)
 
73
 
 
74
    def assertTermsEqual(self, expected, actual):
 
75
        # Assert two given terms are equal.
 
76
        self.assertEqual(expected.token, actual.token)
 
77
        self.assertEqual(expected.title, actual.title)
 
78
        self.assertEqual(expected.value, actual.value)
 
79
 
 
80
    def test_searchForTerms_published_source(self):
 
81
        # When we search for a source package name that is published, a DSP
 
82
        # is returned.
 
83
        spph = self.factory.makeSourcePackagePublishingHistory()
 
84
        vocabulary = DistributionSourcePackageVocabulary(
 
85
            context=spph.distroseries.distribution)
 
86
        results = vocabulary.searchForTerms(query=spph.source_package_name)
 
87
        dsp = self.factory.makeDistributionSourcePackage(
 
88
            sourcepackagename=spph.source_package_name,
 
89
            distribution=spph.distroseries.distribution)
 
90
        self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
 
91
 
 
92
    def test_searchForTerms_unpublished_source(self):
 
93
        # If the source package name isn't published in the distribution,
 
94
        # we get no results.
 
95
        spph = self.factory.makeSourcePackagePublishingHistory()
 
96
        vocabulary = DistributionSourcePackageVocabulary(
 
97
            context=self.factory.makeDistribution())
 
98
        results = vocabulary.searchForTerms(query=spph.source_package_name)
 
99
        self.assertEqual([], list(results))
 
100
 
 
101
    def test_searchForTerms_unpublished_binary(self):
 
102
        # If the binary package name isn't published in the distribution,
 
103
        # we get no results.
 
104
        bpph = self.factory.makeBinaryPackagePublishingHistory()
 
105
        vocabulary = DistributionSourcePackageVocabulary(
 
106
            context=self.factory.makeDistribution())
 
107
        results = vocabulary.searchForTerms(query=bpph.binary_package_name)
 
108
        self.assertEqual([], list(results))
 
109
 
 
110
    def test_searchForTerms_published_binary(self):
 
111
        # We can search for a binary package name, which returns the DSP.
 
112
        bpph = self.factory.makeBinaryPackagePublishingHistory()
 
113
        distribution = bpph.distroarchseries.distroseries.distribution
 
114
        vocabulary = DistributionSourcePackageVocabulary(
 
115
            context=distribution)
 
116
        spn = bpph.binarypackagerelease.build.source_package_release.name
 
117
        dsp = self.factory.makeDistributionSourcePackage(
 
118
            sourcepackagename=spn, distribution=distribution)
 
119
        results = vocabulary.searchForTerms(query=bpph.binary_package_name)
 
120
        self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
 
121
 
 
122
    def test_searchForTerms_published_multiple_binaries(self):
 
123
        # Searching for a subset of a binary package name returns the DSP
 
124
        # that built the binary package.
 
125
        spn = self.factory.getOrMakeSourcePackageName('xorg')
 
126
        spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
 
127
        das = self.factory.makeDistroArchSeries()
 
128
        spph = self.factory.makeSourcePackagePublishingHistory(
 
129
            sourcepackagerelease=spr, distroseries=das.distroseries)
 
130
        for name in ('xorg-common', 'xorg-server', 'xorg-video-intel'):
 
131
            bpn = self.factory.getOrMakeBinaryPackageName(name)
 
132
            bpb = self.factory.makeBinaryPackageBuild(
 
133
                source_package_release=spr, distroarchseries=das)
 
134
            bpr = self.factory.makeBinaryPackageRelease(
 
135
                binarypackagename=bpn, build=bpb)
 
136
            bpph = self.factory.makeBinaryPackagePublishingHistory(
 
137
                binarypackagerelease=bpr, distroarchseries=das)
 
138
        dsp = self.factory.makeDistributionSourcePackage(
 
139
            distribution=das.distroseries.distribution,
 
140
            sourcepackagename=spn)
 
141
        vocabulary = DistributionSourcePackageVocabulary(
 
142
            context=das.distroseries.distribution)
 
143
        results = vocabulary.searchForTerms(query='xorg-se')
 
144
        self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])