Add ability for triggers to be disabled
Will be used in the followup commit to automatically disable broken triggers
This commit is contained in:
parent
1e54a4d9e9
commit
c35eec0615
18 changed files with 358 additions and 37 deletions
|
@ -13,7 +13,11 @@ from endpoints.api.signing import RepositorySignatures
|
|||
from endpoints.api.search import ConductRepositorySearch
|
||||
from endpoints.api.superuser import SuperUserRepositoryBuildLogs, SuperUserRepositoryBuildResource
|
||||
from endpoints.api.superuser import SuperUserRepositoryBuildStatus
|
||||
<<<<<<< HEAD
|
||||
from endpoints.api.appspecifictokens import AppTokens, AppToken
|
||||
=======
|
||||
from endpoints.api.trigger import BuildTrigger
|
||||
>>>>>>> Add ability for triggers to be disabled
|
||||
from endpoints.test.shared import client_with_identity, toggle_feature
|
||||
|
||||
from test.fixtures import *
|
||||
|
@ -24,6 +28,7 @@ REPO_PARAMS = {'repository': 'devtable/someapp'}
|
|||
SEARCH_PARAMS = {'query': ''}
|
||||
NOTIFICATION_PARAMS = {'namespace': 'devtable', 'repository': 'devtable/simple', 'uuid': 'some uuid'}
|
||||
TOKEN_PARAMS = {'token_uuid': 'someuuid'}
|
||||
TRIGGER_PARAMS = {'repository': 'devtable/simple', 'trigger_uuid': 'someuuid'}
|
||||
|
||||
@pytest.mark.parametrize('resource,method,params,body,identity,expected', [
|
||||
(AppTokens, 'GET', {}, {}, None, 401),
|
||||
|
@ -89,7 +94,22 @@ TOKEN_PARAMS = {'token_uuid': 'someuuid'}
|
|||
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'freshuser', 403),
|
||||
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'reader', 403),
|
||||
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'devtable', 404),
|
||||
|
||||
|
||||
(BuildTrigger, 'GET', TRIGGER_PARAMS, {}, None, 401),
|
||||
(BuildTrigger, 'GET', TRIGGER_PARAMS, {}, 'freshuser', 403),
|
||||
(BuildTrigger, 'GET', TRIGGER_PARAMS, {}, 'reader', 403),
|
||||
(BuildTrigger, 'GET', TRIGGER_PARAMS, {}, 'devtable', 404),
|
||||
|
||||
(BuildTrigger, 'DELETE', TRIGGER_PARAMS, {}, None, 403),
|
||||
(BuildTrigger, 'DELETE', TRIGGER_PARAMS, {}, 'freshuser', 403),
|
||||
(BuildTrigger, 'DELETE', TRIGGER_PARAMS, {}, 'reader', 403),
|
||||
(BuildTrigger, 'DELETE', TRIGGER_PARAMS, {}, 'devtable', 404),
|
||||
|
||||
(BuildTrigger, 'PUT', TRIGGER_PARAMS, {}, None, 403),
|
||||
(BuildTrigger, 'PUT', TRIGGER_PARAMS, {}, 'freshuser', 403),
|
||||
(BuildTrigger, 'PUT', TRIGGER_PARAMS, {}, 'reader', 403),
|
||||
(BuildTrigger, 'PUT', TRIGGER_PARAMS, {}, 'devtable', 400),
|
||||
|
||||
(RepositoryUserTransitivePermission, 'GET', {'username': 'A2O9','repository': 'public/publicrepo'}, None, None, 401),
|
||||
(RepositoryUserTransitivePermission, 'GET', {'username': 'A2O9','repository': 'public/publicrepo'}, None, 'freshuser', 403),
|
||||
(RepositoryUserTransitivePermission, 'GET', {'username': 'A2O9','repository': 'public/publicrepo'}, None, 'reader', 403),
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import pytest
|
||||
import json
|
||||
|
||||
from data import model
|
||||
from endpoints.api.trigger_analyzer import is_parent
|
||||
from endpoints.api.trigger import BuildTrigger
|
||||
from endpoints.api.test.shared import conduct_api_call
|
||||
from endpoints.test.shared import client_with_identity
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
@pytest.mark.parametrize('context,dockerfile_path,expected', [
|
||||
|
@ -20,3 +26,30 @@ from endpoints.api.trigger_analyzer import is_parent
|
|||
])
|
||||
def test_super_user_build_endpoints(context, dockerfile_path, expected):
|
||||
assert is_parent(context, dockerfile_path) == expected
|
||||
|
||||
|
||||
def test_enabled_disabled_trigger(app, client):
|
||||
trigger = model.build.list_build_triggers('devtable', 'building')[0]
|
||||
trigger.config = json.dumps({'hook_id': 'someid'})
|
||||
trigger.save()
|
||||
|
||||
params = {
|
||||
'repository': 'devtable/building',
|
||||
'trigger_uuid': trigger.uuid,
|
||||
}
|
||||
|
||||
body = {
|
||||
'enabled': False,
|
||||
}
|
||||
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
result = conduct_api_call(cl, BuildTrigger, 'PUT', params, body, 200).json
|
||||
assert not result['enabled']
|
||||
|
||||
body = {
|
||||
'enabled': True,
|
||||
}
|
||||
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
result = conduct_api_call(cl, BuildTrigger, 'PUT', params, body, 200).json
|
||||
assert result['enabled']
|
||||
|
|
Reference in a new issue