blob: 493cc8e68700fcfd8391955397fbc44407eb6231 [file] [log] [blame]
Joshua Heskethe095c8c2014-01-16 19:19:34 +11001#!/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
17import testtools
18
19import fakes
20
21from turbo_hipster.lib import common
22from turbo_hipster.lib import models
23
24
25class TestTaskStep(testtools.TestCase):
26 def test_task_step_decorator(self):
27 class FakeTask(models.Task):
Joshua Hesketh62721fb2014-12-02 13:22:10 +110028 def __init__(self, global_config, job_name, job_config):
29 super(FakeTask, self).__init__(global_config, job_name,
30 job_config)
Joshua Heskethe095c8c2014-01-16 19:19:34 +110031 # 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 Hesketh62721fb2014-12-02 13:22:10 +110046 task = FakeTask({}, 'build:function', {})
Joshua Heskethe095c8c2014-01-16 19:19:34 +110047 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)