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

feature(models): add Status to Tenant model #72

Merged
merged 1 commit into from
Feb 24, 2024
Merged

Conversation

igorsimb
Copy link
Owner

@igorsimb igorsimb commented Feb 23, 2024

Fixes #67, #58

Summary by CodeRabbit

  • New Features
    • Added a "status" field with predefined choices (Trialing, Active, Exempt, Canceled, Trial expired) to the "Tenant" model for better status management.
    • Introduced TenantFactory and UserFactory for streamlined creation of Tenant and CustomUser instances in tests.
  • Bug Fixes
    • Modified the CustomUser model to include a related_name attribute for the tenant field, ensuring clearer relationships and queries.
  • Refactor
    • Improved database performance by adding indexes to the CustomUser and Tenant models.
    • Simplified test setups by removing redundant pytest decorators and adjusting test markers.
    • Enhanced test coverage for accounts and main app models, including user existence, tenant functionalities, and item model creation.
  • Chores
    • Adjusted test configurations and introduced a fixture to ensure consistent test environment setup.

Copy link

coderabbitai bot commented Feb 23, 2024

Walkthrough

The recent updates focus on enhancing the Tenant and CustomUser models within a Django application. Key modifications include the introduction of a status field in the Tenant model with predefined choices and indexing for improved query performance. The CustomUser model now references the Tenant model, with added indexing for the tenant field to optimize database operations. Additionally, the creation of a Tenant instance is automated for new CustomUser entries without a specified tenant. Comprehensive testing ensures these changes align with the objectives for database efficiency and model functionality.

Changes

Files Change Summary
accounts/migrations/..., main/migrations/... Introduced migrations for altering CustomUser and Tenant models, including new fields and indexes.
accounts/models.py, main/models.py Modified CustomUser and Tenant models to include new fields, indexes, and model options.
tests/accounts/..., tests/main/... Updated and added tests for CustomUser and Tenant functionalities, including new fields and model interactions. Adjusted testing setup by removing pytest decorators and introducing a new fixture.
tests/factories.py Introduced TenantFactory and UserFactory for creating model instances in tests.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5e39bb7 and 47f6679.
Files selected for processing (15)
  • accounts/migrations/0002_alter_customuser_options_alter_customuser_tenant_and_more.py (1 hunks)
  • accounts/models.py (1 hunks)
  • main/migrations/0016_tenant_status_tenant_main_tenant_status_883ca8_idx.py (1 hunks)
  • main/models.py (1 hunks)
  • tests/accounts/test_accounts_forms.py (2 hunks)
  • tests/accounts/test_accounts_models.py (3 hunks)
  • tests/accounts/test_accounts_templates.py (1 hunks)
  • tests/conftest.py (1 hunks)
  • tests/factories.py (1 hunks)
  • tests/main/test_main_forms.py (1 hunks)
  • tests/main/test_main_models.py (11 hunks)
  • tests/main/test_main_tasks.py (3 hunks)
  • tests/main/test_main_templates.py (2 hunks)
  • tests/main/test_main_utils.py (4 hunks)
  • tests/main/test_main_views.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • tests/accounts/test_accounts_templates.py
Additional comments: 12
tests/factories.py (1)
  • 8-17: The implementation of TenantFactory and UserFactory using factory_boy is clean and adheres to best practices for generating test data. The use of Faker for the email field in UserFactory is particularly commendable. Consider adding more fields or traits to these factories if future tests require more complex setups.
main/migrations/0016_tenant_status_tenant_main_tenant_status_883ca8_idx.py (1)
  • 6-29: The migration correctly adds a status field with predefined choices to the Tenant model and indexes this field for improved query performance. The use of integer choices is efficient and aligns with the PR objectives. Consider using a more descriptive name for the index to enhance readability and maintainability.
accounts/migrations/0002_alter_customuser_options_alter_customuser_tenant_and_more.py (1)
  • 7-36: The migration accurately reflects the changes to the CustomUser model, including the addition of a tenant field with a related_name and an index for improved performance. The modifications align with the PR objectives and enhance the model's functionality. Consider using a more descriptive name for the index to enhance readability and maintainability.
main/models.py (3)
  • 19-25: The addition of the Status class within the Tenant model is a good implementation for handling predefined status choices. This approach keeps the code clean and makes it easy to add or modify statuses in the future.
  • 28-28: The status field correctly uses the Status class for choices and sets a default value of "Trialing". This aligns with the PR objectives to track the tenant's current status effectively.
  • 34-36: Indexing the status field is a good practice for optimizing database queries, especially when the field is frequently used in filter conditions. This change should improve the performance of queries involving the status field.
tests/main/test_main_utils.py (3)
  • 149-149: Simplifying the dictionary formatting in the sizes key improves readability and aligns with Python's style recommendations. This change makes the test data more straightforward to understand.
  • 177-177: Adjusting the sizes key to represent an item not in stock by providing an empty list is a clear way to mock this scenario in tests. This change is crucial for testing the behavior of the scrape_item function when encountering items without stock.
  • 210-210: The addition of a test case to verify the behavior of scrape_item when an item is not in stock is a good practice. It ensures that the function correctly identifies items without stock, which is important for maintaining accurate inventory data.
tests/main/test_main_views.py (3)
  • 18-19: The separation of update_items from destroy_scrape_interval_task is noted. This change likely improves modularity and clarity in the codebase. However, ensure that any dependencies or interactions between these functions are properly managed to avoid introducing bugs.
  • 276-282: The formatting change in the scrape_items_from_skus call within the test_update_items_view method improves readability. It's good practice to format longer function calls or those with multiple arguments in a way that enhances clarity.
  • 499-499: The handling of the PeriodicTask.DoesNotExist exception in test_interval_task_does_not_exist_exception is appropriate for ensuring robustness in test cases. It's important to verify that the application behaves as expected even when certain conditions are not met, such as the absence of a specific periodic task.

tests/conftest.py Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5e39bb7 and e6ad224.
Files selected for processing (16)
  • accounts/migrations/0002_alter_customuser_options_alter_customuser_tenant_and_more.py (1 hunks)
  • accounts/models.py (1 hunks)
  • main/migrations/0016_tenant_status_tenant_main_tenant_status_883ca8_idx.py (1 hunks)
  • main/models.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/accounts/test_accounts_forms.py (2 hunks)
  • tests/accounts/test_accounts_models.py (3 hunks)
  • tests/accounts/test_accounts_templates.py (1 hunks)
  • tests/conftest.py (1 hunks)
  • tests/factories.py (1 hunks)
  • tests/main/test_main_forms.py (1 hunks)
  • tests/main/test_main_models.py (11 hunks)
  • tests/main/test_main_tasks.py (3 hunks)
  • tests/main/test_main_templates.py (2 hunks)
  • tests/main/test_main_utils.py (4 hunks)
  • tests/main/test_main_views.py (3 hunks)
Files skipped from review as they are similar to previous changes (14)
  • accounts/migrations/0002_alter_customuser_options_alter_customuser_tenant_and_more.py
  • main/migrations/0016_tenant_status_tenant_main_tenant_status_883ca8_idx.py
  • main/models.py
  • tests/accounts/test_accounts_forms.py
  • tests/accounts/test_accounts_models.py
  • tests/accounts/test_accounts_templates.py
  • tests/conftest.py
  • tests/factories.py
  • tests/main/test_main_forms.py
  • tests/main/test_main_models.py
  • tests/main/test_main_tasks.py
  • tests/main/test_main_templates.py
  • tests/main/test_main_utils.py
  • tests/main/test_main_views.py
Additional comments: 3
accounts/models.py (2)
  • 11-17: The addition of the related_name="users" attribute to the tenant field in the CustomUser model is a good practice. It enhances the readability and usability of the reverse relationship from Tenant to CustomUser. This change facilitates easier access to all users associated with a specific tenant, which aligns well with the PR objectives.
  • 19-20: Adding an index to the tenant field in the CustomUser model is a significant improvement for database performance, especially for queries filtering or joining on this field. This change directly addresses one of the PR objectives to optimize database performance by indexing critical fields. It's important to ensure that the migration file for this index addition is correctly generated and included in the PR.
requirements.txt (1)
  • 47-48: The addition of factory-boy==3.3.0 and Faker==23.2.1 to the requirements.txt file is a positive step towards achieving the PR's objective of writing comprehensive tests. factory-boy and Faker are widely used in the Django community for creating realistic test data and model instances, which can significantly improve the quality and maintainability of tests. It's important to ensure that the versions specified are compatible with the rest of the project's dependencies and the Django version being used.

@igorsimb igorsimb merged commit dd09939 into master Feb 24, 2024
1 check passed
@igorsimb igorsimb deleted the status-field branch February 24, 2024 00:03
@igorsimb igorsimb mentioned this pull request Feb 24, 2024
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.

Add Status field to Tenant model, add indexex to CustomUser and Tenant models
1 participant