|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +############################################################################## |
| 3 | +# |
| 4 | +# Copyright (C) 2025 Jimmy McCann |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are met: |
| 9 | +# |
| 10 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 11 | +# list of conditions and the following disclaimer. |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | +# this list of conditions and the following disclaimer in the documentation |
| 14 | +# and/or other materials provided with the distribution. |
| 15 | +# |
| 16 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 20 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +# |
| 27 | +############################################################################## |
| 28 | + |
| 29 | +import unittest |
| 30 | +from unittest.mock import MagicMock |
| 31 | +from odoolib.service import Service |
| 32 | + |
| 33 | + |
| 34 | +class TestService(unittest.TestCase): |
| 35 | + def setUp(self): |
| 36 | + self.mock_sender = MagicMock() |
| 37 | + self.service_name = "common" |
| 38 | + self.service = Service(self.mock_sender, self.service_name) |
| 39 | + |
| 40 | + def test_sync_method_call(self): |
| 41 | + self.mock_sender.send.return_value = "success" |
| 42 | + |
| 43 | + result = self.service.some_method("arg1", 42) |
| 44 | + |
| 45 | + self.mock_sender.send.assert_called_once_with("common", "some_method", "arg1", 42) |
| 46 | + self.assertEqual(result, "success") |
| 47 | + |
| 48 | + def test_sync_method_caching_and_multiple_calls(self): |
| 49 | + self.mock_sender.send.side_effect = ["res1", "res2"] |
| 50 | + |
| 51 | + result1 = self.service.foo(1) |
| 52 | + result2 = self.service.foo(2) |
| 53 | + |
| 54 | + self.assertEqual(result1, "res1") |
| 55 | + self.assertEqual(result2, "res2") |
| 56 | + self.assertEqual(self.mock_sender.send.call_count, 2) |
| 57 | + |
| 58 | + def test_method_name_reflection(self): |
| 59 | + proxy = self.service.do_something |
| 60 | + self.assertTrue(callable(proxy)) |
| 61 | + self.assertTrue(hasattr(proxy, "async_")) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + unittest.main() |
0 commit comments