Repository navigation
refactor: enhance model validation and loading logic in drawers #7839
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
Merged
Merged
Changes from all commits
Commits
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
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
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.
Here's a review of the added test code:
Issues / Observations
Whitespace-only credential handling is implicit but unverified.
test_model_list_post_requires_provider_credential_fieldspasses"api_base": " "(a space) and expects it to be treated as missing. This is fine if the production code strips values — but the test relies on that undocumented behavior. Consider also asserting a whitespace-onlyapi_keyto lock in stripping for both fields, or add a separate test ifstrip()isn't guaranteed.Magic strings duplicated across tests.
"test_provider", field names, and labels are repeated. Extract constants or a sharedsetUp/helper to avoid drift between the two tests.Patch target string duplication.
"models_provider.views.provide.ModelProvideConstants"appears twice. A module-level constant likePATCH_PROVIDER_CONSTANTS = "..."improves maintainability and typo safety.Weak assertion on cache call.
cache_model_list.assert_called_once()doesn't verify arguments. Assert the payload (model list, provider, type, credentials) to ensure caching keyed correctly — a bug could cache under the wrong provider otherwise.provider.get_model_type_list.return_valueis never asserted.It's set up but not verified. Either assert it was called with expected args, or remove the setup if the endpoint doesn't require validation here. If validation of
model_typeagainst this list exists, add a negative test for an invalidmodel_type.Mocking external constants vs. injectable dependency.
Patching a module-global dict (
ModelProvideConstants) couples the test to implementation detail. Consider injecting the provider registry intoModelList(constructor/class attr) for cleaner, less brittle tests.SimpleNamespace(data=...)for request.Works, but using Django's
RequestFactory(or the actual framework's test client) would exercise middleware/serialization and catch real integration issues (e.g., multi-value form fields, non-string types).Only success/validation paths covered.
Missing tests worth adding:
provider→ appropriate error (404/BadRequest).model_type.provider.get_model_list→ how is it propagated/wrapped?Assertion style inconsistency.
Mixes
assertEqual(200, response.status_code)withassertIn(..., str(...)). Prefer consistentself.assertEqual(response.status_code, 200)ordering; also asserting the body structure (not juststr(context.exception.message)) would be stronger (e.g., structured error codes/fields).allow_builtin_fallback=Falseis asserted but not tested in the alternative branch.Add a test where
allow_builtin_fallbackis passed asTruein the request to cover that path.Potential naming confusion.
test_model_list_returns_provider_models(existing) suggests GET-like behavior; new tests cover POST. Confirm the method overload is intentional, or split into separate endpoints/tests for clarity.No assertion that
get_model_credential().to_form_list()is called once.Adding
provider.get_model_credential.assert_called_once()guards against redundant instantiation.Suggested Minimal Refactor
Then use
patch(PROVIDER_PATCH, ...)consistently and assert cached payload:Overall the tests are reasonably focused; main improvements are stronger assertions on cache arguments, reducing duplication, and adding coverage for error/fallback branches.