(translator_with_random_auth_key, server, tmpdir)
| 270 | |
| 271 | @needs_mock_server |
| 272 | def test_usage_overrun(translator_with_random_auth_key, server, tmpdir): |
| 273 | character_limit = 20 |
| 274 | document_limit = 1 |
| 275 | server.init_character_limit(character_limit) |
| 276 | server.init_document_limit(document_limit) |
| 277 | |
| 278 | translator = translator_with_random_auth_key |
| 279 | usage = translator.get_usage() |
| 280 | assert usage.character.limit == character_limit |
| 281 | assert usage.document.limit == document_limit |
| 282 | assert "Characters: 0 of 20" in str(usage) |
| 283 | assert "Documents: 0 of 1" in str(usage) |
| 284 | |
| 285 | tmpdir = pathlib.Path(tmpdir) |
| 286 | input_path = tmpdir / "example_document.txt" |
| 287 | input_path.write_text("a" * character_limit) |
| 288 | output_path = tmpdir / "example_document_output.txt" |
| 289 | translator.translate_document_from_filepath( |
| 290 | input_path, output_path, target_lang="DE" |
| 291 | ) |
| 292 | |
| 293 | usage = translator.get_usage() |
| 294 | assert usage.any_limit_reached |
| 295 | assert usage.document.limit_reached |
| 296 | assert usage.character.limit_reached |
| 297 | assert not usage.team_document.limit_reached |
| 298 | # Test deprecated properties as well |
| 299 | assert usage.any_limit_exceeded |
| 300 | assert usage.document.limit_exceeded |
| 301 | assert usage.character.limit_exceeded |
| 302 | assert not usage.team_document.limit_exceeded |
| 303 | |
| 304 | with pytest.raises(deepl.exceptions.QuotaExceededException): |
| 305 | translator.translate_document_from_filepath( |
| 306 | input_path, output_path, target_lang="DE" |
| 307 | ) |
| 308 | |
| 309 | with pytest.raises(deepl.exceptions.QuotaExceededException): |
| 310 | translator.translate_text(example_text["EN"], target_lang="DE") |
| 311 | |
| 312 | |
| 313 | @needs_mock_server |
nothing calls this directly
no test coverage detected