/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from configobj import ConfigObj
2
1
import cgi
3
2
import unittest
4
3
import os
6
5
import shutil
7
6
import logging
8
7
 
9
 
import cherrypy
10
 
from turbogears import testutil
11
 
 
12
 
import bzrlib
13
 
 
14
 
from loggerhead.controllers import Root
15
 
 
16
 
def test_simple():
 
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
17
19
    config = ConfigObj()
18
 
    r = Root(config)
19
 
    cherrypy.root = r
20
 
    testutil.create_request('/')
21
 
    assert 'loggerhead branches' in cherrypy.response.body[0]
 
20
    app = TestApp(Root(config))
 
21
    res = app.get('/')
 
22
    res.mustcontain('loggerhead branches')
22
23
 
23
24
 
24
25
class BasicTests(object):
50
51
            folder = '%(branch)s'
51
52
    """
52
53
 
 
54
    def makeHistory(self):
 
55
        return History.from_folder(self.bzrbranch)
 
56
 
53
57
    def setUpLoggerhead(self):
54
 
        ini = self.config_template%dict(branch=self.bzrbranch)
55
 
 
56
 
        config = ConfigObj(ini.splitlines())
57
 
        cherrypy.root = Root(config)
 
58
        app = TestApp(BranchWSGIApp(self.bzrbranch).app)
 
59
        return app
58
60
 
59
61
    def tearDown(self):
60
62
        if self.bzrbranch is not None:
61
63
            shutil.rmtree(self.bzrbranch)
62
64
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
63
65
 
 
66
 
64
67
class TestWithSimpleTree(BasicTests):
65
68
 
66
69
    def setUp(self):
79
82
        self.msg = 'a very exciting commit message <'
80
83
        self.revid = self.tree.commit(message=self.msg)
81
84
 
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()
88
85
 
89
86
    def test_changes(self):
90
 
        testutil.create_request('/project/branch/changes')
91
 
        assert cgi.escape(self.msg) in cherrypy.response.body[0]
 
87
        app = self.setUpLoggerhead()
 
88
        res = app.get('/changes')
 
89
        res.mustcontain(cgi.escape(self.msg))
92
90
 
93
91
    def test_changes_search(self):
94
 
        testutil.create_request('/project/branch/changes?q=foo')
95
 
        assert 'Sorry, no results found for your search.' in cherrypy.response.body[0]
 
92
        app = self.setUpLoggerhead()
 
93
        res = app.get('/changes', params={'q': 'foo'})
 
94
        res.mustcontain('Sorry, no results found for your search.')
96
95
 
97
96
    def test_annotate(self):
98
 
        testutil.create_request('/project/branch/annotate?'
99
 
                                + 'file_id='+self.fileid)
 
97
        app = self.setUpLoggerhead()
 
98
        res = app.get('/annotate', params={'file_id':self.fileid})
100
99
        for line in self.filecontents.splitlines():
101
 
            assert cgi.escape(line) in cherrypy.response.body[0]
 
100
            res.mustcontain(cgi.escape(line))
102
101
 
103
102
    def test_inventory(self):
104
 
        testutil.create_request('/project/branch/files')
105
 
        assert 'myfilename' in cherrypy.response.body[0]
 
103
        app = self.setUpLoggerhead()
 
104
        res = app.get('/files')
 
105
        res.mustcontain('myfilename')
106
106
 
107
107
    def test_revision(self):
108
 
        testutil.create_request('/project/branch/revision/' + self.revid)
109
 
        assert 'myfilename' in cherrypy.response.body[0]
 
108
        app = self.setUpLoggerhead()
 
109
        res = app.get('/revision/1')
 
110
        res.mustcontain('myfilename')
110
111
 
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
 
    """
120
112
 
121
113
class TestEmptyBranch(BasicTests):
122
114
 
123
115
    def setUp(self):
124
116
        BasicTests.setUp(self)
125
117
        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()
132
118
 
133
119
    def test_changes(self):
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
        app = self.setUpLoggerhead()
 
121
        res = app.get('/changes')
 
122
        res.mustcontain('No revisions!')
146
123