-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_socketcli.py
More file actions
36 lines (24 loc) · 974 Bytes
/
test_socketcli.py
File metadata and controls
36 lines (24 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import pytest
from socketdev.exceptions import APIFailure
from socketsecurity import socketcli
def test_cli_honors_disable_blocking_for_api_failures(monkeypatch):
def fail_main_code():
raise APIFailure("upstream request timeout")
monkeypatch.setattr(socketcli, "main_code", fail_main_code)
monkeypatch.setattr(
sys,
"argv",
["socketcli", "--api-token", "test", "--disable-blocking"],
)
with pytest.raises(SystemExit) as exc_info:
socketcli.cli()
assert exc_info.value.code == 0
def test_cli_returns_error_for_api_failures_without_disable_blocking(monkeypatch):
def fail_main_code():
raise APIFailure("upstream request timeout")
monkeypatch.setattr(socketcli, "main_code", fail_main_code)
monkeypatch.setattr(sys, "argv", ["socketcli", "--api-token", "test"])
with pytest.raises(SystemExit) as exc_info:
socketcli.cli()
assert exc_info.value.code == 3