| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
import testtools |
| 15 |
|
| 16 |
from heatclient.tests.unit import fakes |
| 17 |
from heatclient.v1 import actions |
| 18 |
|
| 19 |
|
| 20 |
class ActionManagerTest(testtools.TestCase): |
| 21 |
|
| 22 |
def setUp(self): |
| 23 |
super().setUp() |
| 24 |
|
| 25 |
def _base_test(self, expect_args, expect_kwargs): |
| 26 |
|
| 27 |
class FakeAPI: |
| 28 |
"""Fake API and ensure request url is correct.""" |
| 29 |
|
| 30 |
def json_request(self, *args, **kwargs): |
| 31 |
assert expect_args == args |
| 32 |
assert expect_kwargs['data'] == kwargs['data'] |
| 33 |
return fakes.FakeHTTPResponse( |
| 34 |
'200', |
| 35 |
'', |
| 36 |
{'content-type': 'application/json'}, |
| 37 |
{}), {} |
| 38 |
|
| 39 |
def raw_request(self, *args, **kwargs): |
| 40 |
assert expect_args == args |
| 41 |
return fakes.FakeHTTPResponse( |
| 42 |
'200', |
| 43 |
'', |
| 44 |
{}, |
| 45 |
{}) |
| 46 |
|
| 47 |
def head(self, url, **kwargs): |
| 48 |
resp, body = self.json_request("HEAD", url, **kwargs) |
| 49 |
return resp |
| 50 |
|
| 51 |
def get(self, url, **kwargs): |
| 52 |
resp, body = self.json_request("GET", url, **kwargs) |
| 53 |
return resp |
| 54 |
|
| 55 |
def post(self, url, **kwargs): |
| 56 |
resp, body = self.json_request("POST", url, **kwargs) |
| 57 |
return resp |
| 58 |
|
| 59 |
def put(self, url, **kwargs): |
| 60 |
resp, body = self.json_request("PUT", url, **kwargs) |
| 61 |
return resp |
| 62 |
|
| 63 |
def delete(self, url, **kwargs): |
| 64 |
resp, body = self.raw_request("DELETE", url, **kwargs) |
| 65 |
return resp |
| 66 |
|
| 67 |
def patch(self, url, **kwargs): |
| 68 |
resp, body = self.json_request("PATCH", url, **kwargs) |
| 69 |
return resp |
| 70 |
|
| 71 |
manager = actions.ActionManager(FakeAPI()) |
| 72 |
return manager |
| 73 |
|
| 74 |
def test_suspend(self): |
| 75 |
fields = {'stack_id': 'teststack%2Fabcd1234'} |
| 76 |
expect_args = ('POST', |
| 77 |
'/stacks/teststack%2Fabcd1234/actions') |
| 78 |
expect_kwargs = {'data': {'suspend': None}} |
| 79 |
|
| 80 |
manager = self._base_test(expect_args, expect_kwargs) |
| 81 |
manager.suspend(**fields) |
| 82 |
|
| 83 |
def test_resume(self): |
| 84 |
fields = {'stack_id': 'teststack%2Fabcd1234'} |
| 85 |
expect_args = ('POST', |
| 86 |
'/stacks/teststack%2Fabcd1234/actions') |
| 87 |
expect_kwargs = {'data': {'resume': None}} |
| 88 |
|
| 89 |
manager = self._base_test(expect_args, expect_kwargs) |
| 90 |
manager.resume(**fields) |
| 91 |
|
| 92 |
def test_cancel_update(self): |
| 93 |
fields = {'stack_id': 'teststack%2Fabcd1234'} |
| 94 |
expect_args = ('POST', |
| 95 |
'/stacks/teststack%2Fabcd1234/actions') |
| 96 |
expect_kwargs = {'data': {'cancel_update': None}} |
| 97 |
|
| 98 |
manager = self._base_test(expect_args, expect_kwargs) |
| 99 |
manager.cancel_update(**fields) |
| 100 |
|
| 101 |
def test_cancel_without_rollback(self): |
| 102 |
fields = {'stack_id': 'teststack%2Fabcd1234'} |
| 103 |
expect_args = ('POST', |
| 104 |
'/stacks/teststack%2Fabcd1234/actions') |
| 105 |
expect_kwargs = {'data': {'cancel_without_rollback': None}} |
| 106 |
|
| 107 |
manager = self._base_test(expect_args, expect_kwargs) |
| 108 |
manager.cancel_without_rollback(**fields) |
| 109 |
|
| 110 |
def test_check(self): |
| 111 |
fields = {'stack_id': 'teststack%2Fabcd1234'} |
| 112 |
expect_args = ('POST', |
| 113 |
'/stacks/teststack%2Fabcd1234/actions') |
| 114 |
expect_kwargs = {'data': {'check': None}} |
| 115 |
|
| 116 |
manager = self._base_test(expect_args, expect_kwargs) |
| 117 |
manager.check(**fields) |