-
Notifications
You must be signed in to change notification settings - Fork 307
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
test: add serdes/utils.py unit tests #1478
Conversation
WalkthroughThis change introduces a comprehensive test suite for serialization and deserialization utilities. Several new test classes and pytest fixtures have been added to backend/serdes/tests/test_utils.py to validate functionality such as model dependency detection, dependency graph building, topological sorting, self-referencing field detection, object sorting, and domain export. In addition, specific import statements were revised for clarity, and multiple utility functions were introduced in serdes/utils to support these operations. Changes
Sequence Diagram(s)sequenceDiagram
participant T as TestDomainExport
participant U as get_domain_export_objects
participant M as get_model_dependencies
participant G as build_dependency_graph
participant S as topological_sort
participant O as sort_objects_by_self_reference
T->>U: Initiate domain export process
U->>M: Retrieve model dependencies
M-->>U: Return dependencies
U->>G: Build dependency graph
G-->>U: Return graph
U->>S: Topologically sort graph
S-->>U: Return sorted order
U->>O: Sort objects by self-reference
O-->>U: Return sorted objects
U-->>T: Return export data
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
backend/serdes/tests/test_utils.py (1)
448-448
: Rename unused loop variable as suggested by static analysis.
Because “key” is unused, a slight rename improves clarity.Here’s a diff:
-for key, value in export_data.items(): +for _key, value in export_data.items(): assert len(value) == 0🧰 Tools
🪛 Ruff (0.8.2)
448-448: Loop control variable
key
not used within loop bodyRename unused
key
to_key
(B007)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/serdes/tests/test_utils.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
backend/serdes/tests/test_utils.py
448-448: Loop control variable key
not used within loop body
Rename unused key
to _key
(B007)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: startup-functional-test (3.12)
- GitHub Check: startup-docker-compose-test
- GitHub Check: enterprise-startup-functional-test (3.12)
- GitHub Check: functional-tests (3.12, chromium)
- GitHub Check: enterprise-startup-docker-compose-test
- GitHub Check: enterprise-functional-tests (3.12, chromium)
- GitHub Check: test (3.12)
- GitHub Check: build (3.12)
🔇 Additional comments (13)
backend/serdes/tests/test_utils.py (13)
1-14
: Docstring introduction looks good.
These lines provide a clear overview of the test suite’s purpose and coverage.
16-38
: Import statements are well-structured.
All imported utilities and models appear to be used appropriately in subsequent tests.
44-58
: Fixture 'basic_folder_structure' is clear and maintains readability.
The docstring is concise, and the returned folder structure is intuitive.
60-68
: Fixture 'framework_fixture' is properly validating library presence.
Asserting the library’s existence ensures tests fail early when the required data is missing.
70-80
: Fixture 'risk_matrix_fixture' follows a similar and consistent pattern.
Pulling library data and loading it is straightforward.
82-97
: Fixture 'complex_model_structure' sets up related models effectively.
The code properly returns a dictionary referencing each created model for test usage.
99-171
: Fixture 'complex_domain_structure' neatly demonstrates advanced relational setups.
This fixture thoroughly covers multiple object relationships for robust test scenarios.
176-215
: Tests in 'TestModelDependencies' thoroughly validate foreign key and M2M detection.
The coverage ensures multiple relationship types are checked.
219-248
: Tests in 'TestDependencyGraph' confirm graph construction logic across various scenarios.
The checks for folder inheritance and empty inputs are comprehensive.
252-282
: Tests in 'TestTopologicalSort' handle complex and edge cases well.
Self-dependency handling is tested and ensures the function returns a consistent result.
286-313
: Tests in 'TestSelfReferencingField' correctly verify varied self-referencing patterns.
The coverage for models that do and do not contain self-references is adequate.
317-369
: Tests in 'TestObjectSorting' validate multi-layer dependencies and no-parent scenarios.
Handling complex hierarchies, invalid parents, and empty lists is robust.
373-471
: Domain export tests offer wide coverage of folder trees, subfolders, and cross-linked objects.
The approach ensures both normal and empty-folder scenarios are handled.🧰 Tools
🪛 Ruff (0.8.2)
448-448: Loop control variable
key
not used within loop bodyRename unused
key
to_key
(B007)
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.
These are a great addition, however we should also cover failing cases. Still, merging this for immediate value.
Summary by CodeRabbit