~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Michael Hudson
  • Date: 2009-03-19 18:47:42 UTC
  • mto: This revision was merged to the branch mainline in revision 310.
  • Revision ID: michael.hudson@canonical.com-20090319184742-46w8ftcm4exd1hj6
fix tests by deletion :/

Show diffs side-by-side

added added

removed removed

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