# HG changeset patch
# User cmlenz
# Date 1187185489 0
# Node ID 74c51f648466fd2c9fbc68bf0ad7934da20cd556
# Parent 11658e4af0cc9f0682e7ac3c22b242479cc217f2
Started some tests for the new admin interface.
diff --git a/bitten/admin.py b/bitten/admin.py
--- a/bitten/admin.py
+++ b/bitten/admin.py
@@ -9,14 +9,14 @@
"""Implementation of the web administration interface."""
-from pkg_resources import require
+from pkg_resources import require, DistributionNotFound
import re
from trac.core import *
try:
require("TracWebAdmin")
from webadmin.web_ui import IAdminPageProvider
-except ImportError:
+except DistributionNotFound, ImportError:
IAdminPageProvider = None
from bitten.model import BuildConfig, TargetPlatform
@@ -33,7 +33,7 @@
def get_admin_pages(self, req):
if req.perm.has_permission('BUILD_ADMIN'):
- yield ('bitten', 'Bitten', 'master', 'Build Master')
+ yield ('bitten', 'Builds', 'master', 'Master Settings')
def process_admin_request(self, req, cat, page, path_info):
from bitten.master import BuildMaster
@@ -75,7 +75,7 @@
def get_admin_pages(self, req):
if req.perm.has_permission('BUILD_MODIFY'):
- yield ('bitten', 'Bitten', 'configs', 'Configurations')
+ yield ('bitten', 'Builds', 'configs', 'Configurations')
def process_admin_request(self, req, cat, page, config_name):
data = {}
diff --git a/bitten/master.py b/bitten/master.py
--- a/bitten/master.py
+++ b/bitten/master.py
@@ -47,7 +47,7 @@
# Configuration options
adjust_timestamps = BoolOption('bitten', 'adjust_timestamps', False, doc=
- """Whether the timestamps of builds should be adjusted to be close '
+ """Whether the timestamps of builds should be adjusted to be close
to the timestamps of the corresponding changesets.""")
build_all = BoolOption('bitten', 'build_all', False, doc=
diff --git a/bitten/tests/__init__.py b/bitten/tests/__init__.py
--- a/bitten/tests/__init__.py
+++ b/bitten/tests/__init__.py
@@ -10,13 +10,14 @@
import unittest
-from bitten.tests import master, model, recipe, queue, slave, web_ui
+from bitten.tests import admin, master, model, recipe, queue, slave, web_ui
from bitten.build import tests as build
from bitten.report import tests as report
from bitten.util import tests as util
def suite():
suite = unittest.TestSuite()
+ suite.addTest(admin.suite())
suite.addTest(master.suite())
suite.addTest(model.suite())
suite.addTest(recipe.suite())
diff --git a/bitten/tests/admin.py b/bitten/tests/admin.py
new file mode 100644
--- /dev/null
+++ b/bitten/tests/admin.py
@@ -0,0 +1,156 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://bitten.edgewall.org/wiki/License.
+
+import shutil
+import tempfile
+import unittest
+
+from trac.core import TracError
+from trac.db import DatabaseManager
+from trac.perm import PermissionCache, PermissionSystem
+from trac.test import EnvironmentStub, Mock
+from trac.versioncontrol import Repository
+from trac.web.clearsilver import HDFWrapper
+from trac.web.href import Href
+from trac.web.main import Request, RequestDone
+from bitten.main import BuildSystem
+from bitten.model import BuildConfig, TargetPlatform, Build, schema
+from bitten.admin import BuildMasterAdminPageProvider, \
+ BuildConfigurationsAdminPageProvider
+
+
+class BuildMasterAdminPageProviderTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.env = EnvironmentStub()
+ self.env.path = tempfile.mkdtemp()
+
+ # Create tables
+ db = self.env.get_db_cnx()
+ cursor = db.cursor()
+ connector, _ = DatabaseManager(self.env)._get_connector()
+ for table in schema:
+ for stmt in connector.to_sql(table):
+ cursor.execute(stmt)
+
+ # Set up permissions
+ self.env.config.set('trac', 'permission_store',
+ 'DefaultPermissionStore')
+ PermissionSystem(self.env).grant_permission('joe', 'BUILD_ADMIN')
+
+ # Hook up a dummy repository
+ self.repos = Mock(
+ get_node=lambda path, rev=None: Mock(get_history=lambda: [],
+ isdir=True),
+ normalize_path=lambda path: path,
+ sync=lambda: None
+ )
+ self.env.get_repository = lambda authname=None: self.repos
+
+ def tearDown(self):
+ shutil.rmtree(self.env.path)
+
+ def test_get_admin_pages(self):
+ provider = BuildMasterAdminPageProvider(self.env)
+
+ req = Mock(perm=PermissionCache(self.env, 'joe'))
+ self.assertEqual([('bitten', 'Builds', 'master', 'Master Settings')],
+ list(provider.get_admin_pages(req)))
+
+ PermissionSystem(self.env).revoke_permission('joe', 'BUILD_ADMIN')
+ req = Mock(perm=PermissionCache(self.env, 'joe'))
+ self.assertEqual([], list(provider.get_admin_pages(req)))
+
+ def test_process_get_request(self):
+ provider = BuildMasterAdminPageProvider(self.env)
+
+ data = {}
+ req = Mock(method='GET', hdf=data,
+ perm=PermissionCache(self.env, 'joe'))
+ template_name, content_type = provider.process_admin_request(
+ req, 'bitten', 'master', ''
+ )
+ self.assertEqual('bitten_admin_master.cs', template_name)
+ self.assertEqual(None, content_type)
+ assert 'admin.master' in data
+ self.assertEqual({
+ 'slave_timeout': 3600,
+ 'adjust_timestamps': False,
+ 'build_all': False,
+ }, data['admin.master'])
+
+
+class BuildConfigurationsAdminPageProviderTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.env = EnvironmentStub()
+ self.env.path = tempfile.mkdtemp()
+
+ # Create tables
+ db = self.env.get_db_cnx()
+ cursor = db.cursor()
+ connector, _ = DatabaseManager(self.env)._get_connector()
+ for table in schema:
+ for stmt in connector.to_sql(table):
+ cursor.execute(stmt)
+
+ # Set up permissions
+ self.env.config.set('trac', 'permission_store',
+ 'DefaultPermissionStore')
+ PermissionSystem(self.env).grant_permission('joe', 'BUILD_MODIFY')
+
+ # Hook up a dummy repository
+ self.repos = Mock(
+ get_node=lambda path, rev=None: Mock(get_history=lambda: [],
+ isdir=True),
+ normalize_path=lambda path: path,
+ sync=lambda: None
+ )
+ self.env.get_repository = lambda authname=None: self.repos
+
+ def tearDown(self):
+ shutil.rmtree(self.env.path)
+
+ def test_get_admin_pages(self):
+ provider = BuildConfigurationsAdminPageProvider(self.env)
+
+ req = Mock(perm=PermissionCache(self.env, 'joe'))
+ self.assertEqual([('bitten', 'Builds', 'configs', 'Configurations')],
+ list(provider.get_admin_pages(req)))
+
+ PermissionSystem(self.env).revoke_permission('joe', 'BUILD_MODIFY')
+ req = Mock(perm=PermissionCache(self.env, 'joe'))
+ self.assertEqual([], list(provider.get_admin_pages(req)))
+
+ def test_process_get_request_overview_empty(self):
+ provider = BuildConfigurationsAdminPageProvider(self.env)
+
+ data = {}
+ req = Mock(method='GET', hdf=data,
+ perm=PermissionCache(self.env, 'joe'))
+ template_name, content_type = provider.process_admin_request(
+ req, 'bitten', 'configs', ''
+ )
+ self.assertEqual('bitten_admin_configs.cs', template_name)
+ self.assertEqual(None, content_type)
+ self.assertEqual([], data['admin']['configs'])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(
+ BuildMasterAdminPageProviderTestCase, 'test'
+ ))
+ suite.addTest(unittest.makeSuite(
+ BuildConfigurationsAdminPageProviderTestCase, 'test'
+ ))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
diff --git a/doc/commands.txt b/doc/commands.txt
--- a/doc/commands.txt
+++ b/doc/commands.txt
@@ -159,10 +159,10 @@
.. code-block:: xml
-
+
-Runs the `configure` script in the base directory, enable the `threadsafe`
-feature, and passing `-O` as `CFLAGS`. This is equivalent to::
+Runs the ``configure`` script in the base directory, enable the ``threadsafe``
+feature, and passing ``-O`` as ``CFLAGS``. This is equivalent to::
./configure --enable-threadsafe CFLAGS="-O"
@@ -298,7 +298,7 @@
-Executes the target `compile` of the `build.xml` buildfile at the top of the
+Executes the target ``compile`` of the ``build.xml`` buildfile at the top of the
project source directory.