-
-
Notifications
You must be signed in to change notification settings - Fork 271
Implement resolver for a list of project health metrics #1676
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
arkid15r
merged 7 commits into
OWASP:main
from
ahmedxgouda:dashboard/internal-metrics-resolver
Jul 3, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
310a525
Add project name and filters
ahmedxgouda 9ab9a19
Update tests
ahmedxgouda d5fc5f4
Update tests
ahmedxgouda 53cecd4
Update tests
ahmedxgouda 0d03f15
fix importing
ahmedxgouda 0d7b0a6
Add filter tests
ahmedxgouda 7ed3923
Handle merge
ahmedxgouda 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
Empty file.
22 changes: 22 additions & 0 deletions
22
backend/apps/owasp/graphql/filters/project_health_metrics.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Filters for OWASP ProjectHealthMetrics.""" | ||
|
|
||
| import strawberry | ||
| import strawberry_django | ||
| from django.db.models import Q | ||
|
|
||
| from apps.owasp.models.enums.project import ProjectLevel | ||
| from apps.owasp.models.project_health_metrics import ProjectHealthMetrics | ||
|
|
||
|
|
||
| @strawberry_django.filter_type(ProjectHealthMetrics, lookups=True) | ||
| class ProjectHealthMetricsFilter: | ||
| """Filter for ProjectHealthMetrics.""" | ||
|
|
||
| score: strawberry.auto | ||
|
|
||
| @strawberry_django.filter_field | ||
| # prefix is required for strawberry to work with nested filters | ||
| # Q is the return type for the filter | ||
| def level(self, value: str, prefix: str): | ||
| """Filter by project level.""" | ||
| return Q(project__level=ProjectLevel(value)) if value else Q() | ||
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
Empty file.
26 changes: 26 additions & 0 deletions
26
backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """Test cases for the ProjectHealthMetricsFilter.""" | ||
|
|
||
| from apps.owasp.graphql.filters.project_health_metrics import ProjectHealthMetricsFilter | ||
| from apps.owasp.models.enums.project import ProjectLevel | ||
|
|
||
|
|
||
| class TestProjectHealthMetricsFilter: | ||
| """Test cases for ProjectHealthMetricsFilter class.""" | ||
|
|
||
| def test_filter_has_strawberry_definition(self): | ||
| """Check if ProjectHealthMetricsFilter has valid Strawberry definition.""" | ||
| assert hasattr(ProjectHealthMetricsFilter, "__strawberry_definition__") | ||
|
|
||
| def test_filter_fields(self): | ||
| """Test if the filter fields are correctly defined.""" | ||
| filter_fields = { | ||
| field.name for field in ProjectHealthMetricsFilter.__strawberry_definition__.fields | ||
| } | ||
| expected_fields = {"score", "level"} | ||
| assert expected_fields.issubset(filter_fields) | ||
|
|
||
| def test_filtering(self): | ||
| """Test filtering by project level and score.""" | ||
| filter_instance = ProjectHealthMetricsFilter(level="flagship", score=50) | ||
| assert filter_instance.level == ProjectLevel.FLAGSHIP | ||
| assert filter_instance.score == 50 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.