Show More
@@ -58,28 +58,38 b' def stub_session():' | |||||
58 | return session |
|
58 | return session | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def test_repo_maker_uses_session_for_classmethods(stub_session): |
|
61 | @pytest.fixture | |
|
62 | def stub_session_factory(stub_session): | |||
|
63 | """ | |||
|
64 | Stub of `rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory`. | |||
|
65 | """ | |||
|
66 | session_factory = mock.Mock() | |||
|
67 | session_factory.return_value = stub_session | |||
|
68 | return session_factory | |||
|
69 | ||||
|
70 | ||||
|
71 | def test_repo_maker_uses_session_for_classmethods(stub_session_factory): | |||
62 | repo_maker = client_http.RepoMaker( |
|
72 | repo_maker = client_http.RepoMaker( | |
63 | 'server_and_port', 'endpoint', stub_session) |
|
73 | 'server_and_port', 'endpoint', stub_session_factory) | |
64 | repo_maker.example_call() |
|
74 | repo_maker.example_call() | |
65 | stub_session.post.assert_called_with( |
|
75 | stub_session_factory().post.assert_called_with( | |
66 | 'http://server_and_port/endpoint', data=mock.ANY) |
|
76 | 'http://server_and_port/endpoint', data=mock.ANY) | |
67 |
|
77 | |||
68 |
|
78 | |||
69 | def test_repo_maker_uses_session_for_instance_methods( |
|
79 | def test_repo_maker_uses_session_for_instance_methods( | |
70 | stub_session, config): |
|
80 | stub_session_factory, config): | |
71 | repo_maker = client_http.RepoMaker( |
|
81 | repo_maker = client_http.RepoMaker( | |
72 | 'server_and_port', 'endpoint', stub_session) |
|
82 | 'server_and_port', 'endpoint', stub_session_factory) | |
73 | repo = repo_maker('stub_path', config) |
|
83 | repo = repo_maker('stub_path', config) | |
74 | repo.example_call() |
|
84 | repo.example_call() | |
75 | stub_session.post.assert_called_with( |
|
85 | stub_session_factory().post.assert_called_with( | |
76 | 'http://server_and_port/endpoint', data=mock.ANY) |
|
86 | 'http://server_and_port/endpoint', data=mock.ANY) | |
77 |
|
87 | |||
78 |
|
88 | |||
79 | @mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory') |
|
89 | @mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory') | |
80 | @mock.patch('rhodecode.lib.vcs.connection') |
|
90 | @mock.patch('rhodecode.lib.vcs.connection') | |
81 |
def test_connect_passes_in_the_same_session( |
|
91 | def test_connect_passes_in_the_same_session( | |
82 | stub_session): |
|
92 | connection, session_factory_class, stub_session): | |
83 | session_factory = session_factory_class.return_value |
|
93 | session_factory = session_factory_class.return_value | |
84 | session_factory.return_value = stub_session |
|
94 | session_factory.return_value = stub_session | |
85 |
|
95 |
General Comments 0
You need to be logged in to leave comments.
Login now