~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Jelmer Vernooij
  • Date: 2008-12-07 15:09:23 UTC
  • mto: This revision was merged to the branch mainline in revision 255.
  • Revision ID: jelmer@samba.org-20081207150923-dpupqyf7axazvt28
Use configobj from bzr rather than external configobj (saves a dependency).

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 bzrlib.util.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
 
 
28
    def setup_method(self, meth):
 
29
        self.setUp()
 
30
 
 
31
    def teardown_method(self, meth):
 
32
        self.tearDown()
 
33
 
 
34
    def setUp(self):
 
35
        logging.basicConfig(level=logging.DEBUG)
 
36
        self.bzrbranch = None
 
37
        self.old_bzrhome = None
 
38
 
 
39
    def createBranch(self):
 
40
        self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
 
41
        self.bzrbranch = tempfile.mkdtemp()
 
42
        self.branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
43
            self.bzrbranch, force_new_tree=True)
 
44
        self.tree = self.branch.bzrdir.open_workingtree()
 
45
 
 
46
    config_template = """
 
47
    [project]
 
48
        [[branch]]
 
49
            branch_name = 'branch'
 
50
            folder = '%(branch)s'
 
51
    """
 
52
 
 
53
    def setUpLoggerhead(self):
 
54
        app = TestApp(BranchWSGIApp(self.branch, '').app)
 
55
        return app
 
56
 
 
57
    def tearDown(self):
 
58
        if self.bzrbranch is not None:
 
59
            shutil.rmtree(self.bzrbranch)
 
60
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
 
61
 
 
62
 
 
63
class TestWithSimpleTree(BasicTests):
 
64
 
 
65
    def setUp(self):
 
66
        BasicTests.setUp(self)
 
67
        self.createBranch()
 
68
 
 
69
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
 
70
        self.filecontents = ('some\nmultiline\ndata\n'
 
71
                             'with<htmlspecialchars\n')
 
72
        try:
 
73
            f.write(self.filecontents)
 
74
        finally:
 
75
            f.close()
 
76
        self.tree.add('myfilename')
 
77
        self.fileid = self.tree.path2id('myfilename')
 
78
        self.msg = 'a very exciting commit message <'
 
79
        self.revid = self.tree.commit(message=self.msg)
 
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!')