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 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 15 | from zuul import model |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 16 | from zuul import configloader |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 17 | |
| 18 | from tests.base import BaseTestCase |
| 19 | |
| 20 | |
| 21 | class TestJob(BaseTestCase): |
| 22 | |
| 23 | @property |
| 24 | def job(self): |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 25 | layout = model.Layout() |
| 26 | job = configloader.JobParser.fromYaml(layout, { |
| 27 | 'name': 'job', |
| 28 | 'irrelevant-files': [ |
| 29 | '^docs/.*$' |
| 30 | ]}) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | return job |
| 32 | |
| 33 | def test_change_matches_returns_false_for_matched_skip_if(self): |
| 34 | change = model.Change('project') |
| 35 | change.files = ['docs/foo'] |
| 36 | self.assertFalse(self.job.changeMatches(change)) |
| 37 | |
| 38 | def test_change_matches_returns_true_for_unmatched_skip_if(self): |
| 39 | change = model.Change('project') |
| 40 | change.files = ['foo'] |
| 41 | self.assertTrue(self.job.changeMatches(change)) |
| 42 | |
Maru Newby | 79427a4 | 2015-02-17 17:54:45 +0000 | [diff] [blame] | 43 | def test_job_sets_defaults_for_boolean_attributes(self): |
James E. Blair | 8300578 | 2015-12-11 14:46:03 -0800 | [diff] [blame] | 44 | self.assertIsNotNone(self.job.voting) |
| 45 | |
| 46 | def test_job_inheritance(self): |
| 47 | layout = model.Layout() |
| 48 | base = configloader.JobParser.fromYaml(layout, { |
| 49 | 'name': 'base', |
| 50 | 'timeout': 30, |
| 51 | }) |
| 52 | layout.addJob(base) |
| 53 | python27 = configloader.JobParser.fromYaml(layout, { |
| 54 | 'name': 'python27', |
| 55 | 'parent': 'base', |
| 56 | 'timeout': 40, |
| 57 | }) |
| 58 | layout.addJob(python27) |
| 59 | python27diablo = configloader.JobParser.fromYaml(layout, { |
| 60 | 'name': 'python27', |
| 61 | 'branches': [ |
| 62 | 'stable/diablo' |
| 63 | ], |
| 64 | 'timeout': 50, |
| 65 | }) |
| 66 | layout.addJob(python27diablo) |
| 67 | |
| 68 | pipeline = model.Pipeline('gate', layout) |
| 69 | layout.addPipeline(pipeline) |
| 70 | queue = model.ChangeQueue(pipeline) |
| 71 | |
| 72 | project = model.Project('project') |
| 73 | tree = pipeline.addProject(project) |
| 74 | tree.addJob(layout.getJob('python27')) |
| 75 | |
| 76 | change = model.Change(project) |
| 77 | change.branch = 'master' |
| 78 | item = queue.enqueueChange(change) |
| 79 | |
| 80 | self.assertTrue(base.changeMatches(change)) |
| 81 | self.assertTrue(python27.changeMatches(change)) |
| 82 | self.assertFalse(python27diablo.changeMatches(change)) |
| 83 | |
| 84 | item.freezeJobTree() |
| 85 | self.assertEqual(len(item.getJobs()), 1) |
| 86 | job = item.getJobs()[0] |
| 87 | self.assertEqual(job.name, 'python27') |
| 88 | self.assertEqual(job.timeout, 40) |
| 89 | |
| 90 | change.branch = 'stable/diablo' |
| 91 | |
| 92 | self.assertTrue(base.changeMatches(change)) |
| 93 | self.assertTrue(python27.changeMatches(change)) |
| 94 | self.assertTrue(python27diablo.changeMatches(change)) |
| 95 | |
| 96 | item.freezeJobTree() |
| 97 | self.assertEqual(len(item.getJobs()), 1) |
| 98 | job = item.getJobs()[0] |
| 99 | self.assertEqual(job.name, 'python27') |
| 100 | self.assertEqual(job.timeout, 50) |