Skip to content

odoo test cases#2280

Closed
Aniketkharkia wants to merge 2 commits intodigiteinfotech:masterfrom
Aniketkharkia:odoo_tests
Closed

odoo test cases#2280
Aniketkharkia wants to merge 2 commits intodigiteinfotech:masterfrom
Aniketkharkia:odoo_tests

Conversation

@Aniketkharkia
Copy link
Contributor

@Aniketkharkia Aniketkharkia commented Dec 4, 2025

Summary by CodeRabbit

  • Tests
    • Significantly expanded integration test coverage for chatbot management system including bot registration, configuration, permissions, content management, integrations, and media handling
    • Added comprehensive external service connectivity and error scenario validation
    • Introduced unit tests for Odoo POS integration covering product management, order handling, and authentication flows

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

This PR adds comprehensive test coverage across two test files: integration tests for a chatbot management API (covering bot operations, configurations, integrations, media, and scheduling) and unit tests for Odoo POS integration (covering products, orders, onboarding, and authentication flows).

Changes

Cohort / File(s) Summary
Integration tests for chatbot management system
tests/integration_test/services_test.py
Adds extensive test functions covering chatbot API endpoints: bot registration, configuration, permissions, intents, training, responses, stories, actions, integrations (SSO, live agent, channels), media upload/download, asset management, role/permission management, scheduling, and logging. Includes mocks for external services (AWS, Slack, Jira, Pipedrive, Zapier, Chatwoot, HubSpot, Google) with error case validations.
Unit tests for Odoo POS integration
tests/unit_test/pos_test.py
Introduces unit tests for Odoo POS methods (products_list, orders_list), onboarding flow, and authentication flows for both products and orders. Mocks POSProcessor and environment configuration to simulate Odoo connection details and session management.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Integration test file: Broad coverage across multiple endpoints and scenarios requires reviewing test logic for each major functional area (integrations, media, scheduling, permissions, etc.) and mock implementations for external services
  • Unit test file: Focused but requires careful review of mock sequencing and assertion validations for authentication flows

Poem

🐰 A thousand tests now hop through the code,
Coverage blooming down every road,
Mocks and assertions, all in a row,
Building confidence—watch the system grow! 🧪✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title "odoo test cases" is vague and generic. While it mentions Odoo, it doesn't convey what specific tests were added or their purpose. The changeset includes extensive integration tests for a chatbot system and unit tests for Odoo POS integration, but the title doesn't capture the actual scope or significance of the changes. Use a more descriptive title that specifies the test additions, such as "Add integration and unit tests for chatbot services and Odoo POS" or "Add comprehensive test coverage for API endpoints and Odoo integration."
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tests/unit_test/pos_test.py (3)

40-44: Consider verifying the arguments passed to the mocked function.

The test confirms that onboarding_client is called and returns the expected value, but it doesn't verify that the correct arguments (client_name, bot, user) are passed through.

Apply this diff to make the test more robust:

 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()
+        mock_fn.assert_called_once_with(client_name="demo", bot="test_bot", user="aniket.kharkia@nimblework.com")
         assert resp == {"ok": True}

46-58: Consider verifying arguments passed to pos_login.

The test correctly verifies the data flow through set_odoo_session_cookie, but it could also verify that pos_login receives the expected client_name and bot parameters.

Apply this diff to enhance the test:

         resp = odoo_pos.authenticate(client_name="demo", bot="test_bot")
 
-        p_login.assert_called_once()
+        p_login.assert_called_once_with("demo", "test_bot")
         p_list.assert_called_once()
         p_cookie.assert_called_once_with({"session": "s1", "url": "p_url"})

60-71: Consider verifying arguments passed to pos_login.

Similar to test_authenticate_products, this test could be enhanced by verifying that pos_login receives the expected parameters.

Apply this diff:

         resp = odoo_pos.authenticate(client_name="C", bot="B", page_type="pos_orders")
 
-        p_login.assert_called_once()
+        p_login.assert_called_once_with("C", "B")
         o_list.assert_called_once()
         p_cookie.assert_called_once_with({"session": "xyz", "url": "o_url"})
         assert resp == {"ok": 1}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0b69d9 and 1b963dc.

📒 Files selected for processing (2)
  • tests/integration_test/services_test.py (1 hunks)
  • tests/unit_test/pos_test.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/integration_test/services_test.py (2)
kairon/pos/odoo/odoo_pos.py (2)
  • onboarding (12-22)
  • authenticate (24-38)
kairon/pos/definitions/base.py (2)
  • onboarding (9-10)
  • authenticate (13-14)
tests/unit_test/pos_test.py (2)
kairon/pos/odoo/odoo_pos.py (1)
  • OdooPOS (9-54)
kairon/shared/pos/processor.py (1)
  • POSProcessor (18-732)
🪛 Ruff (0.14.7)
tests/unit_test/pos_test.py

25-25: Unused function argument: module

(ARG001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Python CI
🔇 Additional comments (5)
tests/unit_test/pos_test.py (4)

1-13: LGTM! Proper environment patching before imports.

The pattern of patching kairon.Utility.environment before importing the modules that depend on it is correct and ensures the mock configuration is used throughout the tests.


15-22: LGTM! Clean fixture definition.

The fixture properly instantiates OdooPOS for use across multiple tests.


25-27: LGTM! Proper cleanup of the environment patch.

The module parameter is required by pytest's teardown_module signature. The static analysis warning is a false positive and can be safely ignored.


30-37: LGTM! Tests verify environment configuration is used.

Both tests appropriately verify that the mocked Odoo URL is used when constructing product and order list URLs.

tests/integration_test/services_test.py (1)

2788-2814: Same mock configuration concern applies here.

This test uses the same mock_pos.return_value.authenticate pattern. If the previous test's mock setup is incorrect, apply the same fix here:

 mock_pos = MagicMock()
-mock_pos.return_value.authenticate.return_value = {"ok": True}
+mock_pos.authenticate.return_value = {"ok": True}

 mock_factory.return_value = mock_pos
 ...
-mock_pos.return_value.authenticate.assert_called_once_with(
+mock_pos.authenticate.assert_called_once_with(
     client_name="XYZ_Pvt_Ltd",
     page_type="pos_products",
     bot=pytest.bot
 )

Comment on lines +2760 to +2786
with patch("kairon.pos.definitions.factory.POSFactory.get_instance") as mock_factory:

mock_pos = MagicMock()
mock_pos.return_value.onboarding.return_value = {"ok": True}

mock_factory.return_value = mock_pos

payload = {
"client_name": "XYZ_Pvt_Ltd"
}


response = client.post(
url=f"/api/bot/{pytest.bot}/pos/odoo/register",
json=payload,
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)

actual = response.json()
assert actual["success"]
assert actual["data"] == {'ok': True}
mock_factory.assert_called_once_with("odoo")
mock_pos.return_value.onboarding.assert_called_once_with(
client_name="XYZ_Pvt_Ltd",
bot=pytest.bot,
user='integration@demo.ai'
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix mock configuration to match actual factory usage pattern.

The mock is incorrectly set up with mock_pos.return_value.onboarding.return_value, but POSFactory.get_instance("odoo") returns an OdooPOS instance directly (not a callable). The endpoint code calls pos_instance.onboarding(...) where pos_instance is the returned instance, not a function to be invoked.

Correct the mock setup:

 mock_pos = MagicMock()
-mock_pos.return_value.onboarding.return_value = {"ok": True}
+mock_pos.onboarding.return_value = {"ok": True}

 mock_factory.return_value = mock_pos
 ...
-mock_pos.return_value.onboarding.assert_called_once_with(
+mock_pos.onboarding.assert_called_once_with(
     client_name="XYZ_Pvt_Ltd",
     bot=pytest.bot,
     user='integration@demo.ai'
 )

The same issue exists in test_odoo_loginmock_pos.return_value.authenticate should be mock_pos.authenticate.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with patch("kairon.pos.definitions.factory.POSFactory.get_instance") as mock_factory:
mock_pos = MagicMock()
mock_pos.return_value.onboarding.return_value = {"ok": True}
mock_factory.return_value = mock_pos
payload = {
"client_name": "XYZ_Pvt_Ltd"
}
response = client.post(
url=f"/api/bot/{pytest.bot}/pos/odoo/register",
json=payload,
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["success"]
assert actual["data"] == {'ok': True}
mock_factory.assert_called_once_with("odoo")
mock_pos.return_value.onboarding.assert_called_once_with(
client_name="XYZ_Pvt_Ltd",
bot=pytest.bot,
user='integration@demo.ai'
)
with patch("kairon.pos.definitions.factory.POSFactory.get_instance") as mock_factory:
mock_pos = MagicMock()
mock_pos.onboarding.return_value = {"ok": True}
mock_factory.return_value = mock_pos
payload = {
"client_name": "XYZ_Pvt_Ltd"
}
response = client.post(
url=f"/api/bot/{pytest.bot}/pos/odoo/register",
json=payload,
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["success"]
assert actual["data"] == {'ok': True}
mock_factory.assert_called_once_with("odoo")
mock_pos.onboarding.assert_called_once_with(
client_name="XYZ_Pvt_Ltd",
bot=pytest.bot,
user='integration@demo.ai'
)
🤖 Prompt for AI Agents
In tests/integration_test/services_test.py around lines 2760 to 2786, the mock
config uses mock_pos.return_value.* but POSFactory.get_instance("odoo") returns
an instance directly, so set expectations on the mock instance itself: assign
mock_factory.return_value = mock_pos and replace uses of
mock_pos.return_value.onboarding.return_value with
mock_pos.onboarding.return_value (and similarly change
mock_pos.return_value.onboarding.assert_called_once_with to
mock_pos.onboarding.assert_called_once_with). Do the same fix for the other test
(test_odoo_login): use mock_pos.authenticate and
mock_pos.authenticate.assert_called_once_with instead of
mock_pos.return_value.authenticate variants so the mocked methods match how the
factory is used.

Copy link
Collaborator

@hiteshghuge hiteshghuge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants