~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/blueprints/vocabularies/tests/specificationdepcandidates.txt

  • Committer: Julian Edwards
  • Date: 2010-08-26 08:02:08 UTC
  • mfrom: (11447 launchpad)
  • mto: This revision was merged to the branch mainline in revision 11453.
  • Revision ID: julian.edwards@canonical.com-20100826080208-sut7s35g9z0qtk9v
merge devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
SpecificationDepCandidatesVocabulary
 
2
====================================
 
3
 
 
4
All blueprints that can be added as a dependency of the context
 
5
blueprint.
 
6
 
 
7
    >>> from zope.schema.vocabulary import getVocabularyRegistry
 
8
    >>> vocabulary_registry = getVocabularyRegistry()
 
9
 
 
10
First, we set up a product with three blueprints.
 
11
 
 
12
    >>> specced_product = factory.makeProduct()
 
13
    >>> spec_a = factory.makeSpecification(
 
14
    ...     name='spec-a', summary='The first spec',
 
15
    ...     product=specced_product)
 
16
    >>> spec_b = factory.makeSpecification(
 
17
    ...     name='spec-b', summary='The second spec',
 
18
    ...     product=specced_product)
 
19
    >>> spec_c = factory.makeSpecification(
 
20
    ...     name='spec-c', summary='The third spec',
 
21
    ...     product=specced_product)
 
22
    >>> sorted([spec.name for spec in specced_product.specifications()])
 
23
    [u'spec-a', u'spec-b', u'spec-c']
 
24
 
 
25
The dependency candidates for spec_a are all blueprints for
 
26
specced_product except for spec_a itself.
 
27
 
 
28
    >>> vocab = vocabulary_registry.get(
 
29
    ...     spec_a, "SpecificationDepCandidates")
 
30
    >>> sorted([term.value.name for term in vocab])
 
31
    [u'spec-b', u'spec-c']
 
32
 
 
33
Dependency candidate come only from the same product of the blueprint
 
34
they depend on.
 
35
 
 
36
    >>> unrelated_spec = factory.makeSpecification(
 
37
    ...     product=factory.makeProduct())
 
38
    >>> vocab = vocabulary_registry.get(
 
39
    ...     spec_a, "SpecificationDepCandidates")
 
40
    >>> unrelated_spec in vocab
 
41
    False
 
42
    >>> [term.value.product for term in vocab
 
43
    ...  if term.value.product != specced_product]
 
44
    []
 
45
 
 
46
We mark spec_b as a dependency of spec_a and spec_c as a dependency of
 
47
spec_b.
 
48
 
 
49
    >>> spec_a.createDependency(spec_b)
 
50
    <SpecificationDependency at ...>
 
51
    >>> [spec.name for spec in spec_a.dependencies]
 
52
    [u'spec-b']
 
53
 
 
54
    >>> spec_b.createDependency(spec_c)
 
55
    <SpecificationDependency at ...>
 
56
    >>> [spec.name for spec in spec_b.dependencies]
 
57
    [u'spec-c']
 
58
 
 
59
No circular dependencies - the vocabulary excludes specifications that
 
60
are a dependency of the context spec.
 
61
 
 
62
    >>> spec_a in spec_b.all_blocked
 
63
    True
 
64
    >>> spec_b in spec_c.all_blocked
 
65
    True
 
66
    >>> vocab = vocabulary_registry.get(
 
67
    ...     spec_c, "SpecificationDepCandidates")
 
68
    >>> spec_a in [term.value for term in vocab]
 
69
    False
 
70
 
 
71
This vocabulary provides the IHugeVocabulary interface.
 
72
 
 
73
    >>> from canonical.launchpad.webapp.testing import verifyObject
 
74
    >>> from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
 
75
    >>> verifyObject(IHugeVocabulary, vocab)
 
76
    True
 
77
 
 
78
The search() method returns specifications within the vocabulary that
 
79
matches the search string. The string is matched against the name, or
 
80
fallbacks to a full text search.
 
81
 
 
82
    >>> from zope.security.proxy import removeSecurityProxy
 
83
    >>> naked_vocab = removeSecurityProxy(
 
84
    ...     vocabulary_registry.get(
 
85
    ...         spec_a, "SpecificationDepCandidates"))
 
86
    >>> list(naked_vocab.search('spec-b')) == [spec_b]
 
87
    True
 
88
    >>> list(naked_vocab.search('third')) == [spec_c]
 
89
    True
 
90
 
 
91
The search method uses the SQL `LIKE` operator, with the values quoted
 
92
appropriately. Queries conataining regual expression operators, for
 
93
example, will simply look for the respective characters within the
 
94
vocabulary's item (this used to be the cause of an OOPS, see
 
95
https://bugs.edge.launchpad.net/blueprint/+bug/139385 for more
 
96
details).
 
97
 
 
98
    >>> list(naked_vocab.search('*'))
 
99
    []