15
11
from zope.component import getUtility
12
from zope.security.proxy import removeSecurityProxy
17
from canonical.launchpad.interfaces import IDistributionSet, IProductSet
14
from canonical.testing import DatabaseFunctionalLayer
15
from canonical.launchpad.ftests import login_person
16
from canonical.launchpad.interfaces.distribution import IDistributionSet
17
from canonical.launchpad.interfaces.language import ILanguageSet
18
18
from canonical.launchpad.testing.systemdocs import (
19
19
LayeredDocFileSuite, setUp, tearDown)
20
from canonical.testing import LaunchpadFunctionalLayer
23
def productSetUp(test):
25
test.globs['target'] = getUtility(IProductSet).getByName('thunderbird')
28
def distributionSetUp(test):
30
test.globs['target'] = getUtility(IDistributionSet).getByName('kubuntu')
33
def sourcepackageSetUp(test):
35
ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
36
test.globs['target'] = ubuntu.currentseries.getSourcePackage('evolution')
39
def distributionsourcepackageSetUp(test):
41
ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
42
test.globs['target'] = ubuntu.getSourcePackage('evolution')
20
from canonical.launchpad.testing import TestCaseWithFactory
23
class TestQuestionTarget_answer_contacts_with_languages(TestCaseWithFactory):
24
"""Tests for the 'answer_contacts_with_languages' property of question
27
layer = DatabaseFunctionalLayer
30
super(TestQuestionTarget_answer_contacts_with_languages, self).setUp()
31
self.answer_contact = self.factory.makePerson()
32
login_person(self.answer_contact)
33
lang_set = getUtility(ILanguageSet)
34
self.answer_contact.addLanguage(lang_set['pt_BR'])
35
self.answer_contact.addLanguage(lang_set['en'])
37
def test_Product_implementation_should_prefill_cache(self):
38
# Remove the answer contact's security proxy because we need to call
39
# some non public methods to change its language cache.
40
answer_contact = removeSecurityProxy(self.answer_contact)
41
product = self.factory.makeProduct()
42
product.addAnswerContact(answer_contact)
44
# Must delete the cache because it's been filled in addAnswerContact.
45
answer_contact.deleteLanguagesCache()
46
self.assertRaises(AttributeError, answer_contact.getLanguagesCache)
48
# Need to remove the product's security proxy because
49
# answer_contacts_with_languages is not part of its public API.
50
answer_contacts = removeSecurityProxy(
51
product).answer_contacts_with_languages
52
self.failUnlessEqual(answer_contacts, [answer_contact])
54
lang.englishname for lang in answer_contact.getLanguagesCache()]
55
# The languages cache has been filled in the correct order.
56
self.failUnlessEqual(langs, [u'English', u'Portuguese (Brazil)'])
58
def test_SourcePackage_implementation_should_prefill_cache(self):
59
# Remove the answer contact's security proxy because we need to call
60
# some non public methods to change its language cache.
61
answer_contact = removeSecurityProxy(self.answer_contact)
62
ubuntu = getUtility(IDistributionSet)['ubuntu']
63
self.factory.makeSourcePackageName(name='test-pkg')
64
source_package = ubuntu.getSourcePackage('test-pkg')
65
source_package.addAnswerContact(answer_contact)
67
# Must delete the cache because it's been filled in addAnswerContact.
68
answer_contact.deleteLanguagesCache()
69
self.assertRaises(AttributeError, answer_contact.getLanguagesCache)
71
# Need to remove the sourcepackage's security proxy because
72
# answer_contacts_with_languages is not part of its public API.
73
answer_contacts = removeSecurityProxy(
74
source_package).answer_contacts_with_languages
75
self.failUnlessEqual(answer_contacts, [answer_contact])
77
lang.englishname for lang in answer_contact.getLanguagesCache()]
78
# The languages cache has been filled in the correct order.
79
self.failUnlessEqual(langs, [u'English', u'Portuguese (Brazil)'])
46
suite = unittest.TestSuite()
48
targets = [('product', productSetUp),
49
('distribution', distributionSetUp),
50
('sourcepackage', sourcepackageSetUp),
51
('distributionsourcepackage', distributionsourcepackageSetUp),
54
for name, setUpMethod in targets:
55
test = LayeredDocFileSuite('questiontarget.txt',
56
setUp=setUpMethod, tearDown=tearDown,
57
layer=LaunchpadFunctionalLayer)
83
suite = unittest.TestLoader().loadTestsFromName(__name__)
60
85
test = LayeredDocFileSuite('questiontarget-sourcepackage.txt',
61
86
setUp=setUp, tearDown=tearDown,
62
layer=LaunchpadFunctionalLayer)
87
layer=DatabaseFunctionalLayer)
63
88
suite.addTest(test)
67
if __name__ == '__main__':