~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-29 21:51:12 UTC
  • Revision ID: robey@lag.net-20061229215112-d164jqo8djs3lims
add the script i use to update the website, so i don't lose it

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
 
 
27
 
    # there are so i can run it with py.test and take advantage of the
28
 
    # error reporting...
29
 
    def setup_method(self, meth):
30
 
        self.setUp()
31
 
 
32
 
    def teardown_method(self, meth):
33
 
        self.tearDown()
34
 
 
35
 
    def setUp(self):
36
 
        #logging.basicConfig(level=logging.DEBUG)
37
 
        self.bzrbranch = None
38
 
        self.old_bzrhome = None
39
 
 
40
 
    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 setUpLoggerhead(self):
55
 
        ini = self.config_template%dict(branch=self.bzrbranch)
56
 
 
57
 
        config = ConfigObj(ini.splitlines())
58
 
        cherrypy.root = Root(config)
59
 
 
60
 
    def tearDown(self):
61
 
        if self.bzrbranch is not None:
62
 
            shutil.rmtree(self.bzrbranch)
63
 
        bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
64
 
 
65
 
class TestWithSimpleTree(BasicTests):
66
 
 
67
 
    def setUp(self):
68
 
        BasicTests.setUp(self)
69
 
        self.createBranch()
70
 
 
71
 
        f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
72
 
        self.filecontents = ('some\nmultiline\ndata\n'
73
 
                             'with<htmlspecialchars\n')
74
 
        try:
75
 
            f.write(self.filecontents)
76
 
        finally:
77
 
            f.close()
78
 
        self.tree.add('myfilename')
79
 
        self.fileid = self.tree.path2id('myfilename')
80
 
        self.msg = 'a very exciting commit message <'
81
 
        self.revid = self.tree.commit(message=self.msg)
82
 
 
83
 
        self.setUpLoggerhead()
84
 
 
85
 
    def test_index(self):
86
 
        testutil.create_request('/')
87
 
        link = '<a href="/project/branch">branch</a>'
88
 
        assert link in cherrypy.response.body[0]
89
 
 
90
 
    def test_changes(self):
91
 
        testutil.create_request('/project/branch/changes')
92
 
        assert cgi.escape(self.msg) in cherrypy.response.body[0]
93
 
 
94
 
    def test_changes_search(self):
95
 
        testutil.create_request('/project/branch/changes?q=foo')
96
 
        assert 'Sorry, no results found for your search.' in cherrypy.response.body[0]
97
 
 
98
 
    def test_annotate(self):
99
 
        testutil.create_request('/project/branch/annotate?'
100
 
                                + 'file_id='+self.fileid)
101
 
        for line in self.filecontents.splitlines():
102
 
            assert cgi.escape(line) in cherrypy.response.body[0]
103
 
 
104
 
    def test_inventory(self):
105
 
        testutil.create_request('/project/branch/files')
106
 
        assert 'myfilename' in cherrypy.response.body[0]
107
 
 
108
 
    def test_revision(self):
109
 
        testutil.create_request('/project/branch/revision/' + self.revid)
110
 
        assert 'myfilename' in cherrypy.response.body[0]
111
 
 
112
 
class TestWithSimpleTreeAndCache(TestWithSimpleTree):
113
 
    config_template = """
114
 
    testing = True
115
 
    [project]
116
 
        [[branch]]
117
 
            branch_name = 'branch'
118
 
            folder = '%(branch)s'
119
 
            cachepath = '%(branch)s/cache'
120
 
    """
121
 
 
122
 
class TestEmptyBranch(BasicTests):
123
 
 
124
 
    def setUp(self):
125
 
        BasicTests.setUp(self)
126
 
        self.createBranch()
127
 
        self.setUpLoggerhead()
128
 
 
129
 
    def test_index(self):
130
 
        testutil.create_request('/')
131
 
        link = '<a href="/project/branch">branch</a>'
132
 
        assert link in cherrypy.response.body[0]
133
 
 
134
 
    def test_changes(self):
135
 
        testutil.create_request('/project/branch/changes')
136
 
        assert 'No revisions!' in cherrypy.response.body[0]
137
 
 
138
 
class TestEmptyBranchWithCache(TestEmptyBranch):
139
 
    config_template = """
140
 
    testing = True
141
 
    [project]
142
 
        [[branch]]
143
 
            branch_name = 'branch'
144
 
            folder = '%(branch)s'
145
 
            cachepath = '%(branch)s/cache'
146
 
    """
147