def test_manual_start(run_parameters, expected_error, expected_message): trigger = CustomBuildTrigger(None, {"build_source": "foo"}) if expected_error is not None: with pytest.raises(expected_error) as ipe: trigger.manual_start(run_parameters) assert str(ipe.value) == expected_message else: assert isinstance(trigger.manual_start(run_parameters), PreparedBuild)
def test_handle_trigger_request(payload, expected_error, expected_message): trigger = CustomBuildTrigger(None, {'build_source': 'foo'}) request = AttrDict(dict(data=payload)) if expected_error is not None: with pytest.raises(expected_error) as ipe: trigger.handle_trigger_request(request) assert str(ipe.value) == expected_message else: assert isinstance(trigger.handle_trigger_request(request), PreparedBuild)
def attach_custom_build_trigger(namespace_name, repo_name): permission = AdministerRepositoryPermission(namespace_name, repo_name) if permission.can(): repo = model.repository.get_repository(namespace_name, repo_name) if not repo: msg = 'Invalid repository: %s/%s' % (namespace_name, repo_name) abort(404, message=msg) elif repo.kind.name != 'image': abort(501) trigger = model.build.create_build_trigger(repo, CustomBuildTrigger.service_name(), None, current_user.db_user()) repo_path = '%s/%s' % (namespace_name, repo_name) full_url = url_for('web.buildtrigger', path=repo_path, trigger=trigger.uuid) logger.debug('Redirecting to full url: %s', full_url) return redirect(full_url) abort(403)