Skip to content

Commit 0265be2

Browse files
committed
fix(lock): fix broken test
Signed-off-by: Chris Snow <[email protected]>
1 parent 7115fa6 commit 0265be2

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

hpecp/cli/lock.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def create(self, reason, timeout_secs=300):
7575
response = base.get_client().lock.create(reason, timeout_secs)
7676
if response is False:
7777
print(
78-
"Unabled to lock within '{}'".format(timeout_secs),
78+
"Unable to lock within '{}'".format(timeout_secs),
7979
file=sys.stderr,
8080
)
8181
else:
8282
# reponse contains lock ID
83-
print(response, file=sys.stderr)
83+
print(response, file=sys.stdout)
8484

8585
@base.intercept_exception
8686
def delete(

hpecp/lock.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def create(self, reason=None, timeout_secs=300):
6666
data=data,
6767
description="lock/set_lock",
6868
)
69-
id = CaseInsensitiveDict(response.headers)["Location"]
69+
lock_id = CaseInsensitiveDict(response.headers)["Location"]
7070

7171
if timeout_secs == 0:
72-
return id
72+
return lock_id
7373
else:
7474
try:
7575
polling.poll(
@@ -78,7 +78,7 @@ def create(self, reason=None, timeout_secs=300):
7878
poll_forever=False,
7979
timeout=timeout_secs,
8080
)
81-
return id
81+
return lock_id
8282
except polling.TimeoutException:
8383
return False
8484

tests/lock_test.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,25 @@ def test_delete_all_timeout(self, mock_get, mock_post, mock_delete):
204204

205205

206206
class TestCLICreate(BaseTestCase):
207+
def mocked_requests_get_locked(*args, **kwargs):
208+
if args[0] == "https://127.0.0.1:8080/api/v1/lock":
209+
return MockResponse(
210+
json_data={
211+
"_links": {"self": {"href": "/api/v1/lock"}},
212+
"locked": True,
213+
"_embedded": {
214+
"internal_locks": ["1"],
215+
"external_locks": [],
216+
},
217+
},
218+
status_code=200,
219+
headers=dict(),
220+
)
221+
raise RuntimeError("Unhandle GET request: " + args[0])
222+
207223
@patch("requests.post", side_effect=BaseTestCase.httpPostHandlers)
208-
def test_create(self, mock_post):
224+
@patch("requests.get", side_effect=mocked_requests_get_locked)
225+
def test_create(self, mock_post, mock_get):
209226

210227
try:
211228
hpecp = self.cli.CLI()
@@ -220,7 +237,11 @@ def test_create(self, mock_post):
220237
expected_stdout = "/test_location/1"
221238
expected_stderr = ""
222239

223-
self.assertEqual(stdout, expected_stdout)
240+
self.assertEqual(
241+
stdout,
242+
expected_stdout,
243+
"Expected: '{}' Actual: '{}'".format(expected_stdout, stdout),
244+
)
224245

225246
# coverage seems to populate standard error on PY3 (issues 93)
226247
if six.PY2:

0 commit comments

Comments
 (0)