tests: Add session factory fixture and use it in tests.
This commit is contained in:
parent
ce59485a70
commit
28f81cadd3
1 changed files with 18 additions and 8 deletions
|
|
@ -58,28 +58,38 @@ def stub_session():
|
|||
return session
|
||||
|
||||
|
||||
def test_repo_maker_uses_session_for_classmethods(stub_session):
|
||||
@pytest.fixture
|
||||
def stub_session_factory(stub_session):
|
||||
"""
|
||||
Stub of `rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory`.
|
||||
"""
|
||||
session_factory = mock.Mock()
|
||||
session_factory.return_value = stub_session
|
||||
return session_factory
|
||||
|
||||
|
||||
def test_repo_maker_uses_session_for_classmethods(stub_session_factory):
|
||||
repo_maker = client_http.RepoMaker(
|
||||
'server_and_port', 'endpoint', stub_session)
|
||||
'server_and_port', 'endpoint', stub_session_factory)
|
||||
repo_maker.example_call()
|
||||
stub_session.post.assert_called_with(
|
||||
stub_session_factory().post.assert_called_with(
|
||||
'http://server_and_port/endpoint', data=mock.ANY)
|
||||
|
||||
|
||||
def test_repo_maker_uses_session_for_instance_methods(
|
||||
stub_session, config):
|
||||
stub_session_factory, config):
|
||||
repo_maker = client_http.RepoMaker(
|
||||
'server_and_port', 'endpoint', stub_session)
|
||||
'server_and_port', 'endpoint', stub_session_factory)
|
||||
repo = repo_maker('stub_path', config)
|
||||
repo.example_call()
|
||||
stub_session.post.assert_called_with(
|
||||
stub_session_factory().post.assert_called_with(
|
||||
'http://server_and_port/endpoint', data=mock.ANY)
|
||||
|
||||
|
||||
@mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory')
|
||||
@mock.patch('rhodecode.lib.vcs.connection')
|
||||
def test_connect_passes_in_the_same_session(connection, session_factory_class,
|
||||
stub_session):
|
||||
def test_connect_passes_in_the_same_session(
|
||||
connection, session_factory_class, stub_session):
|
||||
session_factory = session_factory_class.return_value
|
||||
session_factory.return_value = stub_session
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue