~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-11-29 21:39:44 UTC
  • mfrom: (14400.3.1 dsp-vocab-unknown-distro-0)
  • Revision ID: launchpad@pqm.canonical.com-20111129213944-n3l1pj12iws82sog
[rs=sinzui][no-qa] Refator tests before fixing 889192.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
__metaclass__ = type
7
7
 
8
 
from zope.component import getUtility
9
8
 
10
9
from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
11
10
from canonical.testing.layers import DatabaseFunctionalLayer
12
 
from lp.registry.interfaces.distribution import IDistributionSet
13
11
from lp.registry.vocabularies import DistributionSourcePackageVocabulary
14
 
from lp.soyuz.model.distributionsourcepackagecache import (
15
 
    DistributionSourcePackageCache,
16
 
    )
17
12
from lp.testing import TestCaseWithFactory
18
 
from lp.testing.dbuser import dbuser
19
13
 
20
14
 
21
15
class TestDistributionSourcePackageVocabulary(TestCaseWithFactory):
203
197
        results = vocabulary.searchForTerms(dsp.name)
204
198
        self.assertIs(0, results.count())
205
199
 
206
 
    def makeDSPCache(self, distro_name, package_name, make_distro=True,
207
 
                     official=True, binary_names=None, archive=None):
208
 
        if make_distro:
209
 
            distribution = self.factory.makeDistribution(name=distro_name)
210
 
        else:
211
 
            distribution = getUtility(IDistributionSet).getByName(distro_name)
212
 
        dsp = self.factory.makeDistributionSourcePackage(
213
 
            distribution=distribution, sourcepackagename=package_name,
214
 
            with_db=official)
215
 
        if archive is None:
216
 
            archive = dsp.distribution.main_archive
217
 
        else:
218
 
            archive = self.factory.makeArchive(
219
 
                distribution=distribution, purpose=archive)
220
 
        with dbuser('statistician'):
221
 
            DistributionSourcePackageCache(
222
 
                distribution=dsp.distribution,
223
 
                sourcepackagename=dsp.sourcepackagename,
224
 
                archive=archive,
225
 
                name=package_name,
226
 
                binpkgnames=binary_names)
227
 
 
228
200
    def test_searchForTerms_None(self):
229
201
        # Searching for nothing gets you that.
230
202
        vocabulary = DistributionSourcePackageVocabulary(
234
206
 
235
207
    def test_searchForTerms_exact_offcial_source_name(self):
236
208
        # Exact source name matches are found.
237
 
        self.makeDSPCache('fnord', 'snarf')
 
209
        self.factory.makeDSPCache('fnord', 'snarf')
238
210
        vocabulary = DistributionSourcePackageVocabulary(None)
239
211
        results = vocabulary.searchForTerms(query='fnord/snarf')
240
212
        terms = list(results)
243
215
 
244
216
    def test_searchForTerms_similar_offcial_source_name(self):
245
217
        # Partial source name matches are found.
246
 
        self.makeDSPCache('fnord', 'pting-snarf-ack')
 
218
        self.factory.makeDSPCache('fnord', 'pting-snarf-ack')
247
219
        vocabulary = DistributionSourcePackageVocabulary(None)
248
220
        results = vocabulary.searchForTerms(query='fnord/snarf')
249
221
        terms = list(results)
252
224
 
253
225
    def test_searchForTerms_exact_binary_name(self):
254
226
        # Exact binary name matches are found.
255
 
        self.makeDSPCache(
 
227
        self.factory.makeDSPCache(
256
228
            'fnord', 'snarf', binary_names='pting-dev pting ack')
257
229
        vocabulary = DistributionSourcePackageVocabulary(None)
258
230
        results = vocabulary.searchForTerms(query='fnord/pting')
262
234
 
263
235
    def test_searchForTerms_similar_binary_name(self):
264
236
        # Partial binary name matches are found.
265
 
        self.makeDSPCache(
 
237
        self.factory.makeDSPCache(
266
238
            'fnord', 'snarf', binary_names='thrpp pting-dev ack')
267
239
        vocabulary = DistributionSourcePackageVocabulary(None)
268
240
        results = vocabulary.searchForTerms(query='fnord/pting')
272
244
 
273
245
    def test_searchForTerms_exact_unofficial_source_name(self):
274
246
        # Unofficial source packages are not found by search.
275
 
        self.makeDSPCache('fnord', 'snarf', official=False)
 
247
        self.factory.makeDSPCache('fnord', 'snarf', official=False)
276
248
        vocabulary = DistributionSourcePackageVocabulary(None)
277
249
        results = vocabulary.searchForTerms(query='fnord/snarf')
278
250
        terms = list(results)
280
252
 
281
253
    def test_searchForTerms_similar_unofficial_binary_name(self):
282
254
        # Unofficial binary packages are not found by search.
283
 
        self.makeDSPCache(
 
255
        self.factory.makeDSPCache(
284
256
            'fnord', 'snarf', official=False, binary_names='thrpp pting ack')
285
257
        vocabulary = DistributionSourcePackageVocabulary(None)
286
258
        results = vocabulary.searchForTerms(query='fnord/pting')
290
262
    def test_searchForTerms_match_official_source_package_branch(self):
291
263
        # The official package that is only a branch can be matched
292
264
        # by source name if it was built in another distro.
293
 
        self.makeDSPCache('fnord', 'snarf')
 
265
        self.factory.makeDSPCache('fnord', 'snarf')
294
266
        distribution = self.factory.makeDistribution(name='pting')
295
267
        self.factory.makeDistributionSourcePackage(
296
268
            distribution=distribution, sourcepackagename='snarf',
304
276
    def test_searchForTerms_match_official_binary_package_branch(self):
305
277
        # The official package that is only a branch can be matched
306
278
        # by binary name if it was built in another distro.
307
 
        self.makeDSPCache(
 
279
        self.factory.makeDSPCache(
308
280
            'fnord', 'snarf', binary_names='thrpp snarf-dev ack')
309
281
        distribution = self.factory.makeDistribution(name='pting')
310
282
        self.factory.makeDistributionSourcePackage(
318
290
 
319
291
    def test_searchForTerms_ranking(self):
320
292
        # Exact matches are ranked higher than similar matches.
321
 
        self.makeDSPCache('fnord', 'snarf')
322
 
        self.makeDSPCache('fnord', 'snarf-server', make_distro=False)
323
 
        self.makeDSPCache(
 
293
        self.factory.makeDSPCache('fnord', 'snarf')
 
294
        self.factory.makeDSPCache('fnord', 'snarf-server', make_distro=False)
 
295
        self.factory.makeDSPCache(
324
296
            'fnord', 'pting-devel', binary_names='snarf', make_distro=False)
325
 
        self.makeDSPCache(
 
297
        self.factory.makeDSPCache(
326
298
            'fnord', 'pting-client', binary_names='snarf-common',
327
299
            make_distro=False)
328
300
        vocabulary = DistributionSourcePackageVocabulary(None)
336
308
 
337
309
    def test_searchForTerms_partner_archive(self):
338
310
        # Packages in partner archives are searched.
339
 
        self.makeDSPCache('fnord', 'snarf', archive='partner')
 
311
        self.factory.makeDSPCache('fnord', 'snarf', archive='partner')
340
312
        vocabulary = DistributionSourcePackageVocabulary(None)
341
313
        results = vocabulary.searchForTerms(query='fnord/snarf')
342
314
        terms = list(results)
345
317
 
346
318
    def test_searchForTerms_ppa_archive(self):
347
319
        # Packages in PPAs are ignored.
348
 
        self.makeDSPCache('fnord', 'snarf', archive='ppa')
 
320
        self.factory.makeDSPCache('fnord', 'snarf', archive='ppa')
349
321
        vocabulary = DistributionSourcePackageVocabulary(None)
350
322
        results = vocabulary.searchForTerms(query='fnord/snarf')
351
323
        terms = list(results)