~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-07-15 13:51:32 UTC
  • mfrom: (13444.1.3 dsp-vocab-use-spn)
  • Revision ID: launchpad@pqm.canonical.com-20110715135132-e8nsgc9pkt0p204s
[r=adeuring,
        wallyworld][no-qa] Force the DistributionSourcePackage vocab to
        expect and return SourcePackageNames.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    expected."""
17
17
    layer = DatabaseFunctionalLayer
18
18
 
19
 
    def setUp(self):
20
 
        super(TestDistributionSourcePackageVocabulary, self).setUp()
21
 
        self.vocabulary = DistributionSourcePackageVocabulary()
22
 
 
23
19
    def test_provides_ihugevocabulary(self):
24
 
        self.assertProvides(self.vocabulary, IHugeVocabulary)
 
20
        vocabulary = DistributionSourcePackageVocabulary(
 
21
            self.factory.makeDistribution())
 
22
        self.assertProvides(vocabulary, IHugeVocabulary)
25
23
 
26
24
    def test_toTerm_unbuilt_dsp(self):
27
25
        # If the source has no built binaries, the term's value contains a
28
26
        # string to that effect.
29
27
        dsp = self.factory.makeDistributionSourcePackage(
30
28
            sourcepackagename='foo')
31
 
        term = self.vocabulary.toTerm(dsp)
 
29
        vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
 
30
        term = vocabulary.toTerm(dsp.name)
32
31
        self.assertEqual(dsp.sourcepackagename.name, term.title)
33
32
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
34
33
        self.assertEqual(expected_token, term.token)
41
40
        dsp = self.factory.makeDistributionSourcePackage(
42
41
            sourcepackagename=spr.sourcepackagename,
43
42
            distribution=bpph.distroseries.distribution)
44
 
        term = self.vocabulary.toTerm(dsp)
 
43
        vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
 
44
        term = vocabulary.toTerm(spr.sourcepackagename)
45
45
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
46
46
        self.assertEqual(expected_token, term.token)
47
47
        self.assertEqual(bpph.binary_package_name, term.value)
61
61
            self.factory.makeBinaryPackagePublishingHistory(
62
62
                binarypackagerelease=bpr, distroarchseries=das)
63
63
        dsp = spr.distrosourcepackage
64
 
        term = self.vocabulary.toTerm(dsp)
 
64
        vocabulary = DistributionSourcePackageVocabulary(dsp.distribution)
 
65
        term = vocabulary.toTerm(spr.sourcepackagename)
65
66
        expected_token = '%s-%s' % (dsp.distribution.name, dsp.name)
66
67
        self.assertEqual(expected_token, term.token)
67
68
        self.assertEqual(', '.join(expected_names), term.value)
68
69
 
69
70
    def test_searchForTerms_None(self):
70
71
        # Searching for nothing gets you that.
71
 
        results = self.vocabulary.searchForTerms()
 
72
        vocabulary = DistributionSourcePackageVocabulary(
 
73
            self.factory.makeDistribution())
 
74
        results = vocabulary.searchForTerms()
72
75
        self.assertIs(None, results)
73
76
 
74
77
    def assertTermsEqual(self, expected, actual):
78
81
        self.assertEqual(expected.value, actual.value)
79
82
 
80
83
    def test_searchForTerms_published_source(self):
81
 
        # When we search for a source package name that is published, a DSP
82
 
        # is returned.
 
84
        # When we search for a source package name that is published, it is
 
85
        # returned.
83
86
        spph = self.factory.makeSourcePackagePublishingHistory()
84
87
        vocabulary = DistributionSourcePackageVocabulary(
85
88
            context=spph.distroseries.distribution)
86
89
        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])
 
90
        self.assertTermsEqual(
 
91
            vocabulary.toTerm(spph.source_package_name), results[0])
91
92
 
92
93
    def test_searchForTerms_unpublished_source(self):
93
94
        # If the source package name isn't published in the distribution,
108
109
        self.assertEqual([], list(results))
109
110
 
110
111
    def test_searchForTerms_published_binary(self):
111
 
        # We can search for a binary package name, which returns the DSP.
 
112
        # We can search for a binary package name, which returns the
 
113
        # relevant SPN.
112
114
        bpph = self.factory.makeBinaryPackagePublishingHistory()
113
115
        distribution = bpph.distroarchseries.distroseries.distribution
114
116
        vocabulary = DistributionSourcePackageVocabulary(
115
117
            context=distribution)
116
118
        spn = bpph.binarypackagerelease.build.source_package_release.name
117
 
        dsp = self.factory.makeDistributionSourcePackage(
118
 
            sourcepackagename=spn, distribution=distribution)
119
119
        results = vocabulary.searchForTerms(query=bpph.binary_package_name)
120
 
        self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
 
120
        self.assertTermsEqual(vocabulary.toTerm(spn), results[0])
121
121
 
122
122
    def test_searchForTerms_published_multiple_binaries(self):
123
 
        # Searching for a subset of a binary package name returns the DSP
 
123
        # Searching for a subset of a binary package name returns the SPN
124
124
        # that built the binary package.
125
125
        spn = self.factory.getOrMakeSourcePackageName('xorg')
126
126
        spr = self.factory.makeSourcePackageRelease(sourcepackagename=spn)
135
135
                binarypackagename=bpn, build=bpb)
136
136
            bpph = self.factory.makeBinaryPackagePublishingHistory(
137
137
                binarypackagerelease=bpr, distroarchseries=das)
138
 
        dsp = self.factory.makeDistributionSourcePackage(
139
 
            distribution=das.distroseries.distribution,
140
 
            sourcepackagename=spn)
141
138
        vocabulary = DistributionSourcePackageVocabulary(
142
139
            context=das.distroseries.distribution)
143
140
        results = vocabulary.searchForTerms(query='xorg-se')
144
 
        self.assertTermsEqual(vocabulary.toTerm(dsp), results[0])
 
141
        self.assertTermsEqual(vocabulary.toTerm(spn), results[0])