Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 1 | # Copyright 2015 Red Hat, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from zuul import change_matcher as cm |
| 16 | from zuul import model |
| 17 | |
| 18 | from tests.base import BaseTestCase |
| 19 | |
| 20 | |
| 21 | class TestJob(BaseTestCase): |
| 22 | |
| 23 | @property |
| 24 | def job(self): |
| 25 | job = model.Job('job') |
| 26 | job.skip_if_matcher = cm.MatchAll([ |
| 27 | cm.ProjectMatcher('^project$'), |
| 28 | cm.MatchAllFiles([cm.FileMatcher('^docs/.*$')]), |
| 29 | ]) |
| 30 | return job |
| 31 | |
| 32 | def test_change_matches_returns_false_for_matched_skip_if(self): |
| 33 | change = model.Change('project') |
| 34 | change.files = ['docs/foo'] |
| 35 | self.assertFalse(self.job.changeMatches(change)) |
| 36 | |
| 37 | def test_change_matches_returns_true_for_unmatched_skip_if(self): |
| 38 | change = model.Change('project') |
| 39 | change.files = ['foo'] |
| 40 | self.assertTrue(self.job.changeMatches(change)) |
| 41 | |
| 42 | def test_copy_retains_skip_if(self): |
| 43 | job = model.Job('job') |
| 44 | job.copy(self.job) |
| 45 | self.assertTrue(job.skip_if_matcher) |
Maru Newby | 79427a4 | 2015-02-17 17:54:45 +0000 | [diff] [blame] | 46 | |
| 47 | def _assert_job_booleans_are_not_none(self, job): |
| 48 | self.assertIsNotNone(job.voting) |
| 49 | self.assertIsNotNone(job.hold_following_changes) |
| 50 | |
| 51 | def test_job_sets_defaults_for_boolean_attributes(self): |
| 52 | job = model.Job('job') |
| 53 | self._assert_job_booleans_are_not_none(job) |
| 54 | |
| 55 | def test_metajob_does_not_set_defaults_for_boolean_attributes(self): |
| 56 | job = model.Job('^job') |
| 57 | self.assertIsNone(job.voting) |
| 58 | self.assertIsNone(job.hold_following_changes) |
| 59 | |
| 60 | def test_metajob_copy_does_not_set_undefined_boolean_attributes(self): |
| 61 | job = model.Job('job') |
| 62 | metajob = model.Job('^job') |
| 63 | job.copy(metajob) |
| 64 | self._assert_job_booleans_are_not_none(job) |