1
SpecificationDepCandidatesVocabulary
2
====================================
4
All blueprints that can be added as a dependency of the context
7
>>> from zope.schema.vocabulary import getVocabularyRegistry
8
>>> vocabulary_registry = getVocabularyRegistry()
10
First, we set up a product with three blueprints.
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']
25
The dependency candidates for spec_a are all blueprints for
26
specced_product except for spec_a itself.
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']
33
Dependency candidate come only from the same product of the blueprint
36
>>> unrelated_spec = factory.makeSpecification(
37
... product=factory.makeProduct())
38
>>> vocab = vocabulary_registry.get(
39
... spec_a, "SpecificationDepCandidates")
40
>>> unrelated_spec in vocab
42
>>> [term.value.product for term in vocab
43
... if term.value.product != specced_product]
46
We mark spec_b as a dependency of spec_a and spec_c as a dependency of
49
>>> spec_a.createDependency(spec_b)
50
<SpecificationDependency at ...>
51
>>> [spec.name for spec in spec_a.dependencies]
54
>>> spec_b.createDependency(spec_c)
55
<SpecificationDependency at ...>
56
>>> [spec.name for spec in spec_b.dependencies]
59
No circular dependencies - the vocabulary excludes specifications that
60
are a dependency of the context spec.
62
>>> spec_a in spec_b.all_blocked
64
>>> spec_b in spec_c.all_blocked
66
>>> vocab = vocabulary_registry.get(
67
... spec_c, "SpecificationDepCandidates")
68
>>> spec_a in [term.value for term in vocab]
71
This vocabulary provides the IHugeVocabulary interface.
73
>>> from canonical.launchpad.webapp.testing import verifyObject
74
>>> from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
75
>>> verifyObject(IHugeVocabulary, vocab)
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.
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]
88
>>> list(naked_vocab.search('third')) == [spec_c]
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
98
>>> list(naked_vocab.search('*'))