Feature: Retrive site information trough webservice#7
Merged
Conversation
This commit adds a new function to retrieve site information using the `core_webservice_get_site_info` webservice function. A new `site` command has been added to the CLI to expose this functionality. The output can be formatted as a table or as JSON. A test has been added to ensure the new function works as expected. The test runs against a real Moodle environment.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a new CLI command group for retrieving Moodle site information through webservice APIs. The feature allows users to fetch comprehensive site details and display them in either table or JSON format.
- Adds a new
sitecommand group withinfosubcommand to the CLI - Introduces structured data models for site information, functions, and advanced features
- Extends the session API with a generic
callmethod for arbitrary webservice requests
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/py_moodle/site.py |
Defines data models (SiteInfo, SiteFunction, AdvancedFeature) and implements get_site_info function |
src/py_moodle/session.py |
Adds generic call method to MoodleSession for webservice API calls |
src/py_moodle/cli/site.py |
Implements site CLI command group with info subcommand and JSON/table output options |
src/py_moodle/cli/app.py |
Registers the new site command group with the main CLI application |
tests/test_site.py |
Adds integration test for get_site_info function |
Comments suppressed due to low confidence (1)
tests/test_site.py:7
- [nitpick] The function name 'test_get_site_info_real' could be clearer. Consider renaming to 'test_get_site_info_integration' or 'test_get_site_info_with_live_session' to better indicate this is an integration test.
def test_get_site_info_real(request):
Comment on lines
+28
to
+35
| class DataclassEncoder(json.JSONEncoder): | ||
| def default(self, o): | ||
| from dataclasses import asdict, is_dataclass | ||
|
|
||
| if is_dataclass(o): | ||
| return asdict(o) | ||
| return super().default(o) | ||
|
|
There was a problem hiding this comment.
The DataclassEncoder class is defined inside the function scope. Consider moving this to module level or a utility module to improve reusability and avoid recreating the class on each function call.
Suggested change
| class DataclassEncoder(json.JSONEncoder): | |
| def default(self, o): | |
| from dataclasses import asdict, is_dataclass | |
| if is_dataclass(o): | |
| return asdict(o) | |
| return super().default(o) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds a new "site" command group to the CLI, enabling users to fetch and display detailed Moodle site information. It introduces new data models for site details, extends the session API for generic webservice calls, and provides test coverage for the new functionality.
New CLI feature: Site info commands
sitecommand group to the CLI, allowing users to retrieve site information viapy-moodle site info, with output available in both table and JSON formats (src/py_moodle/cli/app.py,src/py_moodle/cli/site.py). [1] [2] [3]Data modeling and API integration
SiteInfo,SiteFunction,AdvancedFeature) to model the site information returned by the Moodle API, and implemented theget_site_infofunction to fetch and parse this data (src/py_moodle/site.py).Session API improvements
callmethod toMoodleSessionfor making arbitrary Moodle webservice API calls, which is now used to implement site info retrieval (src/py_moodle/session.py). [1] [2]Testing
get_site_infocorrectly retrieves and parses site information from a real Moodle environment (tests/test_site.py).