15
14
# along with Tarmac. If not, see <http://www.gnu.org/licenses/>.
17
16
'''Tests for Tarmac!'''
22
from base64 import b64encode
23
from bzrlib.bzrdir import BzrDir
22
24
from bzrlib.directory_service import directories
23
25
from bzrlib.tests import TestCaseInTempDir
24
26
from bzrlib.transport import register_urlparse_netloc_protocol
26
28
from tarmac import branch
29
from tarmac.bin.commands import TarmacCommand
27
30
from tarmac.config import TarmacConfig
28
from tarmac.tests.mock import MockLPBranch
33
class MockLPProject(object):
34
'''A mock LP Project.'''
37
self.name = b64encode(
38
os.urandom(int(math.ceil(0.75 * 10))), '-_')[:10]
41
class MockLPBranch(object):
42
'''A mock LP Branch.'''
44
def __init__(self, tree_dir, source_branch=None):
45
self.tree_dir = tree_dir
48
source_dir = source_branch._internal_bzr_branch.bzrdir
49
bzrdir = source_dir.sprout(tree_dir)
50
self._internal_tree, self._internal_bzr_branch = \
51
bzrdir.open_tree_or_branch(tree_dir)
52
self.revision_count = source_branch.revision_count
54
self._internal_bzr_branch = BzrDir.create_branch_convenience(
56
self.revision_count = 0
57
self.bzr_identity = 'lp:%s' % os.path.basename(self.tree_dir)
58
self.web_link = self.bzr_identity
59
self.project = MockLPProject()
62
class cmd_mock(TarmacCommand):
66
"""Just a dummy command that does nothing."""
69
class MockModule(object):
73
self.__dict__['cmd_mock'] = cmd_mock
77
"""Quickly create an object with given attributes."""
79
def __init__(self, **names):
80
super(Thing, self).__init__(self, **names)
81
self.__dict__.update(names)
84
for item in self.values():
85
if not callable(item):
31
89
class TarmacTestCase(TestCaseInTempDir):