-
Notifications
You must be signed in to change notification settings - Fork 84
odoo test cases #2280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
odoo test cases #2280
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from unittest.mock import patch | ||
|
|
||
| mock_env = { | ||
| "pos": { | ||
| "odoo": { | ||
| "odoo_url": "http://localhost:8080", | ||
| "odoo_master_password":"admin@123" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| patcher = patch("kairon.Utility.environment", mock_env) | ||
| patcher.start() | ||
|
|
||
| from kairon.pos.odoo.odoo_pos import OdooPOS | ||
| from kairon.shared.pos.processor import POSProcessor | ||
|
|
||
| import pytest | ||
|
|
||
| @pytest.fixture | ||
| def odoo_pos(): | ||
| return OdooPOS() | ||
|
|
||
|
|
||
| def teardown_module(module): | ||
| """Stop environment patch after all tests.""" | ||
| patcher.stop() | ||
|
|
||
|
|
||
| def test_products_list(odoo_pos): | ||
| resp = odoo_pos.products_list() | ||
| assert resp["url"].startswith("http://localhost:8080") | ||
|
|
||
|
|
||
| def test_orders_list(odoo_pos): | ||
| resp = odoo_pos.orders_list() | ||
| assert resp["url"].startswith("http://localhost:8080") | ||
|
|
||
|
|
||
| def test_onboarding(odoo_pos): | ||
| with patch.object(POSProcessor, "onboarding_client", return_value={"ok": True}) as mock_fn: | ||
| resp = odoo_pos.onboarding(client_name="demo", bot="test_bot", user="aniket.kharkia@nimblework.com") | ||
| mock_fn.assert_called_once() | ||
| assert resp == {"ok": True} | ||
|
|
||
| def test_authenticate_products(odoo_pos): | ||
| with ( | ||
| patch.object(POSProcessor, "pos_login", return_value={"session": "s1"}) as p_login, | ||
| patch.object(OdooPOS, "products_list", return_value={"url": "p_url"}) as p_list, | ||
| patch.object(POSProcessor, "set_odoo_session_cookie", return_value={"done": True}) as p_cookie, | ||
| ): | ||
| resp = odoo_pos.authenticate(client_name="demo", bot="test_bot") | ||
|
|
||
| p_login.assert_called_once() | ||
| p_list.assert_called_once() | ||
| p_cookie.assert_called_once_with({"session": "s1", "url": "p_url"}) | ||
|
|
||
| assert resp == {"done": True} | ||
|
|
||
| def test_authenticate_orders(odoo_pos): | ||
| with ( | ||
| patch.object(POSProcessor, "pos_login", return_value={"session": "xyz"}) as p_login, | ||
| patch.object(OdooPOS, "orders_list", return_value={"url": "o_url"}) as o_list, | ||
| patch.object(POSProcessor, "set_odoo_session_cookie", return_value={"ok": 1}) as p_cookie | ||
| ): | ||
| resp = odoo_pos.authenticate(client_name="C", bot="B", page_type="pos_orders") | ||
|
|
||
| p_login.assert_called_once() | ||
| o_list.assert_called_once() | ||
| p_cookie.assert_called_once_with({"session": "xyz", "url": "o_url"}) | ||
| assert resp == {"ok": 1} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mock configuration to match actual factory usage pattern.
The mock is incorrectly set up with
mock_pos.return_value.onboarding.return_value, butPOSFactory.get_instance("odoo")returns an OdooPOS instance directly (not a callable). The endpoint code callspos_instance.onboarding(...)wherepos_instanceis the returned instance, not a function to be invoked.Correct the mock setup:
The same issue exists in
test_odoo_login—mock_pos.return_value.authenticateshould bemock_pos.authenticate.📝 Committable suggestion
🤖 Prompt for AI Agents