|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 |
|
3 | 4 | from unittest import TestCase |
4 | 5 | from unittest.mock import patch |
5 | 6 |
|
6 | 7 | from rsconnect.exception import RSConnectException |
7 | | -from rsconnect.timeouts import get_timeout |
| 8 | +from rsconnect.timeouts import get_request_timeout, get_task_timeout |
8 | 9 |
|
9 | 10 |
|
10 | | -class GetTimeoutTestCase(TestCase): |
| 11 | +class GetRequestTimeoutTestCase(TestCase): |
11 | 12 | def test_get_default_timeout(self): |
12 | | - timeout = get_timeout() |
| 13 | + timeout = get_request_timeout() |
13 | 14 | self.assertEqual(300, timeout) |
14 | 15 |
|
15 | 16 | def test_get_valid_timeout_from_environment(self): |
16 | 17 | with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "24"}): |
17 | | - timeout = get_timeout() |
| 18 | + timeout = get_request_timeout() |
18 | 19 | self.assertEqual(24, timeout) |
19 | 20 |
|
20 | 21 | def test_get_zero_timeout_from_environment(self): |
21 | 22 | with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "0"}): |
22 | | - timeout = get_timeout() |
| 23 | + timeout = get_request_timeout() |
23 | 24 | self.assertEqual(0, timeout) |
24 | 25 |
|
25 | 26 | def test_get_invalid_timeout_from_environment(self): |
26 | 27 | with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "foobar"}): |
27 | 28 | with self.assertRaises(RSConnectException): |
28 | | - get_timeout() |
| 29 | + get_request_timeout() |
29 | 30 |
|
30 | 31 | def test_get_negative_timeout_from_environment(self): |
31 | 32 | with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "-24"}): |
32 | 33 | with self.assertRaises(RSConnectException): |
33 | | - get_timeout() |
| 34 | + get_request_timeout() |
| 35 | + |
| 36 | +class GetTaskTimeoutTestCase(TestCase): |
| 37 | + def test_get_default_timeout(self): |
| 38 | + timeout = get_task_timeout() |
| 39 | + self.assertEqual(sys.maxsize, timeout) |
| 40 | + |
| 41 | + def test_get_valid_timeout_from_environment(self): |
| 42 | + with patch.dict(os.environ, {"CONNECT_TASK_TIMEOUT": "24"}): |
| 43 | + timeout = get_task_timeout() |
| 44 | + self.assertEqual(24, timeout) |
| 45 | + |
| 46 | + def test_get_zero_timeout_from_environment(self): |
| 47 | + with patch.dict(os.environ, {"CONNECT_TASK_TIMEOUT": "0"}): |
| 48 | + with self.assertRaises(RSConnectException): |
| 49 | + get_task_timeout() |
| 50 | + |
| 51 | + def test_get_invalid_timeout_from_environment(self): |
| 52 | + with patch.dict(os.environ, {"CONNECT_TASK_TIMEOUT": "foobar"}): |
| 53 | + with self.assertRaises(RSConnectException): |
| 54 | + get_task_timeout() |
| 55 | + |
| 56 | + def test_get_negative_timeout_from_environment(self): |
| 57 | + with patch.dict(os.environ, {"CONNECT_TASK_TIMEOUT": "-24"}): |
| 58 | + with self.assertRaises(RSConnectException): |
| 59 | + get_task_timeout() |
0 commit comments