Skip to content

Commit

Permalink
Merge pull request #589 from russellballestrini/fix-566
Browse files Browse the repository at this point in the history
Fixes 566
  • Loading branch information
russellballestrini committed Apr 25, 2018
2 parents 91a571d + f843f34 commit 414f623
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
27 changes: 24 additions & 3 deletions stacker/status.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import operator


class Status(object):
def __init__(self, name, code, reason=None):
self.name = name
self.code = code
self.reason = reason or getattr(self, "reason", None)

def __cmp__(self, other):
def _comparison(self, operator, other):
if hasattr(other, "code"):
return cmp(self.code, other.code)
return False
return operator(self.code, other.code)
return NotImplemented

def __eq__(self, other):
return self._comparison(operator.eq, other)

def __ne__(self, other):
return self._comparison(operator.ne, other)

def __lt__(self, other):
return self._comparison(operator.lt, other)

def __gt__(self, other):
return self._comparison(operator.gt, other)

def __le__(self, other):
return self._comparison(operator.le, other)

def __ge__(self, other):
return self._comparison(operator.ge, other)


class PendingStatus(Status):
Expand Down
20 changes: 12 additions & 8 deletions stacker/tests/actions/test_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,24 @@ def get_stack(stack_name):
# simulate stack doesn't exist and we haven't submitted anything for
# deletion
mock_provider.get_stack.side_effect = StackDoesNotExist("mock")
status = step.run()
self.assertEqual(status, SKIPPED)

step.run()
self.assertEqual(step.status, SKIPPED)

# simulate stack getting successfully deleted
mock_provider.get_stack.side_effect = get_stack
mock_provider.is_stack_destroyed.return_value = False
mock_provider.is_stack_in_progress.return_value = False
status = step._run_once()
self.assertEqual(status, SUBMITTED)

step._run_once()
self.assertEqual(step.status, SUBMITTED)
mock_provider.is_stack_destroyed.return_value = False
mock_provider.is_stack_in_progress.return_value = True
status = step._run_once()
self.assertEqual(status, SUBMITTED)

step._run_once()
self.assertEqual(step.status, SUBMITTED)
mock_provider.is_stack_destroyed.return_value = True
mock_provider.is_stack_in_progress.return_value = False
status = step._run_once()
self.assertEqual(status, COMPLETE)

step._run_once()
self.assertEqual(step.status, COMPLETE)
10 changes: 10 additions & 0 deletions stacker/tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PlanFailed,
)
from stacker.status import (
SUBMITTED,
COMPLETE,
SKIPPED,
FAILED,
Expand All @@ -44,13 +45,22 @@ def setUp(self):
def test_status(self):
self.assertFalse(self.step.submitted)
self.assertFalse(self.step.completed)

self.step.submit()
self.assertEqual(self.step.status, SUBMITTED)
self.assertTrue(self.step.submitted)
self.assertFalse(self.step.completed)

self.step.complete()
self.assertEqual(self.step.status, COMPLETE)
self.assertNotEqual(self.step.status, SUBMITTED)
self.assertTrue(self.step.submitted)
self.assertTrue(self.step.completed)

self.assertNotEqual(self.step.status, True)
self.assertNotEqual(self.step.status, False)
self.assertNotEqual(self.step.status, 'banana')


class TestPlan(unittest.TestCase):

Expand Down

0 comments on commit 414f623

Please sign in to comment.