~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Robey Pointer
  • Date: 2007-01-14 23:46:10 UTC
  • Revision ID: robey@lag.net-20070114234610-z3cn5j8eky0vqsg3
add a decorator to strip the whitespace from the generated html in the big
pages.  (kid theoretically can do this on its own, but it's not hooked up
from turbogears, and even if it was, it doesn't seem to work on html.)
removing whitespace appears to trim a good 20-30% from the generated pages,
so may help a lot for slow links.  in combination with the trimmed-down
javascript names, some of the worst offenders (revisions with gigantic
diffs) are now nearly half the size they were a few days ago.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import cgi
2
 
import os
3
 
import tempfile
4
 
import shutil
5
 
import logging
6
 
 
7
 
import bzrlib.bzrdir
8
 
import bzrlib.osutils
9
 
from configobj import ConfigObj
10
 
 
11
 
from loggerhead.apps.branch import BranchWSGIApp
12
 
from paste.fixture import TestApp
13
 
 
14
 
 
15
 
def test_config_root():
16
 
    from loggerhead.apps.config import Root
17
 
    config = ConfigObj()
18
 
    app = TestApp(Root(config))
19
 
    res = app.get('/')
20
 
    res.mustcontain('loggerhead branches')
21
 
 
22
 
 
23
 
class BasicTests(object):
24
 
 
25
 
    # setup_method and teardown_method are so i can run the tests with
26
 
    # py.test and take advantage of the error reporting.
27
 
    def setup_method(self, meth):
28
 
        self.setUp()
29
 
 
30
 
    def teardown_method(self, meth):
31
 
        self.tearDown()
32
 
 
33
 
    def setUp(self):
34
 
        logging.basicConfig(level=logging.DEBUG)
35
 
        self.bzrbranch = None
36
 
        self.old_bzrhome = None
37
 
 
38
 
    def createBranch(self):
39
 
        self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
40
 
        self.bzrbranch = tempfile.mkdtemp()
41
 
        self.branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
42
 
            self.bzrbranch, force_new_tree=True)
43
 
        self.tree = self.branch.bzrdir.open_workingtree()
44
 
 
45
 
    config_template = """
46
 
    [project]
47
 
        [[branch]]
48
 
            branch_name = 'branch'
49
 
            folder = '%(branch)s'
50
 
    """
51
 
 
52
 
    def setUpLoggerhead(self):
53
 
        app = TestApp(BranchWSGIApp(self.branch, '').app)
54
 
        return app
55
 
 
56
 
    def tearDown(self):
57
 
        if self.bzrbranch is not None:
58
 
            shutil.rmtree(self.bzrbranch)
59
 
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
60
 
 
61
 
 
62
 
class TestWithSimpleTree(BasicTests):
63
 
 
64
 
    def setUp(self):
65
 
        BasicTests.setUp(self)
66
 
        self.createBranch()
67
 
 
68
 
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
69
 
        self.filecontents = ('some\nmultiline\ndata\n'
70
 
                             'with<htmlspecialchars\n')
71
 
        try:
72
 
            f.write(self.filecontents)
73
 
        finally:
74
 
            f.close()
75
 
        self.tree.add('myfilename')
76
 
        self.fileid = self.tree.path2id('myfilename')
77
 
        self.msg = 'a very exciting commit message <'
78
 
        self.revid = self.tree.commit(message=self.msg)
79
 
 
80
 
 
81
 
    def test_changes(self):
82
 
        app = self.setUpLoggerhead()
83
 
        res = app.get('/changes')
84
 
        res.mustcontain(cgi.escape(self.msg))
85
 
 
86
 
    def test_changes_search(self):
87
 
        app = self.setUpLoggerhead()
88
 
        res = app.get('/changes', params={'q': 'foo'})
89
 
        res.mustcontain('Sorry, no results found for your search.')
90
 
 
91
 
    def test_annotate(self):
92
 
        app = self.setUpLoggerhead()
93
 
        res = app.get('/annotate', params={'file_id':self.fileid})
94
 
        for line in self.filecontents.splitlines():
95
 
            res.mustcontain(cgi.escape(line))
96
 
 
97
 
    def test_inventory(self):
98
 
        app = self.setUpLoggerhead()
99
 
        res = app.get('/files')
100
 
        res.mustcontain('myfilename')
101
 
 
102
 
    def test_revision(self):
103
 
        app = self.setUpLoggerhead()
104
 
        res = app.get('/revision/1')
105
 
        res.mustcontain('myfilename')
106
 
 
107
 
 
108
 
class TestEmptyBranch(BasicTests):
109
 
 
110
 
    def setUp(self):
111
 
        BasicTests.setUp(self)
112
 
        self.createBranch()
113
 
 
114
 
    def test_changes(self):
115
 
        app = self.setUpLoggerhead()
116
 
        res = app.get('/changes')
117
 
        res.mustcontain('No revisions!')
118