forked from mozilla-releng/pushsnapscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e1ff30
commit b7a79a1
Showing
4 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from scriptworker.exceptions import TaskVerificationError | ||
from scriptworker.utils import get_single_item_from_sequence | ||
|
||
SNAP_SCOPES_PREFIX = 'project:releng:snapcraft:firefox:' | ||
ALLOWED_CHANNELS = ('edge', 'candidate') | ||
|
||
|
||
def pluck_channel(task): | ||
scope = get_single_item_from_sequence( | ||
task['scopes'], | ||
lambda scope: scope.startswith(SNAP_SCOPES_PREFIX), | ||
ErrorClass=TaskVerificationError, | ||
no_item_error_message='No scope starts with {}'.format(SNAP_SCOPES_PREFIX), | ||
too_many_item_error_message='Too many scopes start with {}'.format(SNAP_SCOPES_PREFIX), | ||
) | ||
|
||
channel = scope[len(SNAP_SCOPES_PREFIX):] | ||
|
||
if channel not in ALLOWED_CHANNELS: | ||
raise TaskVerificationError( | ||
'Channel "{}" is not allowed. Allowed ones are: {}'.format(channel, ALLOWED_CHANNELS) | ||
) | ||
|
||
return channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
|
||
from scriptworker.exceptions import TaskVerificationError | ||
|
||
from pushsnapscript.task import pluck_channel | ||
|
||
|
||
@pytest.mark.parametrize('raises, scopes, expected', ( | ||
(False, ['project:releng:snapcraft:firefox:candidate'], 'candidate'), | ||
(False, ['project:releng:snapcraft:firefox:edge'], 'edge'), | ||
(False, ['project:releng:snapcraft:firefox:edge', 'some:other:scope'], 'edge'), | ||
(True, ['project:releng:snapcraft:firefox:edge', 'project:releng:snapcraft:firefox:edge'], None), | ||
(True, ['project:releng:snapcraft:firefox:edge', 'project:releng:snapcraft:firefox:candidate'], None), | ||
(True, ['project:releng:snapcraft:firefox:stable'], None), | ||
(True, ['project:releng:snapcraft:firefox:beta'], None), | ||
)) | ||
def test_pluck_channel(raises, scopes, expected): | ||
task = {'scopes': scopes} | ||
if raises: | ||
with pytest.raises(TaskVerificationError): | ||
pluck_channel(task) | ||
else: | ||
assert pluck_channel(task) == expected |