~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Martin Pool
  • Date: 2009-03-10 01:01:04 UTC
  • mto: This revision was merged to the branch mainline in revision 298.
  • Revision ID: mbp@sourcefrog.net-20090310010104-o75ncguznrridwaz
optparse may have already parsed port as an int

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import cgi
 
2
import os
 
3
import tempfile
 
4
import shutil
2
5
import logging
3
6
 
4
 
from bzrlib.tests import TestCaseWithTransport
 
7
import bzrlib.bzrdir
 
8
import bzrlib.osutils
5
9
from bzrlib.util.configobj.configobj import ConfigObj
6
10
 
7
11
from loggerhead.apps.branch import BranchWSGIApp
8
12
from paste.fixture import TestApp
9
 
from paste.httpexceptions import HTTPExceptionHandler
10
 
 
11
13
 
12
14
 
13
15
def test_config_root():
14
16
    from loggerhead.apps.config import Root
15
17
    config = ConfigObj()
16
 
    app = TestApp(HTTPExceptionHandler(Root(config)))
 
18
    app = TestApp(Root(config))
17
19
    res = app.get('/')
18
20
    res.mustcontain('loggerhead branches')
19
21
 
20
22
 
21
 
class BasicTests(TestCaseWithTransport):
 
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()
22
33
 
23
34
    def setUp(self):
24
 
        TestCaseWithTransport.setUp(self)
25
 
        logging.basicConfig(level=logging.ERROR)
26
 
        logging.getLogger('bzr').setLevel(logging.CRITICAL)
 
35
        logging.basicConfig(level=logging.DEBUG)
 
36
        self.bzrbranch = None
 
37
        self.old_bzrhome = None
27
38
 
28
39
    def createBranch(self):
29
 
        self.tree = self.make_branch_and_tree('.')
30
 
 
31
 
    def setUpLoggerhead(self, **kw):
32
 
        branch_app = BranchWSGIApp(self.tree.branch, '', **kw).app
33
 
        return TestApp(HTTPExceptionHandler(branch_app))
 
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)
34
61
 
35
62
 
36
63
class TestWithSimpleTree(BasicTests):
39
66
        BasicTests.setUp(self)
40
67
        self.createBranch()
41
68
 
 
69
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
42
70
        self.filecontents = ('some\nmultiline\ndata\n'
43
71
                             'with<htmlspecialchars\n')
44
 
        self.build_tree_contents(
45
 
            [('myfilename', self.filecontents)])
 
72
        try:
 
73
            f.write(self.filecontents)
 
74
        finally:
 
75
            f.close()
46
76
        self.tree.add('myfilename')
47
77
        self.fileid = self.tree.path2id('myfilename')
48
78
        self.msg = 'a very exciting commit message <'
53
83
        res = app.get('/changes')
54
84
        res.mustcontain(cgi.escape(self.msg))
55
85
 
56
 
    def test_changes_branch_from(self):
57
 
        app = self.setUpLoggerhead(served_url="lp:loggerhead")
58
 
        res = app.get('/changes')
59
 
        self.failUnless("To get this branch, use:" in res)
60
 
        self.failUnless("lp:loggerhead" in res)
61
 
        app = self.setUpLoggerhead(served_url=None)
62
 
        res = app.get('/changes')
63
 
        self.failIf("To get this branch, use:" in res)
64
 
 
65
86
    def test_changes_search(self):
66
87
        app = self.setUpLoggerhead()
67
88
        res = app.get('/changes', params={'q': 'foo'})
77
98
        app = self.setUpLoggerhead()
78
99
        res = app.get('/files')
79
100
        res.mustcontain('myfilename')
80
 
        res = app.get('/files/')
81
 
        res.mustcontain('myfilename')
82
 
        res = app.get('/files/1')
83
 
        res.mustcontain('myfilename')
84
 
        res = app.get('/files/1/')
85
 
        res.mustcontain('myfilename')
86
 
        res = app.get('/files/1/?file_id=' + self.tree.path2id(''))
87
 
        res.mustcontain('myfilename')
88
 
 
89
 
    def test_inventory_bad_rev_404(self):
90
 
        app = self.setUpLoggerhead()
91
 
        res = app.get('/files/200', status=404)
92
 
        res = app.get('/files/invalid-revid', status=404)
93
 
 
94
 
    def test_inventory_bad_path_404(self):
95
 
        app = self.setUpLoggerhead()
96
 
        res = app.get('/files/1/hooha', status=404)
97
 
        res = app.get('/files/1?file_id=dssadsada', status=404)
98
101
 
99
102
    def test_revision(self):
100
103
        app = self.setUpLoggerhead()
112
115
        app = self.setUpLoggerhead()
113
116
        res = app.get('/changes')
114
117
        res.mustcontain('No revisions!')
115
 
 
116
 
    def test_inventory(self):
117
 
        app = self.setUpLoggerhead()
118
 
        res = app.get('/files')
119
 
        res.mustcontain('No revisions!')
120