~launchpad-pqm/launchpad/devel

14012.1.2 by Curtis Hovey
Added rudimentary UsesBugsDistributionVocabulary.
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 bug domain vocabularies."""
5
6
__metaclass__ = type
7
14435.1.8 by Curtis Hovey
Renamed lp/bugs/vocabulary to vocaularies to be consitent with the other modules.
8
from lp.bugs.vocabularies import UsesBugsDistributionVocabulary
14012.1.3 by Curtis Hovey
Constrain UsesBugsDistributionVocabulary to distros that use Lp Bugs.
9
from lp.testing import (
10
    person_logged_in,
11
    TestCaseWithFactory,
12
    )
14612.2.1 by William Grant
format-imports on lib/. So many imports.
13
from lp.testing.layers import DatabaseFunctionalLayer
14012.1.2 by Curtis Hovey
Added rudimentary UsesBugsDistributionVocabulary.
14
15
16
class UsesBugsDistributionVocabularyTestCase(TestCaseWithFactory):
17
    """Test that the vocabulary behaves as expected."""
18
    layer = DatabaseFunctionalLayer
19
20
    def test_init_with_distribution(self):
14012.1.5 by Curtis Hovey
Adapt to a distribution and do not accept a non-distro.
21
        # When the context is adaptable to IDistribution, the distribution
22
        # property is the distribution.
14012.1.2 by Curtis Hovey
Added rudimentary UsesBugsDistributionVocabulary.
23
        distribution = self.factory.makeDistribution()
24
        vocabulary = UsesBugsDistributionVocabulary(distribution)
25
        self.assertEqual(distribution, vocabulary.context)
14012.1.5 by Curtis Hovey
Adapt to a distribution and do not accept a non-distro.
26
        self.assertEqual(distribution, vocabulary.distribution)
27
28
    def test_init_without_distribution(self):
29
        # When the context is not adaptable to IDistribution, the
30
        # distribution property is None
31
        thing = self.factory.makeProduct()
32
        vocabulary = UsesBugsDistributionVocabulary(thing)
33
        self.assertEqual(thing, vocabulary.context)
34
        self.assertEqual(None, vocabulary.distribution)
14012.1.3 by Curtis Hovey
Constrain UsesBugsDistributionVocabulary to distros that use Lp Bugs.
35
36
    def test_contains_distros_that_use_bugs(self):
37
        # The vocabulary contains distributions that also use
38
        # Launchpad to track bugs.
39
        distro_less_bugs = self.factory.makeDistribution()
40
        distro_uses_bugs = self.factory.makeDistribution()
41
        with person_logged_in(distro_uses_bugs.owner):
42
            distro_uses_bugs.official_malone = True
43
        vocabulary = UsesBugsDistributionVocabulary()
44
        self.assertFalse(
45
            distro_less_bugs in vocabulary,
46
            "Vocabulary contains distros that do not use Launchpad Bugs.")
47
        self.assertTrue(
48
            distro_uses_bugs in vocabulary,
49
            "Vocabulary missing distros that use Launchpad Bugs.")
14012.1.4 by Curtis Hovey
Added the context distribution to the vocab to ensure historic
50
51
    def test_contains_context_distro(self):
52
        # The vocabulary contains the context distro even it it does not
53
        # use Launchpad to track bugs. The distro may have tracked bugs
54
        # in the past so it is a legitimate choise for historic data.
55
        distro_less_bugs = self.factory.makeDistribution()
56
        vocabulary = UsesBugsDistributionVocabulary(distro_less_bugs)
57
        self.assertFalse(distro_less_bugs.official_malone)
58
        self.assertTrue(
59
            distro_less_bugs in vocabulary,
60
            "Vocabulary missing context distro.")
14012.1.5 by Curtis Hovey
Adapt to a distribution and do not accept a non-distro.
61
62
    def test_contains_missing_context(self):
14022.1.7 by Curtis Hovey
Make the comments intelligible.
63
        # The vocabulary does not contain the context if the
14012.1.6 by Curtis Hovey
Fixed comment.
64
        # context is not adaptable to a distribution.
14012.1.5 by Curtis Hovey
Adapt to a distribution and do not accept a non-distro.
65
        thing = self.factory.makeProduct()
66
        vocabulary = UsesBugsDistributionVocabulary(thing)
67
        self.assertFalse(
68
            thing in vocabulary,
69
            "Vocabulary contains a non-distribution.")