-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: allow extra options for storage backends #40
Merged
c00kiemon5ter
merged 4 commits into
IdentityPython:master
from
maxxiefjv:feature/allow-redis-tls
Sep 3, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd6e0d9
allow from_uri SSL param options
maxxiefjv 7408566
and default is an empty dict
maxxiefjv 0fbb18c
if user defaults to None as explicit param, set to empty dict
maxxiefjv 04fee31
Normalize Storage wrapper interfaces and allow extra options
c00kiemon5ter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,16 @@ | |
__author__ = 'lundberg' | ||
|
||
|
||
uri_list = ["mongodb://localhost:1234/pyop", "redis://localhost/0"] | ||
db_specs_list = [ | ||
{"uri": "mongodb://localhost:1234/pyop", "name": "pyop"}, | ||
{"uri": "redis://localhost/0", "name": 0}, | ||
] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_redis(monkeypatch): | ||
def mockreturn(*args, **kwargs): | ||
return fakeredis.FakeStrictRedis(decode_responses=True) | ||
return fakeredis.FakeStrictRedis(*args, **kwargs) | ||
monkeypatch.setattr(Redis, "from_url", mockreturn) | ||
|
||
@pytest.fixture(autouse=True) | ||
|
@@ -30,10 +34,10 @@ def mock_mongo(): | |
|
||
|
||
class TestStorage(object): | ||
@pytest.fixture(params=uri_list) | ||
@pytest.fixture(params=db_specs_list) | ||
def db(self, request): | ||
return pyop.storage.StorageBase.from_uri( | ||
request.param, db_name="pyop", collection="test" | ||
request.param["uri"], db_name=request.param["name"], collection="test" | ||
) | ||
|
||
def test_write(self, db): | ||
|
@@ -69,15 +73,15 @@ def test_items(self, db): | |
@pytest.mark.parametrize( | ||
"args,kwargs", | ||
[ | ||
(["redis://localhost"], {"collection": "test"}), | ||
(["redis://localhost", "test"], {}), | ||
(["unix://localhost/0"], {"collection": "test", "ttl": 3}), | ||
(["mongodb://localhost/pyop"], {"collection": "test", "ttl": 3}), | ||
(["mongodb://localhost"], {"db_name": "pyop", "collection": "test"}), | ||
(["mongodb://localhost", "test", "pyop"], {}), | ||
(["mongodb://localhost/pyop", "test"], {}), | ||
(["mongodb://localhost/pyop"], {"db_name": "other", "collection": "test"}), | ||
(["redis://localhost/0"], {"db_name": "pyop", "collection": "test"}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
(["redis://localhost"], {"collection": "test"}), | ||
(["redis://localhost", "test"], {}), | ||
(["redis://localhost"], {"db_name": 2, "collection": "test"}), | ||
(["unix://localhost/0"], {"collection": "test", "ttl": 3}), | ||
], | ||
) | ||
def test_from_uri(self, args, kwargs): | ||
|
@@ -88,11 +92,7 @@ def test_from_uri(self, args, kwargs): | |
@pytest.mark.parametrize( | ||
"error,args,kwargs", | ||
[ | ||
( | ||
TypeError, | ||
["redis://localhost", "ouch"], | ||
{"db_name": 3, "collection": "test", "ttl": None}, | ||
), | ||
(ValueError, ["mongodb://localhost"], {"collection": "test", "ttl": None}), | ||
( | ||
TypeError, | ||
["mongodb://localhost", "ouch"], | ||
|
@@ -110,12 +110,11 @@ def test_from_uri(self, args, kwargs): | |
), | ||
( | ||
TypeError, | ||
["mongodb://localhost"], | ||
{"db_name": "pyop", "collection": "test", "ttl": None, "extra": True}, | ||
["redis://localhost", "ouch"], | ||
{"db_name": 3, "collection": "test", "ttl": None}, | ||
), | ||
(TypeError, ["redis://localhost/0"], {}), | ||
(TypeError, ["redis://localhost/0"], {"db_name": "pyop"}), | ||
(ValueError, ["mongodb://localhost"], {"collection": "test", "ttl": None}), | ||
], | ||
) | ||
def test_from_uri_invalid_parameters(self, error, args, kwargs): | ||
|
@@ -153,11 +152,11 @@ def execute_ttl_test(self, uri, ttl): | |
with pytest.raises(KeyError): | ||
self.db["foo"] | ||
|
||
@pytest.mark.parametrize("uri", uri_list) | ||
@pytest.mark.parametrize("spec", db_specs_list) | ||
@pytest.mark.parametrize("ttl", ["invalid", -1, 2.3, {}]) | ||
def test_invalid_ttl(self, uri, ttl): | ||
def test_invalid_ttl(self, spec, ttl): | ||
with pytest.raises(ValueError): | ||
self.prepare_db(uri, ttl) | ||
self.prepare_db(spec["uri"], ttl) | ||
|
||
|
||
class TestRedisTTL(StorageTTLTest): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: set all but the first arg to RedisWrapper to be keyword-only args.
Added
db_name
as the redis db index.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, the MongoWrapper and RedisWrapper initialization interfaces are the same.