|
| 1 | +from unittest.mock import patch |
| 2 | +from kwtsms import KwtSMS |
| 3 | + |
| 4 | +def _client(**kwargs) -> KwtSMS: |
| 5 | + defaults = dict(username="python_username", password="python_password", |
| 6 | + sender_id="TEST", log_file="") |
| 7 | + defaults.update(kwargs) |
| 8 | + return KwtSMS(**defaults) |
| 9 | + |
| 10 | +OK_RESPONSE = { |
| 11 | + "result": "OK", |
| 12 | + "msg-id": "abc123", |
| 13 | + "status": "DELIVERED", |
| 14 | + "delivered-at": 1700000000, |
| 15 | +} |
| 16 | + |
| 17 | +ERR020_RESPONSE = { |
| 18 | + "result": "ERROR", |
| 19 | + "code": "ERR020", |
| 20 | + "description": "Message ID does not exist.", |
| 21 | +} |
| 22 | + |
| 23 | +class TestStatus: |
| 24 | + def test_status_ok_returns_dict_with_result_ok(self): |
| 25 | + with patch("kwtsms._core._request", return_value=OK_RESPONSE): |
| 26 | + result = _client().status("abc123") |
| 27 | + assert result["result"] == "OK" |
| 28 | + assert result["msg-id"] == "abc123" |
| 29 | + assert result["status"] == "DELIVERED" |
| 30 | + |
| 31 | + def test_status_error_has_action(self): |
| 32 | + with patch("kwtsms._core._request", return_value=ERR020_RESPONSE): |
| 33 | + result = _client().status("bad-id") |
| 34 | + assert result["result"] == "ERROR" |
| 35 | + assert "action" in result |
| 36 | + |
| 37 | + def test_status_network_error_returns_dict(self): |
| 38 | + with patch("kwtsms._core._request", side_effect=RuntimeError("Timeout")): |
| 39 | + result = _client().status("abc123") |
| 40 | + assert result["result"] == "ERROR" |
| 41 | + assert result["code"] == "NETWORK" |
0 commit comments