~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2008-04-18 10:16:47 UTC
  • mfrom: (155.1.5 revision-size-limit)
  • Revision ID: launchpad@pqm.canonical.com-20080418101647-2k1lv1l0edudd191
[r=jml] don't display large diffs richly, as this consumes enormous amounts of RAM during rendering

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from configobj import ConfigObj
1
2
import cgi
2
3
import unittest
3
4
import os
5
6
import shutil
6
7
import logging
7
8
 
8
 
import bzrlib.bzrdir
9
 
import bzrlib.osutils
10
 
from configobj import ConfigObj
11
 
 
12
 
from loggerhead.history import History
13
 
from loggerhead.apps.branch import BranchWSGIApp
14
 
from paste.fixture import TestApp
15
 
 
16
 
 
17
 
def test_config_root():
18
 
    from loggerhead.apps.config import Root
 
9
import cherrypy
 
10
from turbogears import testutil
 
11
 
 
12
import bzrlib
 
13
 
 
14
from loggerhead.controllers import Root
 
15
 
 
16
def test_simple():
19
17
    config = ConfigObj()
20
 
    app = TestApp(Root(config))
21
 
    res = app.get('/')
22
 
    res.mustcontain('loggerhead branches')
 
18
    r = Root(config)
 
19
    cherrypy.root = r
 
20
    testutil.create_request('/')
 
21
    assert 'loggerhead branches' in cherrypy.response.body[0]
23
22
 
24
23
 
25
24
class BasicTests(object):
33
32
        self.tearDown()
34
33
 
35
34
    def setUp(self):
36
 
        logging.basicConfig(level=logging.DEBUG)
 
35
        #logging.basicConfig(level=logging.DEBUG)
37
36
        self.bzrbranch = None
38
37
        self.old_bzrhome = None
39
38
 
52
51
    """
53
52
 
54
53
    def setUpLoggerhead(self):
55
 
        app = TestApp(BranchWSGIApp(self.branch).app)
56
 
        return app
 
54
        ini = self.config_template%dict(branch=self.bzrbranch)
 
55
 
 
56
        config = ConfigObj(ini.splitlines())
 
57
        cherrypy.root = Root(config)
57
58
 
58
59
    def tearDown(self):
59
60
        if self.bzrbranch is not None:
60
61
            shutil.rmtree(self.bzrbranch)
61
62
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
62
63
 
63
 
 
64
64
class TestWithSimpleTree(BasicTests):
65
65
 
66
66
    def setUp(self):
79
79
        self.msg = 'a very exciting commit message <'
80
80
        self.revid = self.tree.commit(message=self.msg)
81
81
 
 
82
        self.setUpLoggerhead()
 
83
 
 
84
    def test_index(self):
 
85
        testutil.create_request('/')
 
86
        link = '<a href="/project/branch">branch</a>'
 
87
        assert link in cherrypy.response.body[0].lower()
82
88
 
83
89
    def test_changes(self):
84
 
        app = self.setUpLoggerhead()
85
 
        res = app.get('/changes')
86
 
        res.mustcontain(cgi.escape(self.msg))
 
90
        testutil.create_request('/project/branch/changes')
 
91
        assert cgi.escape(self.msg) in cherrypy.response.body[0]
87
92
 
88
93
    def test_changes_search(self):
89
 
        app = self.setUpLoggerhead()
90
 
        res = app.get('/changes', params={'q': 'foo'})
91
 
        res.mustcontain('Sorry, no results found for your search.')
 
94
        testutil.create_request('/project/branch/changes?q=foo')
 
95
        assert 'Sorry, no results found for your search.' in cherrypy.response.body[0]
92
96
 
93
97
    def test_annotate(self):
94
 
        app = self.setUpLoggerhead()
95
 
        res = app.get('/annotate', params={'file_id':self.fileid})
 
98
        testutil.create_request('/project/branch/annotate?'
 
99
                                + 'file_id='+self.fileid)
96
100
        for line in self.filecontents.splitlines():
97
 
            res.mustcontain(cgi.escape(line))
 
101
            assert cgi.escape(line) in cherrypy.response.body[0]
98
102
 
99
103
    def test_inventory(self):
100
 
        app = self.setUpLoggerhead()
101
 
        res = app.get('/files')
102
 
        res.mustcontain('myfilename')
 
104
        testutil.create_request('/project/branch/files')
 
105
        assert 'myfilename' in cherrypy.response.body[0]
103
106
 
104
107
    def test_revision(self):
105
 
        app = self.setUpLoggerhead()
106
 
        res = app.get('/revision/1')
107
 
        res.mustcontain('myfilename')
 
108
        testutil.create_request('/project/branch/revision/' + self.revid)
 
109
        assert 'myfilename' in cherrypy.response.body[0]
108
110
 
 
111
class TestWithSimpleTreeAndCache(TestWithSimpleTree):
 
112
    config_template = """
 
113
    testing = True
 
114
    [project]
 
115
        [[branch]]
 
116
            branch_name = 'branch'
 
117
            folder = '%(branch)s'
 
118
            cachepath = '%(branch)s/cache'
 
119
    """
109
120
 
110
121
class TestEmptyBranch(BasicTests):
111
122
 
112
123
    def setUp(self):
113
124
        BasicTests.setUp(self)
114
125
        self.createBranch()
 
126
        self.setUpLoggerhead()
 
127
 
 
128
    def test_index(self):
 
129
        testutil.create_request('/')
 
130
        link = '<a href="/project/branch">branch</a>'
 
131
        assert link in cherrypy.response.body[0].lower()
115
132
 
116
133
    def test_changes(self):
117
 
        app = self.setUpLoggerhead()
118
 
        res = app.get('/changes')
119
 
        res.mustcontain('No revisions!')
 
134
        testutil.create_request('/project/branch/changes')
 
135
        assert 'No revisions!' in cherrypy.response.body[0]
 
136
 
 
137
class TestEmptyBranchWithCache(TestEmptyBranch):
 
138
    config_template = """
 
139
    testing = True
 
140
    [project]
 
141
        [[branch]]
 
142
            branch_name = 'branch'
 
143
            folder = '%(branch)s'
 
144
            cachepath = '%(branch)s/cache'
 
145
    """
120
146