# HG changeset patch # User RhodeCode Admin # Date 2023-04-20 14:04:30 # Node ID cde6d2b19fb8f05e06b7e078ee3609fbc2f180db # Parent 43b5c59f079a3e08602eecffba25fc7670dbb172 tests: added few generated tests diff --git a/vcsserver/tests/test_hooks.py b/vcsserver/tests/test_hooks.py --- a/vcsserver/tests/test_hooks.py +++ b/vcsserver/tests/test_hooks.py @@ -25,6 +25,7 @@ import mercurial.ui import mock import pytest +from vcsserver.hooks import HooksHttpClient from vcsserver.lib.rc_json import json from vcsserver import hooks @@ -243,3 +244,43 @@ class MirrorHttpServer(object): @property def uri(self): return '{}:{}'.format(self.ip_address, self.port) + + +def test_hooks_http_client_init(): + hooks_uri = 'http://localhost:8000' + client = HooksHttpClient(hooks_uri) + assert client.hooks_uri == hooks_uri + + +def test_hooks_http_client_call(): + hooks_uri = 'http://localhost:8000' + + method = 'test_method' + extras = {'key': 'value'} + + with \ + mock.patch('vcsserver.hooks.HTTPConnection') as mock_connection,\ + mock.patch('msgpack.load') as mock_load: + + client = HooksHttpClient(hooks_uri) + + mock_load.return_value = {'result': 'success'} + response = mock.MagicMock() + response.status = 200 + mock_connection.request.side_effect = None + mock_connection.getresponse.return_value = response + + result = client(method, extras) + + mock_connection.assert_called_with(hooks_uri) + mock_connection.return_value.request.assert_called_once() + assert result == {'result': 'success'} + + +def test_hooks_http_client_serialize(): + method = 'test_method' + extras = {'key': 'value'} + headers, body = HooksHttpClient._serialize(method, extras) + + assert headers == {'rc-hooks-protocol': HooksHttpClient.proto} + assert msgpack.unpackb(body) == {'method': method, 'extras': extras}