|
1 | 1 | from functools import partial |
2 | | -from typing import Any, List |
| 2 | +from typing import Any, List, Union |
| 3 | +from unittest.mock import patch |
3 | 4 |
|
4 | 5 | from pytest import fixture, mark, param, raises |
5 | 6 | from supertokens_python import ( |
@@ -450,3 +451,50 @@ async def test_route_handlers_callable(handler_response: Any, expectation: Any): |
450 | 451 | ) |
451 | 452 |
|
452 | 453 | assert res == expected_output |
| 454 | + |
| 455 | + |
| 456 | +@mark.parametrize( |
| 457 | + ("sdk_version", "compatible_versions", "expectation"), |
| 458 | + [ |
| 459 | + param( |
| 460 | + "1.5.0", |
| 461 | + ">=1.0.0,<2.0.0", |
| 462 | + outputs(None), |
| 463 | + id="[Valid][1.5.0][>=1.0.0,<2.0.0] as string", |
| 464 | + ), |
| 465 | + param( |
| 466 | + "1.5.0", |
| 467 | + [">=1.0.0", "<2.0.0"], |
| 468 | + outputs(None), |
| 469 | + id="[Valid][1.5.0][>=1.0.0,<2.0.0] as list of strings", |
| 470 | + ), |
| 471 | + param( |
| 472 | + "2.0.0", |
| 473 | + [">=1.0.0,<2.0.0"], |
| 474 | + raises(Exception, match="Incompatible SDK version for plugin plugin1."), |
| 475 | + id="[Invalid][2.0.0][>=1.0.0,<2.0.0]", |
| 476 | + ), |
| 477 | + ], |
| 478 | +) |
| 479 | +def test_versions( |
| 480 | + sdk_version: str, |
| 481 | + compatible_versions: Union[str, List[str]], |
| 482 | + expectation: Any, |
| 483 | +): |
| 484 | + plugin = plugin_factory( |
| 485 | + "plugin1", |
| 486 | + override_functions=False, |
| 487 | + override_apis=False, |
| 488 | + compatible_sdk_versions=compatible_versions, |
| 489 | + ) |
| 490 | + |
| 491 | + with patch("supertokens_python.plugins.VERSION", sdk_version): |
| 492 | + with expectation as _: |
| 493 | + partial_init( |
| 494 | + recipe_list=[ |
| 495 | + recipe_factory(override_functions=False, override_apis=False), |
| 496 | + ], |
| 497 | + experimental=SupertokensExperimentalConfig( |
| 498 | + plugins=[plugin], |
| 499 | + ), |
| 500 | + ) |
0 commit comments