Joshua Hesketh | e095c8c | 2014-01-16 19:19:34 +1100 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | # |
| 3 | # Copyright 2014 Rackspace Australia |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import testtools |
| 18 | |
| 19 | import fakes |
| 20 | |
| 21 | from turbo_hipster.lib import common |
| 22 | from turbo_hipster.lib import models |
| 23 | |
| 24 | |
| 25 | class TestTaskStep(testtools.TestCase): |
| 26 | def test_task_step_decorator(self): |
| 27 | class FakeTask(models.Task): |
Joshua Hesketh | 62721fb | 2014-12-02 13:22:10 +1100 | [diff] [blame] | 28 | def __init__(self, global_config, job_name, job_config): |
| 29 | super(FakeTask, self).__init__(global_config, job_name, |
| 30 | job_config) |
Joshua Hesketh | e095c8c | 2014-01-16 19:19:34 +1100 | [diff] [blame] | 31 | # Define the number of steps we will do to determine our |
| 32 | # progress. |
| 33 | self.total_steps = 2 |
| 34 | |
| 35 | @common.task_step |
| 36 | def do_something(self): |
| 37 | pass |
| 38 | |
| 39 | def non_step(self): |
| 40 | pass |
| 41 | |
| 42 | @common.task_step |
| 43 | def do_something_more(self): |
| 44 | pass |
| 45 | |
Joshua Hesketh | 62721fb | 2014-12-02 13:22:10 +1100 | [diff] [blame] | 46 | task = FakeTask({}, 'build:function', {}) |
Joshua Hesketh | e095c8c | 2014-01-16 19:19:34 +1100 | [diff] [blame] | 47 | task.job = fakes.FakeJob() |
| 48 | |
| 49 | self.assertEqual(0, task.current_step) |
| 50 | |
| 51 | task.do_something() |
| 52 | self.assertEqual(1, task.current_step) |
| 53 | |
| 54 | task.non_step() |
| 55 | self.assertEqual(1, task.current_step) |
| 56 | |
| 57 | task.do_something_more() |
| 58 | self.assertEqual(2, task.current_step) |