~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_corners.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from loggerhead.tests.test_simple import BasicTests
2
 
 
 
1
import re
3
2
import os
 
3
 
 
4
import cherrypy
4
5
from turbogears import testutil
5
 
import cherrypy
 
6
 
 
7
from loggerhead.tests.test_simple import BasicTests
6
8
 
7
9
class TestCornerCases(BasicTests):
 
10
    """Tests that excercise various corner cases."""
 
11
 
 
12
    def addFileAndCommit(self, filename, commit_msg):
 
13
        """Make a trivial commit that has 'msg' as its commit message.
 
14
 
 
15
        The commit adds a file called 'myfilename' containing the string
 
16
        'foo'.
 
17
        """
 
18
        f = open(os.path.join(self.bzrbranch, filename), 'w')
 
19
        try:
 
20
            f.write("foo")
 
21
        finally:
 
22
            f.close()
 
23
        self.tree.add(filename)
 
24
        self.tree.commit(message=commit_msg)
 
25
 
8
26
 
9
27
    def test_survive_over_upgrade(self):
 
28
        """Check that running 'bzr upgrade' on a branch does not break an
 
29
        instance of loggerhead that's already looked at it.
 
30
        """
10
31
        self.createBranch()
11
32
 
12
 
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
13
 
        try:
14
 
            f.write("foo")
15
 
        finally:
16
 
            f.close()
17
 
        self.tree.add('myfilename')
18
33
        msg = 'a very exciting commit message'
19
 
        self.tree.commit(message=msg)
 
34
        self.addFileAndCommit('myfilename', msg)
20
35
 
21
36
        self.setUpLoggerhead()
22
37
 
30
45
        testutil.create_request('/project/branch/changes')
31
46
        assert msg in cherrypy.response.body[0]
32
47
 
 
48
 
33
49
    def test_revision_only_changing_execute_bit(self):
 
50
        """Check that a commit that only changes the execute bit of a file
 
51
        does not break the rendering."""
34
52
        self.createBranch()
35
53
 
36
 
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
37
 
        try:
38
 
            f.write("foo")
39
 
        finally:
40
 
            f.close()
41
 
        self.tree.add('myfilename')
 
54
        # Just a commit to have a file to change the execute bit of.
42
55
        msg = 'a very exciting commit message'
43
 
        self.tree.commit(message=msg)
 
56
        self.addFileAndCommit('myfilename', msg)
44
57
 
 
58
        # Make a commit that changes the execute bit of 'myfilename'.
45
59
        os.chmod(os.path.join(self.bzrbranch, 'myfilename'), 0755)
46
 
 
47
60
        newrevid = self.tree.commit(message='make something executable')
48
61
 
 
62
        # Check that it didn't break things.
49
63
        self.setUpLoggerhead()
50
 
 
51
 
 
52
64
        testutil.create_request('/project/branch/revision/'+newrevid)
53
65
        assert 'executable' in cherrypy.response.body[0]
 
66
 
 
67
 
 
68
    def test_empty_commit_message(self):
 
69
        """Check that an empty commit message does not break the rendering."""
 
70
        self.createBranch()
 
71
 
 
72
        # Make a commit that has an empty message.
 
73
        self.addFileAndCommit('myfilename', '')
 
74
 
 
75
        # Check that it didn't break things.
 
76
        self.setUpLoggerhead()
 
77
        testutil.create_request('/project/branch/changes')
 
78
        # It's not much of an assertion, but we only really care about
 
79
        # "assert not crashed".
 
80
        assert 'myfilename' in cherrypy.response.body[0]
 
81
 
 
82
 
 
83
    def test_whitespace_only_commit_message(self):
 
84
        """Check that a whitespace-only commit message does not break the
 
85
        rendering."""
 
86
        self.createBranch()
 
87
 
 
88
        # Make a commit that has a whitespace only message.
 
89
        self.addFileAndCommit('myfilename', '   ')
 
90
 
 
91
        # Check that it didn't break things.
 
92
        self.setUpLoggerhead()
 
93
        testutil.create_request('/project/branch/changes')
 
94
        # It's not much of an assertion, but we only really care about
 
95
        # "assert not crashed".
 
96
        assert 'myfilename' in cherrypy.response.body[0]
 
97
 
 
98
    def test_revision_size_limit(self):
 
99
        self.createBranch()
 
100
        msg = 'a very exciting commit message'
 
101
        self.addFileAndCommit('myfilename', msg)
 
102
 
 
103
        file_in_branch = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
 
104
        file_in_branch.write('\n'.join(['line']*100))
 
105
        file_in_branch.close()
 
106
        newrevid = self.tree.commit(message='touch 100 lines')
 
107
 
 
108
        self.setUpLoggerhead()
 
109
        cherrypy.root._config['line_count_limit'] = 50
 
110
        testutil.create_request('/project/branch/revision/'+newrevid)
 
111
 
 
112
        match = re.search(
 
113
            'Diff of [0-9]+ lines is too long to display richly -- limit '
 
114
            'is 50 lines\\.',
 
115
            cherrypy.response.body[0]
 
116
            )
 
117
 
 
118
        assert match is not None