~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Kent Gibson
  • Date: 2007-06-08 10:25:35 UTC
  • mfrom: (128.2.2 robey)
  • mto: (128.3.1 robey.kg)
  • mto: This revision was merged to the branch mainline in revision 134.
  • Revision ID: kent@ispirenetworks.com-20070608102535-j9kwvlvy8njlpyb6
merge loggerhead.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from configobj import ConfigObj
 
2
import unittest
 
3
import os
 
4
import tempfile
 
5
import shutil
 
6
 
 
7
import cherrypy
 
8
from turbogears import testutil
 
9
 
 
10
import bzrlib
 
11
 
 
12
from loggerhead.controllers import Root
 
13
 
 
14
def test_simple():
 
15
    config = ConfigObj()
 
16
    r = Root(config)
 
17
    cherrypy.root = r
 
18
    testutil.create_request('/')
 
19
    assert 'loggerhead branches' in cherrypy.response.body[0]
 
20
 
 
21
config_template = """
 
22
[project]
 
23
    [[branch]]
 
24
        branch_name = 'branch'
 
25
        folder = '%s'
 
26
"""
 
27
 
 
28
 
 
29
class TestWithSimpleTree(object):
 
30
    def setUp(self):
 
31
        self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
 
32
        self.bzrbranch = tempfile.mkdtemp()
 
33
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
34
            self.bzrbranch, force_new_tree=True)
 
35
        tree = branch.bzrdir.open_workingtree()
 
36
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
 
37
        self.filecontents = 'some\nmultiline\ndata'
 
38
        try:
 
39
            f.write(self.filecontents)
 
40
        finally:
 
41
            f.close()
 
42
        tree.add('myfilename')
 
43
        self.fileid = tree.path2id('myfilename')
 
44
        self.msg = 'a very exciting commit message'
 
45
        self.revid = tree.commit(message=self.msg)
 
46
 
 
47
        ini = config_template%self.bzrbranch
 
48
 
 
49
        config = ConfigObj(ini.splitlines())
 
50
        cherrypy.root = Root(config)
 
51
 
 
52
    def tearDown(self):
 
53
        shutil.rmtree(self.bzrbranch)
 
54
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
 
55
 
 
56
    # there are so i can run it with py.test and take advantage of the
 
57
    # error reporting...
 
58
    def setup_method(self, meth):
 
59
        self.setUp()
 
60
 
 
61
    def teardown_method(self, meth):
 
62
        self.tearDown()
 
63
 
 
64
    def test_index(self):
 
65
        testutil.create_request('/')
 
66
        link = '<a href="/project/branch">branch</a>'
 
67
        assert link in cherrypy.response.body[0]
 
68
 
 
69
    def test_changes(self):
 
70
        testutil.create_request('/project/branch/changes')
 
71
        assert self.msg in cherrypy.response.body[0]
 
72
 
 
73
    def test_annotate(self):
 
74
        testutil.create_request('/project/branch/annotate?'
 
75
                                + 'file_id='+self.fileid)
 
76
        for line in self.filecontents.splitlines():
 
77
            assert line in cherrypy.response.body[0]
 
78
 
 
79
    def test_inventory(self):
 
80
        testutil.create_request('/project/branch/files')
 
81
        assert 'myfilename' in cherrypy.response.body[0]
 
82