Revision 70b0d2a2
b/test/ganeti.rapi.client_unittest.py | ||
---|---|---|
30 | 30 |
from ganeti import constants |
31 | 31 |
from ganeti import http |
32 | 32 |
from ganeti import serializer |
33 |
from ganeti import utils |
|
33 | 34 |
|
34 | 35 |
from ganeti.rapi import connector |
35 | 36 |
from ganeti.rapi import rlib2 |
... | ... | |
40 | 41 |
|
41 | 42 |
_URI_RE = re.compile(r"https://(?P<host>.*):(?P<port>\d+)(?P<path>/.*)") |
42 | 43 |
|
44 |
# List of resource handlers which aren't used by the RAPI client |
|
45 |
_KNOWN_UNUSED = set([ |
|
46 |
connector.R_root, |
|
47 |
connector.R_2, |
|
48 |
]) |
|
49 |
|
|
50 |
# Global variable for collecting used handlers |
|
51 |
_used_handlers = None |
|
52 |
|
|
43 | 53 |
|
44 | 54 |
def _GetPathFromUri(uri): |
45 | 55 |
"""Gets the path and query from a URI. |
... | ... | |
107 | 117 |
self._last_req_data = request_body |
108 | 118 |
|
109 | 119 |
try: |
110 |
HandlerClass, items, args = self._mapper.getController(path) |
|
111 |
self._last_handler = HandlerClass(items, args, None) |
|
120 |
(handler_cls, items, args) = self._mapper.getController(path) |
|
121 |
|
|
122 |
# Record handler as used |
|
123 |
_used_handlers.add(handler_cls) |
|
124 |
|
|
125 |
self._last_handler = handler_cls(items, args, None) |
|
112 | 126 |
if not hasattr(self._last_handler, method.upper()): |
113 | 127 |
raise http.HttpNotImplemented(message="Method not implemented") |
114 | 128 |
|
... | ... | |
1130 | 1144 |
self.assertEqual(self.rapi.CountPending(), 0) |
1131 | 1145 |
|
1132 | 1146 |
|
1147 |
class RapiTestRunner(unittest.TextTestRunner): |
|
1148 |
def run(self, *args): |
|
1149 |
global _used_handlers |
|
1150 |
assert _used_handlers is None |
|
1151 |
|
|
1152 |
_used_handlers = set() |
|
1153 |
try: |
|
1154 |
# Run actual tests |
|
1155 |
result = unittest.TextTestRunner.run(self, *args) |
|
1156 |
|
|
1157 |
diff = (set(connector.CONNECTOR.values()) - _used_handlers - |
|
1158 |
_KNOWN_UNUSED) |
|
1159 |
if diff: |
|
1160 |
raise AssertionError("The following RAPI resources were not used by the" |
|
1161 |
" RAPI client: %r" % utils.CommaJoin(diff)) |
|
1162 |
finally: |
|
1163 |
# Reset global variable |
|
1164 |
_used_handlers = None |
|
1165 |
|
|
1166 |
return result |
|
1167 |
|
|
1168 |
|
|
1133 | 1169 |
if __name__ == '__main__': |
1134 |
client.UsesRapiClient(testutils.GanetiTestProgram)() |
|
1170 |
client.UsesRapiClient(testutils.GanetiTestProgram)(testRunner=RapiTestRunner) |
Also available in: Unified diff