Skip to content

Commit

Permalink
Merge 8610603 into 86a95af
Browse files Browse the repository at this point in the history
  • Loading branch information
chmeliik committed Apr 23, 2019
2 parents 86a95af + 8610603 commit 3172b6a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ if [[ $OS != "fedora" ]]; then
$RUN $PYTHON get-pip.py
fi

# "mock" koji-hub (just to prevent ImportError, actual mocking done in tests)
KOJIHUB_PATH='/usr/share/koji-hub'
$RUN mkdir -p "$KOJIHUB_PATH"
$RUN touch "$KOJIHUB_PATH/kojihub.py"

# Run tests
$RUN pytest -vv tests --cov koji_containerbuild
41 changes: 41 additions & 0 deletions tests/test_hub_containerbuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import koji
import pytest
from flexmock import flexmock

from koji_containerbuild.plugins import hub_containerbuild


@pytest.mark.parametrize('admin_perms', [True, False])
@pytest.mark.parametrize('priority', [1, 0, None, -1])
def test_priority_permissions(priority, admin_perms):
src, target = 'source', 'target'

task_opts = {}
if priority:
task_opts['priority'] = koji.PRIO_DEFAULT + priority

session = flexmock()
(session
.should_receive('hasPerm')
.with_args('admin')
.and_return(admin_perms))
hub_containerbuild.context = flexmock(session=session)

should_succeed = priority is None or priority >= 0 or admin_perms

kojihub = flexmock()
(kojihub
.should_receive('make_task')
.with_args('buildContainer', [src, target, {}],
channel='container', **task_opts)
.times(1 if should_succeed else 0))
hub_containerbuild.kojihub = kojihub

if should_succeed:
hub_containerbuild.buildContainer(src, target, priority=priority)
else:
with pytest.raises(koji.ActionNotAllowed) as exc_info:
hub_containerbuild.buildContainer(src, target, priority=priority)

e = exc_info.value
assert str(e) == 'only admins may create high-priority tasks'

0 comments on commit 3172b6a

Please sign in to comment.