~launchpad-pqm/launchpad/devel

9861.5.1 by Curtis Hovey
Updated the question index to follow the preferred layout for artefacts.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
__metaclass__ = type
5
6
import unittest
7
8
from zope.component import getUtility
9
10
from canonical.testing.layers import DatabaseFunctionalLayer
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
11
from lp.answers.browser.question import (
12
    QuestionEditMenu,
13
    QuestionExtrasMenu,
14
    )
9861.5.1 by Curtis Hovey
Updated the question index to follow the preferred layout for artefacts.
15
from lp.services.worlddata.interfaces.language import ILanguageSet
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
from lp.testing import (
17
    login_person,
18
    TestCaseWithFactory,
19
    )
9861.5.1 by Curtis Hovey
Updated the question index to follow the preferred layout for artefacts.
20
from lp.testing.menu import check_menu_links
21
22
23
class TestQuestionMenus(TestCaseWithFactory):
24
    """Test specification menus links."""
25
    layer = DatabaseFunctionalLayer
26
27
    def setUp(self):
28
        TestCaseWithFactory.setUp(self)
29
        self.person = self.factory.makePerson()
30
        login_person(self.person)
31
        self.question = self.factory.makeQuestion()
32
33
    def test_QuestionEditMenu(self):
34
        menu = QuestionEditMenu(self.question)
35
        self.assertTrue(check_menu_links(menu))
36
37
    def test_QuestionExtrasMenu(self):
38
        menu = QuestionExtrasMenu(self.question)
39
        self.assertTrue(check_menu_links(menu))
40
41
    def test_link_linkfaq(self):
42
        # A question without a linked FAQ has an 'add' icon.
43
        menu = QuestionExtrasMenu(self.question)
44
        link = menu.linkfaq()
45
        self.assertEqual('add', link.icon)
46
        # A question with a linked FAQ has an 'edit' icon.
47
        self.person.addLanguage(getUtility(ILanguageSet)['en'])
48
        target = self.question.target
12959.4.21 by Curtis Hovey
Alway pass the subscribed_by argument to addAnswerContact.
49
        target.addAnswerContact(self.person, self.person)
9861.5.1 by Curtis Hovey
Updated the question index to follow the preferred layout for artefacts.
50
        faq = self.factory.makeFAQ(target=target)
51
        self.question.linkFAQ(self.person, faq, 'message')
52
        link = menu.linkfaq()
53
        self.assertEqual('edit', link.icon)
54
55
56
def test_suite():
57
    suite = unittest.TestSuite()
58
    suite.addTest(unittest.TestLoader().loadTestsFromName(__name__))
59
    return suite
60
61
62
if __name__ == '__main__':
63
    unittest.TextTestRunner().run(test_suite())