Skip to content
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

Bot Sorting #1205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

maheshsattala
Copy link
Contributor

  1. Added code for the bot sorting with modified date and fixed the test cases for the same.

Copy link

coderabbitai bot commented May 15, 2024

Walkthrough

Walkthrough

The recent updates enhance the bot management system by introducing a modified_at timestamp to track bot updates and ensuring that only authorized users can update bots. Additionally, test cases have been adjusted to reflect these changes, ensuring proper functionality and user authorization.

Changes

Files Change Summary
kairon/api/app/routers/account.py Updated update_bot to include current_user.get_user() as an argument.
kairon/shared/account/data_objects.py Added modified_at field to the Bot class.
kairon/shared/account/processor.py Modified list_bots to order by modified_at; updated update_bot to modify modified_at field.
tests/integration_test/services_test.py Adjusted bot names and indices in assertions for bot operations tests.
tests/unit_test/api/api_processor_test.py Updated test cases to include user information in update_bot and adjusted bot indices.

In code we trust, with changes so bright,
Bots now update with a timestamp's light.
Tests are refined, ensuring they're right,
Users protected, with all their might.
A rabbit's joy, in lines so tight!
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

Out of diff range and nitpick comments (15)
kairon/api/app/routers/account.py (1)

Line range hint 1-1: Remove unused imports fastapi.Form and fastapi.Path.

- from fastapi import APIRouter, Depends, Security, Form, Path
+ from fastapi import APIRouter, Depends, Security
kairon/shared/account/processor.py (3)

Line range hint 91-91: Avoid using bare except statements.

Using bare except statements can catch unexpected errors and make debugging difficult. Specify the exception type to catch only the intended exceptions.

-        except:
+        except DoesNotExist:

Line range hint 645-645: Avoid using bare except statements.

Using bare except statements can catch unexpected errors and make debugging difficult. Specify the exception type to catch only the intended exceptions.

-        except:
+        except DoesNotExist:

Line range hint 813-813: Remove unused import.

The import kairon.shared.data.processor.MongoProcessor is not used in this file and should be removed to keep the code clean.

- from kairon.shared.data.processor import MongoProcessor
tests/unit_test/api/api_processor_test.py (11)

Line range hint 2688-2688: Use isinstance() instead of comparing types directly.

-        assert all([i for i in temp if type(i) is dict])
+        assert all([i for i in temp if isinstance(i, dict)])

Line range hint 25-25: Remove the unused import kairon.api.app.routers.idp.get_idp_config.

- from kairon.api.app.routers.idp import get_idp_config

Line range hint 46-46: Remove the redefined unused import AppException.

- from kairon.exceptions import AppException

Line range hint 47-47: Remove the redefined unused import time.

- import time

Line range hint 48-48: Remove the redefined unused import IdpConfig.

- from kairon.idp.data_objects import IdpConfig

Line range hint 49-49: Remove the redefined unused imports RegisterAccount, EventConfig, IDPConfig, StoryRequest, HttpActionParameters, and Password.

- from kairon.api.models import RegisterAccount, EventConfig, IDPConfig, StoryRequest, HttpActionParameters, Password

Line range hint 50-50: Remove the unused import mongomock.MongoClient.

- from mongomock import MongoClient

Line range hint 1397-1397: Remove the unused local variable start_date.

-        start_date = datetime.datetime.now()

Line range hint 1539-1539: Remove the unused local variable data_stack.

-        data_stack = Utility.decode_limited_access_token(refresh)

Line range hint 1577-1577: Remove the unused local variable data_stack.

-        data_stack = Utility.decode_limited_access_token(refresh)

Line range hint 1594-1594: Fix the f-string without any placeholders.

-        assert f"Account frozen due to too many unsuccessful login attempts. Please come back in *"
+        assert "Account frozen due to too many unsuccessful login attempts. Please come back in *"
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 589e8e1 and b49042d.
Files selected for processing (5)
  • kairon/api/app/routers/account.py (1 hunks)
  • kairon/shared/account/data_objects.py (1 hunks)
  • kairon/shared/account/processor.py (1 hunks)
  • tests/integration_test/services_test.py (4 hunks)
  • tests/unit_test/api/api_processor_test.py (16 hunks)
Additional Context Used
Ruff (81)
kairon/api/app/routers/account.py (2)

1-1: fastapi.Form imported but unused


1-1: fastapi.Path imported but unused

kairon/shared/account/processor.py (3)

91-91: Do not use bare except


645-645: Do not use bare except


813-813: kairon.shared.data.processor.MongoProcessor imported but unused

tests/integration_test/services_test.py (57)

826-826: f-string without any placeholders


836-836: f-string without any placeholders


2414-2414: Local variable response_three is assigned to but never used


2638-2638: Comparison to None should be cond is None


5463-5463: Avoid equality comparisons to True; use if actual["success"]: for truth checks


5672-5672: Do not compare types, use isinstance()


8497-8497: f-string without any placeholders


9037-9037: Local variable response_one is assigned to but never used


9041-9041: Local variable response_two is assigned to but never used


9045-9045: Local variable response_three is assigned to but never used


9068-9068: f-string without any placeholders


9211-9211: f-string without any placeholders


9691-9691: Local variable response_delete_story_one is assigned to but never used


9696-9696: Local variable response_delete_story_two is assigned to but never used


10385-10385: Local variable payload_response is assigned to but never used


12483-12483: f-string without any placeholders


14003-14003: Comparison to None should be cond is None


14049-14049: Comparison to None should be cond is None


16866-16866: f-string without any placeholders


16877-16877: f-string without any placeholders


16888-16888: f-string without any placeholders


16901-16901: f-string without any placeholders


16911-16911: f-string without any placeholders


16920-16920: f-string without any placeholders


16937-16937: f-string without any placeholders


16943-16943: f-string without any placeholders


16949-16949: f-string without any placeholders


16969-16969: f-string without any placeholders


16973-16973: f-string without any placeholders


16979-16979: f-string without any placeholders


16990-16990: f-string without any placeholders


17007-17007: f-string without any placeholders


17020-17020: f-string without any placeholders


17033-17033: f-string without any placeholders


17047-17047: f-string without any placeholders


17079-17079: f-string without any placeholders


18643-18643: Comparison to None should be cond is None


18684-18684: Comparison to None should be cond is None


18698-18698: Comparison to None should be cond is None


19239-19239: f-string without any placeholders


20534-20534: Local variable mock is assigned to but never used


21891-21891: f-string without any placeholders


21926-21926: Comparison to None should be cond is None


22015-22015: Comparison to None should be cond is None


22041-22041: Comparison to None should be cond is None


22281-22281: Avoid equality comparisons to False; use if not actual["data"]["logs"][1]["translate_responses"]: for false checks


22282-22282: Avoid equality comparisons to False; use if not actual["data"]["logs"][1]["translate_actions"]: for false checks


22298-22298: f-string without any placeholders


22544-22544: f-string without any placeholders


22596-22596: f-string without any placeholders


23254-23254: f-string without any placeholders


23268-23268: f-string without any placeholders


23361-23361: Local variable passwrd_change_response is assigned to but never used


23441-23441: Local variable regsiter_response is assigned to but never used


23473-23473: Local variable regsiter_response is assigned to but never used


23678-23678: Avoid equality comparisons to False; use if not actual["success"]: for false checks


23682-23682: f-string without any placeholders

tests/unit_test/api/api_processor_test.py (19)

25-25: kairon.api.app.routers.idp.get_idp_config imported but unused


46-46: Redefinition of unused AppException from line 27


47-47: Redefinition of unused time from line 5


48-48: Redefinition of unused IdpConfig from line 28


49-49: Redefinition of unused RegisterAccount from line 26


49-49: Redefinition of unused EventConfig from line 26


49-49: Redefinition of unused IDPConfig from line 26


49-49: Redefinition of unused StoryRequest from line 26


49-49: Redefinition of unused HttpActionParameters from line 26


49-49: Redefinition of unused Password from line 26


50-50: mongomock.MongoClient imported but unused


1397-1397: Local variable start_date is assigned to but never used


1539-1539: Local variable data_stack is assigned to but never used


1577-1577: Local variable data_stack is assigned to but never used


1594-1594: f-string without any placeholders


1628-1628: Local variable start_date is assigned to but never used


1722-1722: Local variable payload is assigned to but never used


2569-2569: Local variable idp_config is assigned to but never used


2688-2688: Do not compare types, use isinstance()

Additional comments not posted (29)
kairon/shared/account/data_objects.py (1)

85-85: Addition of modified_at field looks good and will help in tracking the last modification time of each bot.

kairon/api/app/routers/account.py (1)

167-167: The addition of current_user.get_user() to the update_bot function ensures that the user context is passed during bot updates. This change looks good.

kairon/shared/account/processor.py (2)

212-217: Ensure proper ordering of bots by modified_at.

The logic to order bots by modified_at in descending order looks correct. This will ensure that the most recently modified bots appear first.


220-229: Ensure modified_at is updated correctly.

The logic to update the modified_at field if the user matches the bot's user looks correct. This ensures that the modification time is only updated by the bot's owner.

tests/unit_test/api/api_processor_test.py (21)

126-126: Ensure the user parameter is correctly passed and utilized in the AccountProcessor.update_bot method.


195-195: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


207-207: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


219-219: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


229-229: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


239-239: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


266-266: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


278-278: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


291-291: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


313-313: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


323-323: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


337-337: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


344-344: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


356-356: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


379-379: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


410-410: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


418-418: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


424-424: Ensure the bot ID retrieval logic aligns with the new bot ordering by modified_at.


445-447: Ensure the assertions reflect the new bot ordering by modified_at.


451-454: Ensure the user parameter is correctly passed and utilized in the AccountProcessor.update_bot method.


458-462: Ensure the user parameter is correctly passed and utilized in the AccountProcessor.update_bot method.

tests/integration_test/services_test.py (4)

1118-1125: The changes in the test_list_bots function correctly update the bot index to reflect the new ordering logic. The assertions have been adjusted to match the new order of bots.


9557-9557: The changes in the test_add_intents_to_different_bot function correctly update the bot index to reflect the new ordering logic.


9681-9681: The changes in the _mock_training_limit function correctly update the bot index to reflect the new ordering logic.


9720-9720: The changes in the test_delete_bot function correctly update the bot index to reflect the new ordering logic.

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.

None yet

1 participant