Skip to content

Commit

Permalink
Add a mock() function
Browse files Browse the repository at this point in the history
This is the same as the Mocker() however it looks more correct to do
@requests_mock.mock() rather than @requests_mock.Mocker().

Ideally mock() would be the decorator and Mocker() the context manager
but it doesn't really matter.
  • Loading branch information
Jamie Lennox committed Jul 29, 2014
1 parent 96fbd5a commit 4ae5f15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion requests_mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

from requests_mock.adapter import Adapter, ANY
from requests_mock.exceptions import MockException, NoMockAddress
from requests_mock.mocker import Mocker, MockerCore
from requests_mock.mocker import mock, Mocker, MockerCore
from requests_mock.mocker import DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT


__all__ = ['Adapter',
'ANY',
'mock',
'Mocker',
'MockerCore',
'MockException',
Expand Down
3 changes: 3 additions & 0 deletions requests_mock/mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ def inner(*args, **kwargs):
return func(*args, **kwargs)

return inner


mock = Mocker
8 changes: 4 additions & 4 deletions requests_mock/tests/test_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_with_context_manager(self):
self.assertMockStopped()

@mock.patch('requests.adapters.HTTPAdapter.send')
@requests_mock.Mocker(real_http=True)
@requests_mock.mock(real_http=True)
def test_real_http(self, real_send, mocker):
url = 'http://www.google.com/'

Expand All @@ -61,17 +61,17 @@ def test_real_http(self, real_send, mocker):
self.assertEqual(1, real_send.call_count)
self.assertEqual(url, real_send.call_args[0][0].url)

@requests_mock.Mocker()
@requests_mock.mock()
def test_with_test_decorator(self, m):
self._do_test(m)

@requests_mock.Mocker(kw='mock')
@requests_mock.mock(kw='mock')
def test_with_mocker_kwargs(self, **kwargs):
self._do_test(kwargs['mock'])

def test_with_decorator(self):

@requests_mock.Mocker()
@requests_mock.mock()
def inner(m):
self.assertMockStarted()
self._do_test(m)
Expand Down

0 comments on commit 4ae5f15

Please sign in to comment.