~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Robey Pointer
  • Date: 2006-12-13 03:02:49 UTC
  • Revision ID: robey@lag.net-20061213030249-poznwaqmwiqmm7jx
add an annotate page, and rename inventory -> files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from configobj import ConfigObj
2
 
import cgi
3
 
import unittest
4
 
import os
5
 
import tempfile
6
 
import shutil
7
 
import logging
8
 
 
9
 
import cherrypy
10
 
from turbogears import testutil
11
 
 
12
 
import bzrlib
13
 
 
14
 
from loggerhead.controllers import Root
15
 
 
16
 
def test_simple():
17
 
    config = ConfigObj()
18
 
    r = Root(config)
19
 
    cherrypy.root = r
20
 
    testutil.create_request('/')
21
 
    assert 'loggerhead branches' in cherrypy.response.body[0]
22
 
 
23
 
 
24
 
class BasicTests(object):
25
 
 
26
 
    # setup_method and teardown_method are so i can run the tests with
27
 
    # py.test and take advantage of the error reporting.
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
 
        ini = self.config_template%dict(branch=self.bzrbranch)
55
 
 
56
 
        config = ConfigObj(ini.splitlines())
57
 
        cherrypy.root = Root(config)
58
 
 
59
 
    def tearDown(self):
60
 
        if self.bzrbranch is not None:
61
 
            shutil.rmtree(self.bzrbranch)
62
 
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
63
 
 
64
 
class TestWithSimpleTree(BasicTests):
65
 
 
66
 
    def setUp(self):
67
 
        BasicTests.setUp(self)
68
 
        self.createBranch()
69
 
 
70
 
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
71
 
        self.filecontents = ('some\nmultiline\ndata\n'
72
 
                             'with<htmlspecialchars\n')
73
 
        try:
74
 
            f.write(self.filecontents)
75
 
        finally:
76
 
            f.close()
77
 
        self.tree.add('myfilename')
78
 
        self.fileid = self.tree.path2id('myfilename')
79
 
        self.msg = 'a very exciting commit message <'
80
 
        self.revid = self.tree.commit(message=self.msg)
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()
88
 
 
89
 
    def test_changes(self):
90
 
        testutil.create_request('/project/branch/changes')
91
 
        assert cgi.escape(self.msg) in cherrypy.response.body[0]
92
 
 
93
 
    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]
96
 
 
97
 
    def test_annotate(self):
98
 
        testutil.create_request('/project/branch/annotate?'
99
 
                                + 'file_id='+self.fileid)
100
 
        for line in self.filecontents.splitlines():
101
 
            assert cgi.escape(line) in cherrypy.response.body[0]
102
 
 
103
 
    def test_inventory(self):
104
 
        testutil.create_request('/project/branch/files')
105
 
        assert 'myfilename' in cherrypy.response.body[0]
106
 
 
107
 
    def test_revision(self):
108
 
        testutil.create_request('/project/branch/revision/' + self.revid)
109
 
        assert 'myfilename' in cherrypy.response.body[0]
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
 
    """
120
 
 
121
 
class TestEmptyBranch(BasicTests):
122
 
 
123
 
    def setUp(self):
124
 
        BasicTests.setUp(self)
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()
132
 
 
133
 
    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
 
    """
146