| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import testtools |
| 16 |
|
| 17 |
|
| 18 |
class BaseController(testtools.TestCase): |
| 19 |
def __init__(self, api, schema_api, controller_class): |
| 20 |
self.controller = controller_class(api, schema_api) |
| 21 |
|
| 22 |
def _assertRequestId(self, obj): |
| 23 |
self.assertIsNotNone(getattr(obj, 'request_ids', None)) |
| 24 |
self.assertEqual(['req-1234'], obj.request_ids) |
| 25 |
|
| 26 |
def list(self, *args, **kwargs): |
| 27 |
gen_obj = self.controller.list(*args, **kwargs) |
| 28 |
|
| 29 |
|
| 30 |
resources = list(gen_obj) |
| 31 |
if len(resources) > 0: |
| 32 |
self._assertRequestId(gen_obj) |
| 33 |
else: |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
self.assertEqual([], gen_obj.request_ids) |
| 38 |
|
| 39 |
return resources |
| 40 |
|
| 41 |
def get_associated_image_tasks(self, *args, **kwargs): |
| 42 |
resource = self.controller.get_associated_image_tasks( |
| 43 |
*args, **kwargs) |
| 44 |
|
| 45 |
self._assertRequestId(resource) |
| 46 |
return resource |
| 47 |
|
| 48 |
def get(self, *args, **kwargs): |
| 49 |
resource = self.controller.get(*args, **kwargs) |
| 50 |
|
| 51 |
self._assertRequestId(resource) |
| 52 |
return resource |
| 53 |
|
| 54 |
def create(self, *args, **kwargs): |
| 55 |
resource = self.controller.create(*args, **kwargs) |
| 56 |
self._assertRequestId(resource) |
| 57 |
return resource |
| 58 |
|
| 59 |
def create_multiple(self, *args, **kwargs): |
| 60 |
tags = self.controller.create_multiple(*args, **kwargs) |
| 61 |
actual = [tag.name for tag in tags] |
| 62 |
self._assertRequestId(tags) |
| 63 |
return actual |
| 64 |
|
| 65 |
def update(self, *args, **properties): |
| 66 |
resource = self.controller.update(*args, **properties) |
| 67 |
self._assertRequestId(resource) |
| 68 |
return resource |
| 69 |
|
| 70 |
def delete(self, *args): |
| 71 |
resp = self.controller.delete(*args) |
| 72 |
self._assertRequestId(resp) |
| 73 |
|
| 74 |
def delete_all(self, *args): |
| 75 |
resp = self.controller.delete_all(*args) |
| 76 |
self._assertRequestId(resp) |
| 77 |
|
| 78 |
def deactivate(self, *args): |
| 79 |
resp = self.controller.deactivate(*args) |
| 80 |
self._assertRequestId(resp) |
| 81 |
|
| 82 |
def reactivate(self, *args): |
| 83 |
resp = self.controller.reactivate(*args) |
| 84 |
self._assertRequestId(resp) |
| 85 |
|
| 86 |
def upload(self, *args, **kwargs): |
| 87 |
resp = self.controller.upload(*args, **kwargs) |
| 88 |
self._assertRequestId(resp) |
| 89 |
|
| 90 |
def stage(self, *args, **kwargs): |
| 91 |
resp = self.controller.stage(*args, **kwargs) |
| 92 |
self._assertRequestId(resp) |
| 93 |
|
| 94 |
def data(self, *args, **kwargs): |
| 95 |
body = self.controller.data(*args, **kwargs) |
| 96 |
self._assertRequestId(body) |
| 97 |
return body |
| 98 |
|
| 99 |
def delete_locations(self, *args): |
| 100 |
resp = self.controller.delete_locations(*args) |
| 101 |
self._assertRequestId(resp) |
| 102 |
|
| 103 |
def add_location(self, *args, **kwargs): |
| 104 |
resp = self.controller.add_location(*args, **kwargs) |
| 105 |
self._assertRequestId(resp) |
| 106 |
|
| 107 |
def update_location(self, *args, **kwargs): |
| 108 |
resp = self.controller.update_location(*args, **kwargs) |
| 109 |
self._assertRequestId(resp) |
| 110 |
|
| 111 |
def associate(self, *args, **kwargs): |
| 112 |
resource_types = self.controller.associate(*args, **kwargs) |
| 113 |
self._assertRequestId(resource_types) |
| 114 |
return resource_types |
| 115 |
|
| 116 |
def deassociate(self, *args): |
| 117 |
resp = self.controller.deassociate(*args) |
| 118 |
self._assertRequestId(resp) |
| 119 |
|
| 120 |
def image_import(self, *args, **kwargs): |
| 121 |
resp = self.controller.image_import(*args, **kwargs) |
| 122 |
self._assertRequestId(resp) |
| 123 |
|
| 124 |
def add_image_location(self, *args): |
| 125 |
resp = self.controller.add_image_location(*args) |
| 126 |
self._assertRequestId(resp) |
| 127 |
|
| 128 |
def get_image_locations(self, *args): |
| 129 |
resource = self.controller.get_image_locations(*args) |
| 130 |
self._assertRequestId(resource) |
| 131 |
return resource |
| 132 |
|
| 133 |
|
| 134 |
class BaseResourceTypeController(BaseController): |
| 135 |
def __init__(self, api, schema_api, controller_class): |
| 136 |
super(BaseResourceTypeController, self).__init__(api, schema_api, |
| 137 |
controller_class) |
| 138 |
|
| 139 |
def get(self, *args, **kwargs): |
| 140 |
resource_types = self.controller.get(*args) |
| 141 |
names = [rt.name for rt in resource_types] |
| 142 |
self._assertRequestId(resource_types) |
| 143 |
return names |