-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change pickle default version to Python default instead of Highest ve…
…rsion
- Loading branch information
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pickle | ||
import sys | ||
|
||
import pytest | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from django_redis.serializers.pickle import PickleSerializer | ||
|
||
|
||
class TestPickleSerializer: | ||
@pytest.mark.skipif( | ||
sys.version_info < (3, 8), | ||
reason="Protocol 5 was added as highest from python version 3.8", | ||
) | ||
def test_using_negative_protocol_value(self): | ||
serializer_p5 = PickleSerializer({"PICKLE_VERSION": pickle.HIGHEST_PROTOCOL}) | ||
p5_data = serializer_p5.dumps({"key": "value"}) | ||
|
||
serializer_test = PickleSerializer({"PICKLE_VERSION": -1}) | ||
test_data = serializer_test.dumps({"key": "value"}) | ||
assert p5_data == test_data | ||
|
||
def test_invalid_pickle_version_provided(self): | ||
with pytest.raises( | ||
ImproperlyConfigured, match="PICKLE_VERSION value must be an integer" | ||
): | ||
PickleSerializer({"PICKLE_VERSION": "not-an-integer"}) | ||
|
||
def test_setup_pickle_version_not_explicitly_specified(self): | ||
serializer = PickleSerializer({}) | ||
assert serializer._pickle_version == pickle.DEFAULT_PROTOCOL | ||
|
||
def test_setup_pickle_version_too_high(self): | ||
with pytest.raises( | ||
ImproperlyConfigured, | ||
match=f"PICKLE_VERSION can't be higher than pickle.HIGHEST_PROTOCOL:" | ||
f" {pickle.HIGHEST_PROTOCOL}", | ||
): | ||
PickleSerializer({"PICKLE_VERSION": pickle.HIGHEST_PROTOCOL + 1}) |