Skip to content

Commit

Permalink
v0.1.4 Release - Updated test file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fasilwdr committed Nov 21, 2024
1 parent 7e817a5 commit 2234f05
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tests/test_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2234f05

Please sign in to comment.