Skip to content

Commit 9d75cc0

Browse files
authored
fix state-dependent tests (#229)
1 parent 378fd0e commit 9d75cc0

File tree

3 files changed

+76
-41
lines changed

3 files changed

+76
-41
lines changed

tests/cmds/test_cases.py

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,54 @@
1818
ALL_EVENTS = """{
1919
"events": [
2020
{
21-
"eventId": "0_1d71796f-af5b-4231-9d8e-df6434da4663_984418168383179707_986472527798692818_971",
22-
"eventTimestamp": "2020-12-23T12:41:38.592Z"
21+
"eventId": "0_147e9445-2f30-4a91-8b2a-9455332e880a_973435567569502913_986467523038446097_163",
22+
"eventTimestamp": "2020-12-23T14:24:44.593Z",
23+
"exposure": [
24+
"OutsideTrustedDomains",
25+
"IsPublic"
26+
],
27+
"fileName": "example.docx",
28+
"filePath": "/Users/casey/Documents/"
2329
}
24-
]
30+
],
31+
"totalCount": 42
2532
}"""
2633
ALL_CASES = """{
2734
"cases": [
2835
{
29-
"number": 3,
30-
"name": "test@test.test",
31-
"updatedAt": "2021-01-24T11:00:04.217878Z",
32-
"subject": "942897"
36+
"assignee": 273411254592236320,
37+
"assigneeUsername": "test@example.com",
38+
"createdAt": "2020-10-27T15:16:05.369203Z",
39+
"createdByUserUid": 806150685834341100,
40+
"createdByUsername": "adrian@example.com",
41+
"lastModifiedByUserUid": 806150685834341100,
42+
"lastModifiedByUsername": "adrian@example.com",
43+
"name": "Sample case name",
44+
"number": 942897,
45+
"status": "OPEN",
46+
"subject": 421380797518239200,
47+
"subjectUsername": "casey@example.com",
48+
"updatedAt": "2021-01-24T11:00:04.217878Z"
3349
}
3450
],
35-
"totalCount": 31
51+
"totalCount": 42
3652
}"""
37-
CASE_DETAILS = '{"number": 3, "name": "test@test.test"}'
53+
CASE_DETAILS = """{
54+
"assignee": 273411254592236320,
55+
"assigneeUsername": "test-single@example.com",
56+
"createdAt": "2020-10-27T15:16:05.369203Z",
57+
"createdByUserUid": 806150685834341100,
58+
"createdByUsername": "adrian@example.com",
59+
"lastModifiedByUserUid": 806150685834341100,
60+
"lastModifiedByUsername": "adrian@example.com",
61+
"name": "Sample case name",
62+
"number": 123456,
63+
"status": "OPEN",
64+
"subject": 421380797518239200,
65+
"subjectUsername": "casey@example.com",
66+
"updatedAt": "2021-01-24T11:00:04.217878Z"
67+
}
68+
"""
3869
MISSING_ARGUMENT_ERROR = "Missing argument '{}'."
3970
MISSING_NAME = MISSING_ARGUMENT_ERROR.format("NAME")
4071
MISSING_CASE_NUMBER_ARG = MISSING_ARGUMENT_ERROR.format("CASE_NUMBER")
@@ -43,13 +74,6 @@
4374
MISSING_CASE_NUMBER_OPTION = MISSING_OPTION_ERROR.format("case-number")
4475

4576

46-
@pytest.fixture
47-
def error(mocker):
48-
error = mocker.Mock(spec=Exception)
49-
error.response = "error"
50-
return error
51-
52-
5377
@pytest.fixture
5478
def py42_response(mocker):
5579
return mocker.MagicMock(spec=Py42Response)
@@ -188,7 +212,6 @@ def gen():
188212

189213
cli_state.sdk.cases.get_all.return_value = gen()
190214
result = runner.invoke(cli, ["cases", "list"], obj=cli_state,)
191-
assert "test@test.test" in result.output
192215
assert "2021-01-24T11:00:04.217878Z" in result.output
193216
assert "942897" in result.output
194217

@@ -206,11 +229,16 @@ def test_show_with_include_file_events_calls_file_events_get_all_with_expected_p
206229
runner.invoke(
207230
cli, ["cases", "show", "1", "--include-file-events"], obj=cli_state,
208231
)
232+
cli_state.sdk.cases.get.assert_called_once_with(1)
209233
cli_state.sdk.cases.file_events.get_all.assert_called_once_with(1)
210234

211235

212-
def test_show_when_py42_raises_exception_prints_error_message(runner, cli_state, error):
213-
cli_state.sdk.cases.file_events.get_all.side_effect = Py42NotFoundError(error)
236+
def test_show_when_py42_raises_exception_prints_error_message(
237+
runner, cli_state, custom_error
238+
):
239+
cli_state.sdk.cases.file_events.get_all.side_effect = Py42NotFoundError(
240+
custom_error
241+
)
214242
result = runner.invoke(
215243
cli, ["cases", "show", "1", "--include-file-events"], obj=cli_state,
216244
)
@@ -222,21 +250,29 @@ def test_show_prints_expected_data(runner, cli_state, py42_response):
222250
py42_response.data = json.loads(CASE_DETAILS)
223251
cli_state.sdk.cases.get.return_value = py42_response
224252
result = runner.invoke(cli, ["cases", "show", "1"], obj=cli_state,)
225-
assert "test@test.test" in result.output
253+
assert "test-single@example.com" in result.output
254+
assert "2021-01-24T11:00:04.217878Z" in result.output
255+
assert "123456" in result.output
226256

227257

228258
def test_show_prints_expected_data_with_include_file_events_option(
229-
runner, cli_state, py42_response
259+
runner, cli_state, py42_response, mocker
230260
):
231261
py42_response.text = ALL_EVENTS
262+
get_case_response = mocker.MagicMock(spec=Py42Response)
263+
get_case_response.data = json.loads(CASE_DETAILS)
264+
cli_state.sdk.cases.get.return_value = get_case_response
232265
cli_state.sdk.cases.file_events.get_all.return_value = py42_response
233266
result = runner.invoke(
234267
cli, ["cases", "show", "1", "--include-file-events"], obj=cli_state,
235268
)
236269
assert (
237-
"0_1d71796f-af5b-4231-9d8e-df6434da4663_984418168383179707_986472527798692818_971"
270+
"0_147e9445-2f30-4a91-8b2a-9455332e880a_973435567569502913_986467523038446097_163"
238271
in result.output
239272
)
273+
assert "test-single@example.com" in result.output
274+
assert "2021-01-24T11:00:04.217878Z" in result.output
275+
assert "123456" in result.output
240276

241277

242278
def test_show_case_when_missing_case_number_prints_error(runner, cli_state):
@@ -273,9 +309,9 @@ def test_file_events_add_calls_add_event_with_expected_params(runner, cli_state)
273309

274310

275311
def test_file_events_add_when_py42_raises_exception_prints_error_message(
276-
runner, cli_state, error
312+
runner, cli_state, custom_error
277313
):
278-
cli_state.sdk.cases.file_events.add.side_effect = Py42BadRequestError(error)
314+
cli_state.sdk.cases.file_events.add.side_effect = Py42BadRequestError(custom_error)
279315
result = runner.invoke(
280316
cli,
281317
["cases", "file-events", "add", "--case-number", "1", "--event-id", "1"],
@@ -309,9 +345,9 @@ def test_file_events_remove_calls_delete_event_with_expected_params(runner, cli_
309345

310346

311347
def test_file_events_remove_when_py42_raises_exception_prints_error_message(
312-
runner, cli_state, error
348+
runner, cli_state, custom_error
313349
):
314-
cli_state.sdk.cases.file_events.delete.side_effect = Py42NotFoundError(error)
350+
cli_state.sdk.cases.file_events.delete.side_effect = Py42NotFoundError(custom_error)
315351
result = runner.invoke(
316352
cli,
317353
["cases", "file-events", "remove", "--case-number", "1", "--event-id", "1"],
@@ -346,10 +382,10 @@ def test_file_events_list_prints_expected_data(runner, cli_state):
346382
cli_state.sdk.cases.file_events.get_all.return_value = json.loads(ALL_EVENTS)
347383
result = runner.invoke(cli, ["cases", "file-events", "list", "1"], obj=cli_state,)
348384
assert (
349-
"0_1d71796f-af5b-4231-9d8e-df6434da4663_984418168383179707_986472527798692818_971"
385+
"0_147e9445-2f30-4a91-8b2a-9455332e880a_973435567569502913_986467523038446097_163"
350386
in result.output
351387
)
352-
assert "2020-12-23T12:41:38.592Z" in result.output
388+
assert "2020-12-23T14:24:44.593Z" in result.output
353389

354390

355391
def test_file_events_list_when_missing_case_number_prints_error(runner, cli_state):

tests/cmds/test_devices.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from py42.exceptions import Py42ForbiddenError
77
from py42.exceptions import Py42NotFoundError
88
from py42.response import Py42Response
9-
from requests import HTTPError
109
from requests import Response
1110

1211
from code42cli import PRODUCT_NAME
@@ -313,28 +312,28 @@ def reactivate_device_success(cli_state, empty_successful_response):
313312

314313

315314
@pytest.fixture
316-
def deactivate_device_not_found_failure(cli_state):
317-
cli_state.sdk.devices.deactivate.side_effect = Py42NotFoundError(HTTPError())
315+
def deactivate_device_not_found_failure(cli_state, custom_error):
316+
cli_state.sdk.devices.deactivate.side_effect = Py42NotFoundError(custom_error)
318317

319318

320319
@pytest.fixture
321-
def reactivate_device_not_found_failure(cli_state):
322-
cli_state.sdk.devices.reactivate.side_effect = Py42NotFoundError(HTTPError())
320+
def reactivate_device_not_found_failure(cli_state, custom_error):
321+
cli_state.sdk.devices.reactivate.side_effect = Py42NotFoundError(custom_error)
323322

324323

325324
@pytest.fixture
326-
def deactivate_device_in_legal_hold_failure(cli_state):
327-
cli_state.sdk.devices.deactivate.side_effect = Py42BadRequestError(HTTPError())
325+
def deactivate_device_in_legal_hold_failure(cli_state, custom_error):
326+
cli_state.sdk.devices.deactivate.side_effect = Py42BadRequestError(custom_error)
328327

329328

330329
@pytest.fixture
331-
def deactivate_device_not_allowed_failure(cli_state):
332-
cli_state.sdk.devices.deactivate.side_effect = Py42ForbiddenError(HTTPError())
330+
def deactivate_device_not_allowed_failure(cli_state, custom_error):
331+
cli_state.sdk.devices.deactivate.side_effect = Py42ForbiddenError(custom_error)
333332

334333

335334
@pytest.fixture
336-
def reactivate_device_not_allowed_failure(cli_state):
337-
cli_state.sdk.devices.reactivate.side_effect = Py42ForbiddenError(HTTPError())
335+
def reactivate_device_not_allowed_failure(cli_state, custom_error):
336+
cli_state.sdk.devices.reactivate.side_effect = Py42ForbiddenError(custom_error)
338337

339338

340339
@pytest.fixture

tests/cmds/test_legal_hold.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ def check_matter_accessible_success(cli_state, matter_response):
240240

241241

242242
@pytest.fixture
243-
def check_matter_accessible_failure(cli_state):
243+
def check_matter_accessible_failure(cli_state, custom_error):
244244
cli_state.sdk.legalhold.get_matter_by_uid.side_effect = Py42BadRequestError(
245-
HTTPError()
245+
custom_error
246246
)
247247

248248

0 commit comments

Comments
 (0)