Skip to content

Add backend tests for certificate generation - #5342

Open
anurag2787 wants to merge 12 commits into
OWASP:feature/contributor-recognition-programfrom
anurag2787:score-calculation-test
Open

Add backend tests for certificate generation#5342
anurag2787 wants to merge 12 commits into
OWASP:feature/contributor-recognition-programfrom
anurag2787:score-calculation-test

Conversation

@anurag2787

@anurag2787 anurag2787 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Proposed change

Add backend tests for certificate generation

Resolves #5199

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran all required checks and tests locally; all warnings addressed and failures resolved
  • I used AI for code, documentation, tests, or communication related to this PR

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 51d48e76-1457-4c6b-be0a-c7ba18bef075

📥 Commits

Reviewing files that changed from the base of the PR and between 5693a71 and 89a7586.

📒 Files selected for processing (1)
  • backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py

Summary by CodeRabbit

  • Bug Fixes

    • Improved certificate recalculation reliability by capturing and reporting unexpected issuance failures, including failures in the final batch.
    • Improved tier handling during certificate issuance.
  • Tests

    • Expanded coverage for certificate issuance, verification, lookup, provider handling, score calculation, tier assignment, leaderboard data, and scoring behavior.
    • Added validation for recalculation failures, invalid or missing certificates, duplicate certificates, and users without linked accounts.

Walkthrough

The change adds backend tests for OWASP contributor certificates, score recalculation, GraphQL access, management commands, certificate providers, and CRP model representations. Final-batch certificate issuance now records unexpected failures.

Changes

OWASP certificate and scoring coverage

Layer / File(s) Summary
Certificate issuance and provider behavior
backend/tests/unit/apps/owasp/models/crp/certificate_test.py, backend/tests/unit/apps/owasp/utils/certificate_provider_test.py, backend/src/apps/owasp/utils/score_calculator.py
Tests cover certificate generation, issuance outcomes, provider failures, successful creation, provider selection, unknown provider configuration, and enum-based tier passing.
Score recalculation and certificate failure tracking
backend/src/apps/owasp/utils/score_calculator.py, backend/tests/unit/apps/owasp/utils/score_calculator_test.py
The final batch records unexpected certificate issuance exceptions. Calculator tests cover scoring, batching, persistence, certificate issuance, empty-user handling, and failure statistics.
Recalculation command reporting
backend/tests/unit/apps/owasp/management/commands/owasp_crp_recalculate_scores_test.py
Tests verify calculator invocation, successful output, and CommandError reporting for certificate failures.
Certificate queries and model representations
backend/tests/unit/apps/owasp/api/internal/nodes/certificate_test.py, backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py, backend/tests/unit/apps/owasp/models/crp/*_test.py
GraphQL tests cover certificate fields, resolvers, lookup behavior, and active certificate selection. Model tests cover string representations for scores, snapshots, and scoring weights.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • OWASP/Nest#4842: Extends ContributionScoreCalculator with related certificate handling.
  • OWASP/Nest#4922: Covers ContributionScoreCalculator certificate issuance and failure handling.
  • OWASP/Nest#4962: Adds tests for certificate issuance and related score recalculation logic.

Suggested reviewers: kasya

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary backend certificate testing work, although it does not mention related Contributor Recognition Program coverage.
Description check ✅ Passed The description directly states that the PR adds backend tests for certificate generation and links the relevant issue.
Linked Issues check ✅ Passed The PR adds backend unit coverage for certificate generation and related CRP behavior, satisfying the backend objective in [#5199].
Out of Scope Changes check ✅ Passed The changes remain within backend testing and certificate recalculation behavior for the Contributor Recognition Program.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/apps/owasp/utils/score_calculator.py (1)

305-355: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated batch persist-and-issue logic.

The mid-loop batch block (lines 305-330) and the final leftover-batch block (lines 331-355) now contain the same bulk-save-then-issue-certificates sequence, including identical except CertificateIssuanceError and except Exception handling. This change makes both blocks fully mirror each other. Extract a single helper method that takes contribution_scores, pending_scores, and failed_certificates, and call it from both places, to keep the exception-handling policy in one location and prevent future edits from drifting out of sync again.

♻️ Proposed refactor
+    def _persist_and_issue_certificates(
+        self,
+        contribution_scores: list[ContributionScore],
+        pending_scores: list[ContributionScore],
+        failed_certificates: list[tuple[str, Exception]],
+    ) -> None:
+        BulkSaveModel.bulk_save(
+            ContributionScore, contribution_scores, fields=["value", "tier"]
+        )
+        for pending_score in pending_scores:
+            try:
+                Certificate.issue_certificate(
+                    pending_score.github_user,
+                    pending_score.value,
+                    TierChoices(pending_score.tier),
+                )
+            except CertificateIssuanceError as e:
+                logger.exception(
+                    "Failed to issue certificate for user %s",
+                    pending_score.github_user.login,
+                )
+                failed_certificates.append((pending_score.github_user.login, e))
+            except Exception as e:
+                logger.exception(
+                    "Unexpected certificate processing error for user %s",
+                    pending_score.github_user.login,
+                )
+                failed_certificates.append((pending_score.github_user.login, e))
+
             if len(contribution_scores) >= self.BATCH_SIZE:
-                BulkSaveModel.bulk_save(
-                    ContributionScore, contribution_scores, fields=["value", "tier"]
-                )
-                for pending_score in pending_scores:
-                    try:
-                        ...
-                    except Exception as e:
-                        ...
-                        failed_certificates.append((pending_score.github_user.login, e))
+                self._persist_and_issue_certificates(
+                    contribution_scores, pending_scores, failed_certificates
+                )
                 pending_scores.clear()
                 contribution_scores.clear()

         if contribution_scores:
-            BulkSaveModel.bulk_save(
-                ContributionScore, contribution_scores, fields=["value", "tier"]
-            )
-            for pending_score in pending_scores:
-                try:
-                    ...
-                except Exception as e:
-                    ...
-                    failed_certificates.append((pending_score.github_user.login, e))
+            self._persist_and_issue_certificates(
+                contribution_scores, pending_scores, failed_certificates
+            )
             pending_scores.clear()
             contribution_scores.clear()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/apps/owasp/utils/score_calculator.py` around lines 305 - 355,
Extract the duplicated bulk-save and certificate-issuance sequence into a single
helper method that accepts contribution_scores, pending_scores, and
failed_certificates. Move the existing exception handling into that helper, then
replace both the mid-loop batch block and final leftover-batch block with calls
to it while preserving the existing clearing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/tests/unit/apps/owasp/models/crp/certificate_test.py`:
- Line 1: Prepend the project's standard copyright header to each new test file:
backend/tests/unit/apps/owasp/models/crp/certificate_test.py lines 1-1,
backend/tests/unit/apps/owasp/utils/certificate_provider_test.py lines 1-1,
backend/tests/unit/apps/owasp/utils/score_calculator_test.py lines 1-1, and
backend/tests/unit/apps/owasp/management/commands/owasp_crp_recalculate_scores_test.py
lines 1-1; leave the existing test imports and contents unchanged.

In `@backend/tests/unit/apps/owasp/models/crp/scoring_weight_test.py`:
- Around line 13-14: Update the test around the ScoringWeight string
representation to remove the get_event_type_display patch and invoke the real
EventTypeChoices.PR_MERGED display path. Keep the assertion verifying the
expected event label and “25 points” suffix so incorrect choice labels are
detected.

In `@backend/tests/unit/apps/owasp/utils/score_calculator_test.py`:
- Around line 189-431: Extract the repeated queryset setup from the six
recalculate_all tests into a shared helper or fixture, such as
_mock_users_queryset(mock_user_class, users), and centralize the empty
PullRequest and Issue queryset configuration as well. Update each named test to
reuse the shared setup while preserving its user list and count behavior.
- Around line 432-460: Update ContributionScoreCalculator.recalculate_user to
pass a TierChoices value, matching recalculate_all’s existing TierChoices(tier)
pattern, when calling Certificate.issue_certificate. Preserve the returned tier
string and score persistence behavior, and update test_recalculate_user to
assert the certificate call receives the TierChoices representation.

---

Outside diff comments:
In `@backend/src/apps/owasp/utils/score_calculator.py`:
- Around line 305-355: Extract the duplicated bulk-save and certificate-issuance
sequence into a single helper method that accepts contribution_scores,
pending_scores, and failed_certificates. Move the existing exception handling
into that helper, then replace both the mid-loop batch block and final
leftover-batch block with calls to it while preserving the existing clearing
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9a116b17-b343-40c0-bea1-ed1d1b2435d5

📥 Commits

Reviewing files that changed from the base of the PR and between 0106c69 and a96f9ce.

📒 Files selected for processing (10)
  • backend/src/apps/owasp/utils/score_calculator.py
  • backend/tests/unit/apps/owasp/api/internal/nodes/certificate_test.py
  • backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_crp_recalculate_scores_test.py
  • backend/tests/unit/apps/owasp/models/crp/certificate_test.py
  • backend/tests/unit/apps/owasp/models/crp/contribution_score_test.py
  • backend/tests/unit/apps/owasp/models/crp/leaderboard_snapshot_test.py
  • backend/tests/unit/apps/owasp/models/crp/scoring_weight_test.py
  • backend/tests/unit/apps/owasp/utils/certificate_provider_test.py
  • backend/tests/unit/apps/owasp/utils/score_calculator_test.py

Comment thread backend/tests/unit/apps/owasp/models/crp/certificate_test.py
Comment thread backend/tests/unit/apps/owasp/models/crp/scoring_weight_test.py Outdated
Comment thread backend/tests/unit/apps/owasp/utils/score_calculator_test.py Outdated
Comment thread backend/tests/unit/apps/owasp/utils/score_calculator_test.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/apps/owasp/utils/score_calculator.py (1)

305-355: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated certificate-issuance loop into a helper method.

The mid-batch flush (lines 309-327) and the final-batch flush (lines 335-353) contain the identical try/except block for issuing certificates and recording failures. This diff added the generic except Exception clause to both blocks, completing the duplication. Extract a shared helper, for example _issue_certificates_for_batch(pending_scores, failed_certificates), and call it from both flush points to keep the two code paths from diverging in future changes.

♻️ Proposed refactor
+    def _issue_certificates_for_batch(
+        self,
+        pending_scores: list[ContributionScore],
+        failed_certificates: list[tuple[str, Exception]],
+    ) -> None:
+        """Issue certificates for a batch of pending scores, recording failures."""
+        for pending_score in pending_scores:
+            try:
+                Certificate.issue_certificate(
+                    pending_score.github_user,
+                    pending_score.value,
+                    TierChoices(pending_score.tier),
+                )
+            except CertificateIssuanceError as e:
+                logger.exception(
+                    "Failed to issue certificate for user %s",
+                    pending_score.github_user.login,
+                )
+                failed_certificates.append((pending_score.github_user.login, e))
+            except Exception as e:
+                logger.exception(
+                    "Unexpected certificate processing error for user %s",
+                    pending_score.github_user.login,
+                )
+                failed_certificates.append((pending_score.github_user.login, e))
+
             if len(contribution_scores) >= self.BATCH_SIZE:
                 BulkSaveModel.bulk_save(
                     ContributionScore, contribution_scores, fields=["value", "tier"]
                 )
-                for pending_score in pending_scores:
-                    try:
-                        Certificate.issue_certificate(
-                            pending_score.github_user,
-                            pending_score.value,
-                            TierChoices(pending_score.tier),
-                        )
-                    except CertificateIssuanceError as e:
-                        logger.exception(
-                            "Failed to issue certificate for user %s",
-                            pending_score.github_user.login,
-                        )
-                        failed_certificates.append((pending_score.github_user.login, e))
-                    except Exception as e:
-                        logger.exception(
-                            "Unexpected certificate processing error for user %s",
-                            pending_score.github_user.login,
-                        )
-                        failed_certificates.append((pending_score.github_user.login, e))
+                self._issue_certificates_for_batch(pending_scores, failed_certificates)
                 pending_scores.clear()
                 contribution_scores.clear()

         if contribution_scores:
             BulkSaveModel.bulk_save(
                 ContributionScore, contribution_scores, fields=["value", "tier"]
             )
-            for pending_score in pending_scores:
-                try:
-                    Certificate.issue_certificate(
-                        pending_score.github_user,
-                        pending_score.value,
-                        TierChoices(pending_score.tier),
-                    )
-                except CertificateIssuanceError as e:
-                    logger.exception(
-                        "Failed to issue certificate for user %s",
-                        pending_score.github_user.login,
-                    )
-                    failed_certificates.append((pending_score.github_user.login, e))
-                except Exception as e:
-                    logger.exception(
-                        "Unexpected certificate processing error for user %s",
-                        pending_score.github_user.login,
-                    )
-                    failed_certificates.append((pending_score.github_user.login, e))
+            self._issue_certificates_for_batch(pending_scores, failed_certificates)
             pending_scores.clear()
             contribution_scores.clear()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/apps/owasp/utils/score_calculator.py` around lines 305 - 355,
Extract the duplicated certificate-processing try/except loop into a shared
helper such as _issue_certificates_for_batch, preserving both
CertificateIssuanceError and generic exception handling and failed_certificates
recording. Replace the loops in both the mid-batch and final flush paths of the
score-calculation method with calls to this helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@backend/src/apps/owasp/utils/score_calculator.py`:
- Around line 305-355: Extract the duplicated certificate-processing try/except
loop into a shared helper such as _issue_certificates_for_batch, preserving both
CertificateIssuanceError and generic exception handling and failed_certificates
recording. Replace the loops in both the mid-batch and final flush paths of the
score-calculation method with calls to this helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 707a4d31-674d-491d-9ca4-e2033b3439f2

📥 Commits

Reviewing files that changed from the base of the PR and between a96f9ce and 612a03c.

📒 Files selected for processing (8)
  • backend/src/apps/owasp/utils/score_calculator.py
  • backend/tests/unit/apps/owasp/api/internal/nodes/certificate_test.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_crp_recalculate_scores_test.py
  • backend/tests/unit/apps/owasp/models/crp/__init__.py
  • backend/tests/unit/apps/owasp/models/crp/certificate_test.py
  • backend/tests/unit/apps/owasp/models/crp/leaderboard_snapshot_test.py
  • backend/tests/unit/apps/owasp/models/crp/scoring_weight_test.py
  • backend/tests/unit/apps/owasp/utils/score_calculator_test.py

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 31, 2026
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Jul 31, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 8 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

3 similar comments
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@anurag2787

Copy link
Copy Markdown
Collaborator Author

Hi @arkid15r pr is ready for review please let me know if any changes required Thanks!

@anurag2787 anurag2787 added the gsoc2026:anurag2787 anurag2787's GSoC 2026 related work label Aug 3, 2026
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
@anurag2787
anurag2787 force-pushed the score-calculation-test branch from 612a03c to ede615d Compare August 3, 2026 02:15

@arkid15r arkid15r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see these tests ran succesfuly.

@anurag2787

Copy link
Copy Markdown
Collaborator Author

I don't see these tests ran succesfuly.

Hi @arkid15r the test are getting pass locally and the ci failure is related to sync so are you talking about the Test run by CI??

Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/tests/unit/apps/owasp/models/crp/__init__.py`:
- Line 1: Add the repository-standard copyright header to the package
initializer to resolve Ruff CPY001, or explicitly exempt this initializer in the
Ruff configuration if omitting the header is intentional.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: db125d5d-fa2b-4b7d-8b1f-e5618800ad44

📥 Commits

Reviewing files that changed from the base of the PR and between 612a03c and a67a449.

📒 Files selected for processing (1)
  • backend/tests/unit/apps/owasp/models/crp/__init__.py

Comment thread backend/tests/unit/apps/owasp/models/crp/__init__.py Outdated
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Aug 12, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@anurag2787

Copy link
Copy Markdown
Collaborator Author

I don't see these tests ran succesfuly.

Hi @arkid15r the test are getting pass locally and the ci failure is related to sync so are you talking about the Test run by CI??

Hi @arkid15r i checked the latest CI run the workflow is triggering correctly but the backend tests aren't being reached because trivy and the dependency audit are failing due to a dependency version mismatch so to fix this i have raised pr #5408 to fix that

@anurag2787
anurag2787 marked this pull request as draft August 12, 2026 05:48
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.73%. Comparing base (90ce862) to head (8900d88).
⚠️ Report is 2 commits behind head on feature/contributor-recognition-program.

Additional details and impacted files

Impacted file tree graph

@@                             Coverage Diff                             @@
##           feature/contributor-recognition-program    #5342      +/-   ##
===========================================================================
+ Coverage                                    97.93%   98.73%   +0.79%     
===========================================================================
  Files                                          555      555              
  Lines                                        17695    17701       +6     
  Branches                                      2524     2525       +1     
===========================================================================
+ Hits                                         17330    17477     +147     
+ Misses                                         263      122     -141     
  Partials                                       102      102              
Flag Coverage Δ
backend 99.21% <100.00%> (+1.08%) ⬆️
frontend 97.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/src/apps/owasp/utils/score_calculator.py 97.47% <100.00%> (+74.78%) ⬆️

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77e0f88...8900d88. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py`:
- Around line 16-18: Update the CertificateQuery tests to use the defined
my_certificates field and resolver instead of my_certificate, including all
affected assertions and method calls in the covered test cases. Adjust expected
results to assert [] when github_user is absent and the ordered QuerySet when it
is present.

In `@backend/tests/unit/apps/owasp/models/crp/certificate_test.py`:
- Line 46: Rename every unused patch-injected mock parameter by prefixing it
with an underscore while preserving decorator order and test behavior: update
mock_exit and mock_enter in certificate_test.py at lines 46, 65, 82, and 102;
update mock_load and the other unused injected mocks in score_calculator_test.py
at lines 59, 75, 103, 109, 116, 144, 166, 196, 228-230, 270-272, 306-310, 349,
380-384, 419-423, and 451. Do not alter mocks that are actually referenced.

In `@backend/tests/unit/apps/owasp/utils/score_calculator_test.py`:
- Around line 18-25: Remove the unused mock_weights pytest fixture and remove
its parameter from test_load_scoring_weights. Leave the test’s locally created
weight mocks and remaining setup unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9aae6fb2-a04c-42ff-a9ac-2cc002790017

📥 Commits

Reviewing files that changed from the base of the PR and between 61c0a4b and 5693a71.

📒 Files selected for processing (11)
  • backend/src/apps/owasp/utils/score_calculator.py
  • backend/tests/unit/apps/owasp/api/internal/nodes/certificate_test.py
  • backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py
  • backend/tests/unit/apps/owasp/management/commands/owasp_crp_recalculate_scores_test.py
  • backend/tests/unit/apps/owasp/models/crp/__init__.py
  • backend/tests/unit/apps/owasp/models/crp/certificate_test.py
  • backend/tests/unit/apps/owasp/models/crp/contribution_score_test.py
  • backend/tests/unit/apps/owasp/models/crp/leaderboard_snapshot_test.py
  • backend/tests/unit/apps/owasp/models/crp/scoring_weight_test.py
  • backend/tests/unit/apps/owasp/utils/certificate_provider_test.py
  • backend/tests/unit/apps/owasp/utils/score_calculator_test.py

Comment thread backend/tests/unit/apps/owasp/api/internal/queries/certificate_test.py Outdated
Comment thread backend/tests/unit/apps/owasp/models/crp/certificate_test.py
Comment thread backend/tests/unit/apps/owasp/utils/score_calculator_test.py Outdated
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Aug 12, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 12, 2026
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Aug 12, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@anurag2787
anurag2787 marked this pull request as ready for review August 12, 2026 17:52
@anurag2787
anurag2787 requested a review from arkid15r August 12, 2026 17:53
pending_score.github_user.login,
)
failed_certificates.append((pending_score.github_user.login, e))
except Exception as e:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this wide exception catch here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this earlier because some tests were failing and removing them was causing the coverage to drop but while checking it again i found the issue and fixed it so the tests are no longer failing

Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Aug 15, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@anurag2787
anurag2787 marked this pull request as draft August 15, 2026 12:44
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@sonarqubecloud

Copy link
Copy Markdown

@anurag2787
anurag2787 marked this pull request as ready for review August 16, 2026 09:56
@anurag2787
anurag2787 requested a review from arkid15r August 16, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend backend-tests gsoc2026:anurag2787 anurag2787's GSoC 2026 related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants