本文整理汇总了Python中bitten.model.BuildConfig类的典型用法代码示例。如果您正苦于以下问题:Python BuildConfig类的具体用法?Python BuildConfig怎么用?Python BuildConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuildConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_process_deactivate_config
def test_process_deactivate_config(self):
BuildConfig(self.env, name='foo', path='branches/foo',
active=True).insert()
BuildConfig(self.env, name='bar', path='branches/bar',
active=True).insert()
redirected_to = []
def redirect(url):
redirected_to.append(url)
raise RequestDone
req = Mock(method='POST', perm=PermissionCache(self.env, 'joe'),
abs_href=Href('http://example.org/'), redirect=redirect,
authname='joe',
args={'apply': ''})
provider = BuildConfigurationsAdminPageProvider(self.env)
try:
provider.render_admin_panel(req, 'bitten', 'configs', '')
self.fail('Expected RequestDone')
except RequestDone:
self.assertEqual('http://example.org/admin/bitten/configs',
redirected_to[0])
config = BuildConfig.fetch(self.env, name='foo')
self.assertEqual(False, config.active)
config = BuildConfig.fetch(self.env, name='bar')
self.assertEqual(False, config.active)
示例2: test_view_config
def test_view_config(self):
config = BuildConfig(self.env, name='test', path='trunk')
config.insert()
platform = TargetPlatform(self.env, config='test', name='any')
platform.insert()
PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
req = Mock(method='GET', base_path='', cgi_location='',
path_info='/build/test', href=Href('/trac'), args={},
chrome={}, authname='joe',
perm=PermissionCache(self.env, 'joe'))
root = Mock(get_entries=lambda: ['foo'],
get_history=lambda: [('trunk', rev, 'edit') for rev in
range(123, 111, -1)])
self.repos.get_node=lambda path, rev=None: root
self.repos.youngest_rev=123
self.repos.get_changeset=lambda rev: Mock(author='joe', date=99)
module = BuildConfigController(self.env)
assert module.match_request(req)
_, data, _ = module.process_request(req)
self.assertEqual('view_config', data['page_mode'])
assert not 'next' in req.chrome['links']
self.assertEquals(Resource('build', 'test'), data['context'].resource)
self.assertEquals([], data['config']['attachments']['attachments'])
self.assertEquals('/trac/attachment/build/test/',
data['config']['attachments']['attach_href'])
示例3: test_view_config_paging
def test_view_config_paging(self):
config = BuildConfig(self.env, name='test', path='trunk')
config.insert()
platform = TargetPlatform(self.env, config='test', name='any')
platform.insert()
PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
req = Mock(method='GET', base_path='', cgi_location='',
path_info='/build/test', href=Href('/trac'), args={},
chrome={}, authname='joe',
perm=PermissionCache(self.env, 'joe'))
root = Mock(get_entries=lambda: ['foo'],
get_history=lambda: [('trunk', rev, 'edit') for rev in
range(123, 110, -1)])
self.repos = Mock(get_node=lambda path, rev=None: root,
sync=lambda: None, normalize_path=lambda path: path)
self.repos.authz = Mock(has_permission=lambda path: True, assert_permission=lambda path: None)
module = BuildConfigController(self.env)
assert module.match_request(req)
_, data, _ = module.process_request(req)
if req.chrome:
self.assertEqual('/trac/build/test?page=2',
req.chrome['links']['next'][0]['href'])
示例4: test_cancel_build
def test_cancel_build(self):
config = BuildConfig(self.env, 'test', path='somepath', active=True,
recipe='<build></build>')
config.insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
status=Build.IN_PROGRESS, started=42)
build.insert()
outheaders = {}
outbody = StringIO()
req = Mock(method='DELETE', base_path='',
path_info='/builds/%d' % build.id,
href=Href('/trac'), remote_addr='127.0.0.1', args={},
perm=PermissionCache(self.env, 'hal'),
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write,
incookie=Cookie('trac_auth='))
module = BuildMaster(self.env)
assert module.match_request(req)
self.assertRaises(RequestDone, module.process_request, req)
self.assertEqual(204, outheaders['Status'])
self.assertEqual('', outbody.getvalue())
# Make sure the started timestamp has been set
build = Build.fetch(self.env, build.id)
self.assertEqual(Build.PENDING, build.status)
assert not build.started
示例5: test_bitten_keeps_order_of_revisions_from_versioncontrol
def test_bitten_keeps_order_of_revisions_from_versioncontrol(self):
# Trac's API specifies that they are sorted chronological (backwards)
# We must not assume that these revision numbers can be sorted later on,
# for example the mercurial plugin will return the revisions as strings
# (e.g. '880:4c19fa95fb9e')
config = BuildConfig(self.env, name='test', path='trunk')
config.insert()
platform = TargetPlatform(self.env, config='test', name='any')
platform.insert()
PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
req = Mock(method='GET', base_path='', cgi_location='',
path_info='/build/'+config.name, href=Href('/trac'), args={},
chrome={}, authname='joe',
perm=PermissionCache(self.env, 'joe'))
# revisions are intentionally not sorted in any way - bitten should just keep them!
revision_ids = [5, 8, 2]
revision_list = [('trunk', revision, 'edit') for revision in revision_ids]
root = Mock(get_entries=lambda: ['foo'], get_history=lambda: revision_list)
self.repos.get_node=lambda path, rev=None: root
self.repos.youngest_rev=5
self.repos.get_changeset=lambda rev: Mock(author='joe', date=99)
module = BuildConfigController(self.env)
assert module.match_request(req)
_, data, _ = module.process_request(req)
actual_revision_ids = data['config']['revisions']
self.assertEquals(revision_ids, actual_revision_ids)
示例6: test_insert
def test_insert(self):
config = BuildConfig(self.env, name='test', path='trunk', label='Test')
config.insert()
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("SELECT name,path,label,active,description "
"FROM bitten_config")
self.assertEqual(('test', 'trunk', 'Test', 0, ''), cursor.fetchone())
示例7: test_should_delete_build_platform_dont_exist
def test_should_delete_build_platform_dont_exist(self):
messages = []
self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
config = BuildConfig(self.env, 'test', active=True)
config.insert()
build = Build(self.env, config=config.name, rev=42,
platform="no-stuff", rev_time=123456)
build.insert()
queue = BuildQueue(self.env, build_all=True)
self.assertEqual(True, queue.should_delete_build(build, self.repos))
self.assert_("platform no longer exists" in messages[0])
示例8: test_should_delete_build_config_deactivated
def test_should_delete_build_config_deactivated(self):
messages = []
self.env.log = Mock(info=lambda msg, *args: messages.append(msg))
config = BuildConfig(self.env, 'test', active=False)
config.insert()
platform = TargetPlatform(self.env, config='test', name='stuff')
platform.insert()
build = Build(self.env, config=config.name, rev=42,
platform=platform.id, rev_time=123456)
build.insert()
queue = BuildQueue(self.env, build_all=True)
self.assertEqual(True, queue.should_delete_build(build, self.repos))
self.assert_("configuration is deactivated" in messages[0])
示例9: test_process_attach_build
def test_process_attach_build(self):
body, content_type = encode_multipart_formdata({
'description': 'baz baz',
'file': ('baz.txt', 'hello baz'),
'__FORM_TOKEN': '123456'})
args = {}
for k, v in dict(cgi.FieldStorage(fp=StringIO(body), environ={
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': content_type})
).items():
if v.filename:
args[k] = v
else:
args[k] = v.value
args.update({'collection': 'attach', 'member': 'build'})
self.assertTrue('file' in args)
outheaders = {}
outbody = StringIO()
req = Mock(args=args, form_token='123456', authname='hal',
remote_addr='127.0.0.1',
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write)
config = BuildConfig(self.env, 'test', path='somepath', active=True,
recipe='')
config.insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
started=42, status=Build.IN_PROGRESS)
build.insert()
module = BuildMaster(self.env)
self.assertRaises(RequestDone, module._process_attachment,
req, config, build)
self.assertEqual(201, outheaders['Status'])
self.assertEqual('18', outheaders['Content-Length'])
self.assertEqual('text/plain', outheaders['Content-Type'])
self.assertEqual('Attachment created', outbody.getvalue())
build_atts = list(Attachment.select(self.env, 'build', 'test/1'))
self.assertEquals(1, len(build_atts))
self.assertEquals('hal', build_atts[0].author)
self.assertEquals('baz baz', build_atts[0].description)
self.assertEquals('baz.txt', build_atts[0].filename)
self.assertEquals('hello baz',
build_atts[0].open().read())
示例10: process_request
def process_request(self, req):
req.perm.assert_permission('BUILD_EXEC')
if 'id' not in req.args:
if req.method != 'POST':
raise HTTPMethodNotAllowed('Method not allowed')
return self._process_build_creation(req)
build = Build.fetch(self.env, req.args['id'])
if not build:
raise HTTPNotFound('No such build')
config = BuildConfig.fetch(self.env, build.config)
if not req.args['collection']:
if req.method == 'DELETE':
return self._process_build_cancellation(req, config, build)
else:
return self._process_build_initiation(req, config, build)
if req.method != 'POST':
raise HTTPMethodNotAllowed('Method not allowed')
if req.args['collection'] == 'steps':
return self._process_build_step(req, config, build)
else:
raise HTTPNotFound('No such collection')
示例11: should_delete_build
def should_delete_build(self, build, repos):
config = BuildConfig.fetch(self.env, build.config)
platform = TargetPlatform.fetch(self.env, build.platform)
# Platform may or may not exist anymore - get safe name for logging
platform_name = platform and platform.name \
or 'unknown platform "%s"' % build.platform
# Drop build if platform no longer exists
if not platform:
self.log.info('Dropping build of configuration "%s" at '
'revision [%s] on %s because the platform no longer '
'exists', config.name, build.rev, platform_name)
return True
# Ignore pending builds for deactived build configs
if not config.active:
self.log.info('Dropping build of configuration "%s" at '
'revision [%s] on %s because the configuration is '
'deactivated', config.name, build.rev, platform_name)
return True
# If not 'build_all', drop if a more recent revision is available
if not self.build_all and \
len(list(Build.select(self.env, config=build.config,
min_rev_time=build.rev_time, platform=build.platform))) > 1:
self.log.info('Dropping build of configuration "%s" at revision [%s] '
'on "%s" because a more recent build exists',
config.name, build.rev, platform_name)
return True
return False
示例12: get_navigation_items
def get_navigation_items(self, req):
"""Return the navigation item for access the build status overview from
the Trac navigation bar."""
if 'BUILD_VIEW' in req.perm:
status = ''
if BuildMaster(self.env).quick_status:
repos = self.env.get_repository(req.authname)
if hasattr(repos, 'sync'):
repos.sync()
for config in BuildConfig.select(self.env,
include_inactive=False):
prev_rev = None
for platform, rev, build in collect_changes(repos, config):
if rev != prev_rev:
if prev_rev is not None:
break
prev_rev = rev
if build:
build_data = _get_build_data(self.env, req, build)
if build_data['status'] == 'failed':
status='bittenfailed'
break
if build_data['status'] == 'in progress':
status='bitteninprogress'
elif not status:
if (build_data['status'] == 'completed'):
status='bittencompleted'
if not status:
status='bittenpending'
yield ('mainnav', 'build',
tag.a('Builds Status', href=req.href.build(), accesskey=5,
class_=status))
示例13: test_process_update_config
def test_process_update_config(self):
BuildConfig(self.env, name='foo', label='Foo', path='branches/foo',
active=True).insert()
redirected_to = []
def redirect(url):
redirected_to.append(url)
raise RequestDone
req = Mock(method='POST', perm=PermissionCache(self.env, 'joe'),
abs_href=Href('http://example.org/'), redirect=redirect,
authname='joe', chrome={'warnings': [], 'notices': []},
href=Href('/'),
args={'save': '', 'name': 'foo', 'label': 'Foobar',
'description': 'Thanks for all the fish!'})
provider = BuildConfigurationsAdminPageProvider(self.env)
try:
provider.render_admin_panel(req, 'bitten', 'configs', 'foo')
self.fail('Expected RequestDone')
except RequestDone:
self.assertEqual(['Configuration Saved.'], req.chrome['notices'])
self.assertEqual('http://example.org/admin/bitten/configs/foo',
redirected_to[0])
config = BuildConfig.fetch(self.env, name='foo')
self.assertEqual('Foobar', config.label)
self.assertEqual('Thanks for all the fish!', config.description)
示例14: populate
def populate(self):
"""Add a build for the next change on each build configuration to the
queue.
The next change is the latest repository check-in for which there isn't
a corresponding build on each target platform. Repeatedly calling this
method will eventually result in the entire change history of the build
configuration being in the build queue.
"""
repos = self.env.get_repository()
assert repos, 'No "(default)" Repository: Add a repository or alias ' \
'named "(default)" to Trac.'
db = self.env.get_db_cnx()
builds = []
for config in BuildConfig.select(self.env, db=db):
platforms = []
for platform, rev, build in collect_changes(repos, config, db):
if not self.build_all and platform.id in platforms:
# We've seen this platform already, so these are older
# builds that should only be built if built_all=True
self.log.debug('Ignoring older revisions for configuration '
'%r on %r', config.name, platform.name)
break
platforms.append(platform.id)
if build is None:
self.log.info('Enqueuing build of configuration "%s" at '
'revision [%s] on %s', config.name, rev,
platform.name)
rev_time = to_timestamp(repos.get_changeset(rev).date)
age = int(time.time()) - rev_time
if self.stabilize_wait and age < self.stabilize_wait:
self.log.info('Delaying build of revision %s until %s '
'seconds pass. Current age is: %s '
'seconds' % (rev, self.stabilize_wait,
age))
continue
build = Build(self.env, config=config.name,
platform=platform.id, rev=str(rev),
rev_time=rev_time)
builds.append(build)
for build in builds:
try:
build.insert(db=db)
db.commit()
except Exception, e:
# really only want to catch IntegrityErrors raised when
# a second slave attempts to add builds with the same
# (config, platform, rev) as an existing build.
self.log.info('Failed to insert build of configuration "%s" '
'at revision [%s] on platform [%s]: %s',
build.config, build.rev, build.platform, e)
db.rollback()
示例15: get_annotation_data
def get_annotation_data(self, context):
add_stylesheet(context.req, 'bitten/bitten_coverage.css')
resource = context.resource
self.log.debug("Looking for coverage report for %[email protected]%s..." % (
resource.id, str(resource.version)))
builds = Build.select(self.env, rev=resource.version)
reports = []
for build in builds:
config = BuildConfig.fetch(self.env, build.config)
if not resource.id.startswith(config.branch):
continue
reports = Report.select(self.env, build=build.id,
category='coverage')
branch_in_config = resource.id[len(config.branch):]
for report in reports:
for item in report.items:
if item.get('file') == branch_in_config:
coverage = item.get('line_hits', '').split()
if coverage:
# Return first result with line data
self.log.debug(
"Coverage annotate for %[email protected]%s: %s" % \
(resource.id, resource.version, coverage))
return coverage
return []