Skip to content
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: fix AllDebrid downloader tests #922

Conversation

the-eversio
Copy link
Contributor

@the-eversio the-eversio commented Nov 29, 2024

Pull Request Check List

  • Added tests for changed code.

Description: Fix AllDebrid downloader tests

The tests were broken through the many recent refactors, as well as the API changes
AllDebrid made recently.
This PR updates the tests to ensure it conforms to the BaseDownloader API, removes
some cruft, and adds a fixture for the magnet/files endpoint (which we now depend on).

Summary by CodeRabbit

  • New Features

    • Introduced optional agent attribute in the AllDebrid request parameters for enhanced customization.
    • Added new methods for managing torrents, including add_torrent, delete_torrent, and select_files.
    • New JSON files added to support testing with structured data for magnet files and user information.
  • Bug Fixes

    • Improved readability and consistency in method signatures and class constructors.
  • Tests

    • Restructured tests to utilize a new request handler for better organization and clarity in API interactions.

Copy link
Contributor

coderabbitai bot commented Nov 29, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces several modifications to the alldebrid.py file, enhancing code readability through formatting improvements and structural adjustments. Key changes include the addition of an optional agent attribute in the AllDebridBaseRequestParameters class and reformatting of constructors in the AllDebridRequestHandler and AllDebridAPI classes. The test_alldebrid_downloader.py file has been significantly updated to reflect a new request handling approach, centralizing API request execution. Additionally, two new JSON files have been added for testing user and magnet file data.

Changes

File Path Change Summary
src/program/services/downloaders/alldebrid.py - Added optional agent attribute to AllDebridBaseRequestParameters class.
- Reformatted constructors for AllDebridRequestHandler and AllDebridAPI for readability.
- Updated method signatures for get_instant_availability, add_torrent, delete_torrent, and others for consistency.
src/tests/test_alldebrid_downloader.py - Removed direct API call functions; introduced AllDebridRequestHandler for centralized API requests.
- Updated downloader fixture and tests to use the new request handler.
- Added validation test for the downloader.
src/tests/test_data/alldebrid_magnet_files.json - Introduced a new JSON file with structured data for magnet files, including success status and file details.
src/tests/test_data/alldebrid_user.json - Added a new JSON file containing user information, including premium status and expiration timestamp.

Possibly related PRs

Suggested reviewers

  • davidemarcoli
  • Gaisberg

Poem

🐇 In the code where rabbits play,
Improvements hop in every way.
With cleaner lines and tests anew,
Our downloader's ready, swift, and true!
JSONs added, data bright,
Hooray for changes, what a sight! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
src/tests/test_alldebrid_downloader.py (3)

8-8: Remove unused import AllDebridRequestHandler

The imported AllDebridRequestHandler is not used in this file.

Apply this diff to remove the unused import:

 from program.services.downloaders.alldebrid import (
     AllDebridDownloader,
-    AllDebridRequestHandler,
 )
🧰 Tools
🪛 Ruff (0.8.0)

8-8: program.services.downloaders.alldebrid.AllDebridRequestHandler imported but unused

Remove unused import: program.services.downloaders.alldebrid.AllDebridRequestHandler

(F401)


59-59: Simplify assertion by removing unnecessary comparison to True

In Python, you can assert the expression directly without comparing to True.

Apply this diff:

-def test_validate(downloader):
-    assert downloader.validate() == True
+def test_validate(downloader):
+    assert downloader.validate()
🧰 Tools
🪛 Ruff (0.8.0)

59-59: Avoid equality comparisons to True; use if downloader.validate(): for truth checks

Replace with downloader.validate()

(E712)


74-74: Use is None when comparing to None

In Python, comparisons to None should use is None rather than == None.

Apply this diff:

-    assert downloader.select_files(MAGNET_ID, [1, 2, 3]) == None
+    assert downloader.select_files(MAGNET_ID, [1, 2, 3]) is None
🧰 Tools
🪛 Ruff (0.8.0)

74-74: Comparison to None should be cond is None

Replace with cond is None

(E711)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc7ed05 and cbae948.

📒 Files selected for processing (4)
  • src/program/services/downloaders/alldebrid.py (9 hunks)
  • src/tests/test_alldebrid_downloader.py (3 hunks)
  • src/tests/test_data/alldebrid_magnet_files.json (1 hunks)
  • src/tests/test_data/alldebrid_user.json (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/program/services/downloaders/alldebrid.py
  • src/tests/test_data/alldebrid_magnet_files.json
  • src/tests/test_data/alldebrid_user.json
🧰 Additional context used
🪛 Ruff (0.8.0)
src/tests/test_alldebrid_downloader.py

8-8: program.services.downloaders.alldebrid.AllDebridRequestHandler imported but unused

Remove unused import: program.services.downloaders.alldebrid.AllDebridRequestHandler

(F401)


59-59: Avoid equality comparisons to True; use if downloader.validate(): for truth checks

Replace with downloader.validate()

(E712)


74-74: Comparison to None should be cond is None

Replace with cond is None

(E711)


78-78: Local variable torrent_info is assigned to but never used

Remove assignment to unused variable torrent_info

(F841)


83-83: Comparison to None should be cond is None

Replace with cond is None

(E711)

🔇 Additional comments (1)
src/tests/test_alldebrid_downloader.py (1)

145-150: Ensure test data files exist and paths are correct

Verify that the file alldebrid_magnet_files.json exists at the specified path and is accessible during test execution.

Run the following script to check for the existence of the required test data file:

✅ Verification successful

Test data file exists at the specified path

The file alldebrid_magnet_files.json exists at the expected location src/tests/test_data/alldebrid_magnet_files.json, confirming that the test will be able to access the required test data.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if 'alldebrid_magnet_files.json' exists in 'src/tests/test_data/'

# Test: Find the file. Expect: Path to the file if it exists.
fd 'alldebrid_magnet_files.json' src/tests/test_data/

Length of output: 101

src/tests/test_alldebrid_downloader.py Outdated Show resolved Hide resolved
src/tests/test_alldebrid_downloader.py Outdated Show resolved Hide resolved
src/tests/test_alldebrid_downloader.py Outdated Show resolved Hide resolved

def test_get_instant_availability(downloader):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is currently failing due to bugs in the downloader, @dreulavelle has a fix in his branch

@the-eversio the-eversio marked this pull request as draft November 29, 2024 10:36
@the-eversio the-eversio changed the base branch from main to feature/uncached_downloading November 29, 2024 11:45
@the-eversio the-eversio force-pushed the fix-alldebrid-tests branch 2 times, most recently from af5d32b to 476e4c7 Compare November 29, 2024 11:51
@the-eversio the-eversio marked this pull request as ready for review November 29, 2024 11:56
@Gaisberg Gaisberg merged commit 6b3d5ac into rivenmedia:feature/uncached_downloading Dec 2, 2024
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants