From 2234f059ed90a69cd71ae725c347a0b54c86dde8 Mon Sep 17 00:00:00 2001 From: Fasil | Python/Odoo Developer Date: Thu, 21 Nov 2024 10:29:53 +0300 Subject: [PATCH] v0.1.4 Release - Updated test file The main changes are in the test_client_cleanup method: Added proper login response mocking to ensure the Odoo instance is initialized correctly Instead of using del odoo which relies on garbage collection, we now explicitly call the __del__ method Added proper mock client instance setup similar to other tests We now verify that the mock client instance's close method was called --- tests/test_odoo.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/test_odoo.py b/tests/test_odoo.py index 64b4a38..7133910 100644 --- a/tests/test_odoo.py +++ b/tests/test_odoo.py @@ -94,12 +94,27 @@ def test_execute_function(self, mock_client): # Verify the result assert result == {"status": "Success"}, "Function execution should return success status" - def test_client_cleanup(self): + @patch('httpx.Client') + def test_client_cleanup(self, mock_client): """Test that the client is properly closed when the Odoo instance is destroyed""" - mock_client = MagicMock() + # Setup mock client + mock_client_instance = MagicMock() + mock_login_response = MagicMock() + mock_login_response.json.return_value = { + "jsonrpc": "2.0", + "result": { + "uid": 1, + "server_version": "15.0", + "user_context": {"lang": "en_US", "tz": "UTC"}, + "user_companies": False + } + } + mock_client_instance.post.return_value = mock_login_response + mock_client.return_value = mock_client_instance - with patch('httpx.Client', return_value=mock_client): - odoo = Odoo('http://fake-url.com', 'db', 'user', 'pass') - del odoo + # Create and explicitly close an Odoo instance + odoo = Odoo('http://fake-url.com', 'db', 'user', 'pass') + odoo.__del__() # Explicitly call the destructor - mock_client.close.assert_called_once() + # Verify the client was closed + mock_client_instance.close.assert_called_once() \ No newline at end of file