1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test the answers domain vocabularies."""
8
from canonical.testing.layers import DatabaseFunctionalLayer
9
from lp.answers.vocabulary import UsesAnswersDistributionVocabulary
10
from lp.testing import (
16
class UsesAnswersDistributionVocabularyTestCase(TestCaseWithFactory):
17
"""Test that the vocabulary behaves as expected."""
18
layer = DatabaseFunctionalLayer
20
def test_init_with_distribution(self):
21
# When the context is adaptable to IDistribution, the distribution
22
# property is the distribution.
23
distribution = self.factory.makeDistribution()
24
vocabulary = UsesAnswersDistributionVocabulary(distribution)
25
self.assertEqual(distribution, vocabulary.context)
26
self.assertEqual(distribution, vocabulary.distribution)
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 = UsesAnswersDistributionVocabulary(thing)
33
self.assertEqual(thing, vocabulary.context)
34
self.assertEqual(None, vocabulary.distribution)
36
def test_contains_distros_that_use_answers(self):
37
# The vocabulary contains distributions that also use
38
# Launchpad to track answers.
39
distro_less_answers = self.factory.makeDistribution()
40
distro_uses_answers = self.factory.makeDistribution()
41
with person_logged_in(distro_uses_answers.owner):
42
distro_uses_answers.official_answers = True
43
vocabulary = UsesAnswersDistributionVocabulary()
45
distro_less_answers in vocabulary,
46
"Vocabulary contains distros that do not use Launchpad Answers.")
48
distro_uses_answers in vocabulary,
49
"Vocabulary missing distros that use Launchpad Answers.")
51
def test_contains_context_distro(self):
52
# The vocabulary contains the context distro even it it does not
53
# use Launchpad to track answers. The distro may have tracked answers
54
# in the past so it is a legitimate choise for historic data.
55
distro_less_answers = self.factory.makeDistribution()
56
vocabulary = UsesAnswersDistributionVocabulary(distro_less_answers)
57
self.assertFalse(distro_less_answers.official_answers)
59
distro_less_answers in vocabulary,
60
"Vocabulary missing context distro.")
62
def test_contains_missing_context(self):
63
# The vocabulary does not contain the context if the
64
# context is not adaptable to a distribution.
65
thing = self.factory.makeProduct()
66
vocabulary = UsesAnswersDistributionVocabulary(thing)
69
"Vocabulary contains a non-distribution.")