~launchpad-pqm/launchpad/devel

8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
3
4
"""Unit tests for CodeReviewComments."""
5
6
__metaclass__ = type
7
8
import unittest
9
10
from canonical.launchpad.webapp.interfaces import IPrimaryContext
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
11
from canonical.launchpad.webapp.testing import verifyObject
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
12
from canonical.testing.layers import DatabaseFunctionalLayer
7675.831.1 by Michael Nelson
Fixed failing code tests that were rendering the default comment template.
13
from lp.code.browser.codereviewcomment import (
14
    CodeReviewDisplayComment,
15
    ICodeReviewDisplayComment,
16
    )
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
17
from lp.testing import (
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
18
    person_logged_in,
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
19
    TestCaseWithFactory,
20
    )
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
21
22
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
23
class TestCodeReviewComments(TestCaseWithFactory):
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
24
25
    layer = DatabaseFunctionalLayer
26
27
    def testPrimaryContext(self):
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
28
        # Tests the adaptation of a code review comment into a primary
29
        # context.
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
30
        # We need a person to make a comment.
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
31
        with person_logged_in(self.factory.makePerson()):
32
            # The primary context of a code review comment is the same
33
            # as the primary context for the branch merge proposal that
34
            # the comment is for.
35
            comment = self.factory.makeCodeReviewComment()
36
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
37
        self.assertEqual(
38
            IPrimaryContext(comment).context,
39
            IPrimaryContext(comment.branch_merge_proposal).context)
40
7675.831.1 by Michael Nelson
Fixed failing code tests that were rendering the default comment template.
41
    def test_display_comment_provides_icodereviewdisplaycomment(self):
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
42
        # The CodeReviewDisplayComment class provides IComment.
43
        with person_logged_in(self.factory.makePerson()):
44
            comment = self.factory.makeCodeReviewComment()
45
46
        display_comment = CodeReviewDisplayComment(comment)
47
7675.831.1 by Michael Nelson
Fixed failing code tests that were rendering the default comment template.
48
        verifyObject(ICodeReviewDisplayComment, display_comment)
7675.820.24 by Michael Nelson
Tested interface for Code's display comment model.
49
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
50
51
def test_suite():
52
    return unittest.TestLoader().loadTestsFromName(__name__)