-
Notifications
You must be signed in to change notification settings - Fork 158
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
Disable decorators cache per-call #404
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,37 @@ async def test_calls_get_and_returns(self, decorator, decorator_call): | |
assert decorator.cache.set.call_count == 0 | ||
assert stub.call_count == 0 | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_read(self, decorator, decorator_call): | ||
decorator.cache.get = CoroutineMock(return_value=1) | ||
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. Why do you need this if its not being called? 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. Probably from copy&pasting, removed |
||
|
||
await decorator_call(aiocache_disable_read=True) | ||
|
||
assert decorator.cache.get.call_count == 0 | ||
assert decorator.cache.set.call_count == 1 | ||
assert stub.call_count == 1 | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_write(self, decorator, decorator_call): | ||
decorator.cache.get = CoroutineMock(return_value=None) | ||
|
||
await decorator_call(aiocache_disable_write=True) | ||
|
||
assert decorator.cache.get.call_count == 1 | ||
assert decorator.cache.set.call_count == 0 | ||
assert stub.call_count == 1 | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_params_not_propagated(self, decorator, decorator_call): | ||
decorator.cache.get = CoroutineMock(return_value=None) | ||
|
||
await decorator_call( | ||
aiocache_disable_read=True, | ||
aiocache_disable_write=True, | ||
) | ||
|
||
stub.assert_called_once_with() | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_from_cache_returns(self, decorator, decorator_call): | ||
decorator.cache.get = CoroutineMock(return_value=1) | ||
|
@@ -434,6 +465,38 @@ async def test_calls_fn_raises_exception(self, mocker, decorator, decorator_call | |
with pytest.raises(Exception): | ||
assert await decorator_call(keys=[]) | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_read(self, decorator, decorator_call): | ||
decorator.cache.multi_get = CoroutineMock(return_value=[1, 2]) | ||
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. same, not needed because its not being called? 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. Removed |
||
|
||
await decorator_call(1, keys=['a', 'b'], aiocache_disable_read=True) | ||
|
||
assert decorator.cache.multi_get.call_count == 0 | ||
assert decorator.cache.multi_set.call_count == 1 | ||
assert stub_dict.call_count == 1 | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_write(self, decorator, decorator_call): | ||
decorator.cache.multi_get = CoroutineMock(return_value=[None, None]) | ||
|
||
await decorator_call(1, keys=['a', 'b'], aiocache_disable_write=True) | ||
|
||
assert decorator.cache.multi_get.call_count == 1 | ||
assert decorator.cache.multi_set.call_count == 0 | ||
assert stub_dict.call_count == 1 | ||
|
||
@pytest.mark.asyncio | ||
async def test_disable_params_not_propagated(self, decorator, decorator_call): | ||
decorator.cache.multi_get = CoroutineMock(return_value=[None, None]) | ||
|
||
await decorator_call( | ||
1, keys=['a', 'b'], | ||
aiocache_disable_read=True, | ||
aiocache_disable_write=True, | ||
) | ||
|
||
stub_dict.assert_called_once_with(1, keys=['a', 'b']) | ||
|
||
@pytest.mark.asyncio | ||
async def test_set_in_cache(self, decorator, decorator_call): | ||
await decorator.set_in_cache({'a': 1, 'b': 2}, (), {}) | ||
|
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.
Put explicitly in the
function
signature pleaseThere 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.
Also, add docs about those two new parameters in the class docstring or in
decorators.rst
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.
Done