|
1 | 1 | from datetime import datetime |
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | import gopay |
4 | 5 | from gopay.enums import Language, TokenScope |
5 | 6 | from gopay.http import AccessToken, Request, Response |
| 7 | +from gopay.models import DEFAULT_TIMEOUT |
6 | 8 | from gopay.payments import Payments |
7 | 9 | from gopay.services import AbstractCache |
8 | 10 |
|
@@ -84,3 +86,81 @@ def test_with_services( |
84 | 86 |
|
85 | 87 | def test_embed_url(self, payments: Payments, gateway_url: str): |
86 | 88 | assert payments.get_embedjs_url == gateway_url[:-4] + "/gp-gw/js/embed.js" |
| 89 | + |
| 90 | + def test_default_timeout( |
| 91 | + self, client_id: str, client_secret: str, goid: str, gateway_url: str |
| 92 | + ): |
| 93 | + """When no timeout is specified, the default value from DEFAULT_TIMEOUT is used.""" |
| 94 | + payments = gopay.payments( |
| 95 | + { |
| 96 | + "client_id": client_id, |
| 97 | + "client_secret": client_secret, |
| 98 | + "goid": goid, |
| 99 | + "gateway_url": gateway_url, |
| 100 | + } |
| 101 | + ) |
| 102 | + assert payments.gopay.api_client.timeout == DEFAULT_TIMEOUT |
| 103 | + |
| 104 | + def test_custom_timeout( |
| 105 | + self, client_id: str, client_secret: str, goid: str, gateway_url: str |
| 106 | + ): |
| 107 | + """Custom timeout specified in config is correctly propagated to ApiClient.""" |
| 108 | + custom_timeout = 60 |
| 109 | + payments = gopay.payments( |
| 110 | + { |
| 111 | + "client_id": client_id, |
| 112 | + "client_secret": client_secret, |
| 113 | + "goid": goid, |
| 114 | + "gateway_url": gateway_url, |
| 115 | + "timeout": custom_timeout, |
| 116 | + } |
| 117 | + ) |
| 118 | + assert payments.gopay.api_client.timeout == custom_timeout |
| 119 | + |
| 120 | + def test_timeout_is_passed_to_full_config( |
| 121 | + self, client_id: str, client_secret: str, goid: str, gateway_url: str |
| 122 | + ): |
| 123 | + """Timeout in full config (with all optional fields) is correctly propagated.""" |
| 124 | + payments = gopay.payments( |
| 125 | + { |
| 126 | + "client_id": client_id, |
| 127 | + "client_secret": client_secret, |
| 128 | + "goid": goid, |
| 129 | + "gateway_url": gateway_url, |
| 130 | + "scope": TokenScope.ALL, |
| 131 | + "language": Language.CZECH, |
| 132 | + "timeout": 3600, |
| 133 | + } |
| 134 | + ) |
| 135 | + assert payments.gopay.api_client.timeout == 3600 |
| 136 | + |
| 137 | + def test_invalid_timeout_zero( |
| 138 | + self, client_id: str, client_secret: str, goid: str, gateway_url: str |
| 139 | + ): |
| 140 | + """Timeout of 0 is rejected by Pydantic validation (must be > 0).""" |
| 141 | + with pytest.raises(Exception): |
| 142 | + gopay.payments( |
| 143 | + { |
| 144 | + "client_id": client_id, |
| 145 | + "client_secret": client_secret, |
| 146 | + "goid": goid, |
| 147 | + "gateway_url": gateway_url, |
| 148 | + "timeout": 0, |
| 149 | + } |
| 150 | + ) |
| 151 | + |
| 152 | + def test_invalid_timeout_negative( |
| 153 | + self, client_id: str, client_secret: str, goid: str, gateway_url: str |
| 154 | + ): |
| 155 | + """Negative timeout is rejected by Pydantic validation (must be > 0).""" |
| 156 | + with pytest.raises(Exception): |
| 157 | + gopay.payments( |
| 158 | + { |
| 159 | + "client_id": client_id, |
| 160 | + "client_secret": client_secret, |
| 161 | + "goid": goid, |
| 162 | + "gateway_url": gateway_url, |
| 163 | + "timeout": -10, |
| 164 | + } |
| 165 | + ) |
| 166 | + |
0 commit comments