summaryrefslogtreecommitdiffstats
path: root/deluge/tests
Commit message (Collapse)AuthorAge
* Fix parsing magnet with tracker tiersCalum Lind2022-07-08
| | | | | | | | | Magnets with trackers specified with tr.x param were not being unquoted so unusable raw tracker string was being set. Fixed by unquoting tracker and adding test See-also: https://dev.deluge-torrent.org/ticket/2716
* Fix missing trackers adding magnetsCalum Lind2022-07-05
| | | | | | | | | | | The changes to remove deprecated lt methods didn't account for magnet trackers so magnets are missing trackers when added. Previously the addition of trackers was handled by libtorrent when a url was passed in add_torrent_params. The url parameter is deprecated so instead we need to add both the info_hash and trackers. Trac: https://dev.deluge-torrent.org/ticket/3530
* [Web] Accept charset in content-type for json messagesibizaman2022-06-12
| | | | | Trac: https://dev.deluge-torrent.org/ticket/3521 Closes: https://github.com/deluge-torrent/deluge/pull/385
* [Core] Refactor prefetch_metadata for more clarityChase Sterling2022-05-17
| | | | | | | | | | | | | | | | | | | | | | | | Just trying to clean up some of the more complicated callback logic. Notable changes: * The test was awaiting a DeferredList. By default that will eat exceptions and just add them to the result list (including test assertion exceptions.) Added fireOnOneErrback=True to make sure that wasn't happening. * Moved the logic for multiple calls to await the same response into torrentmanager from core, so no matter where the prefetch is called from it will wait for the original call. * Implemented the multiple calls with an explicit queue of waiting callbacks, rather than a callback callback chain. * Moved to one inline async function rather than split into a main and callback after alert function. * Added some more type hints to the stuff I changed. Adjusted test since we are using prefetch as an async function now we have to schedule the alert to come after we start awaiting the prefetch call. Closes: https://github.com/deluge-torrent/deluge/pull/368
* [Core] Cleanup temp files in add_torrent_urlCalum Lind2022-05-01
| | | | | | | | | | | | | Temporary torrent files are not deleted by add_torrent_url. Not as big a problem as with tracker icons pages but should be removed after use. Fixed by updating the method to use async and a try..finally cleanup block. Perhaps could be refactored to not require temporary files and instead store the downloaded torrent as object for passing to add_torrent_file. Trac: https://dev.deluge-torrent.org/ticket/3167
* [TrackerIcons] Cleanup tmp files created by downloading pageCalum Lind2022-05-01
| | | | | | | | | | | | | Temporary files created while download host html page are no cleaned up if the download fails. Fixed by adding a 'finally' step in the callback chain to delete any created temporary files. Added tests to ensure the temporary files are deleted, using a fixture that creates a known filename for the test. Trac: https://dev.deluge-torrent.org/ticket/3167
* [Tests] Remove winreg interface name checkCalum Lind2022-05-01
| | | | | | | GitHub CI tests on Windows failing for get_windows_interface_name so remove the fragile tests since not a requirement to be this specific with testing whether name exists for these methods relying on standard lib or 3rd-party libs.
* [Tests] Remove reference to Twisted TrialCalum Lind2022-03-02
| | | | | With the move to pytest remove remainings documentation or comments that refer to Trial.
* [Tests] Skip SNI icon testCalum Lind2022-03-02
| | | | | | | The SNI icon test is failing due to seo.com removing their favicon. A new test to replace it would be needed to check SNI support. Ideally new tests would not rely on external sites.
* Automatically refresh and expire the torrent status cache.Chase Sterling2022-02-15
| | | | | | | | | | Stop at ratio was not working when no clients were connected, because it was using a cached version of the torrent status, and never calling for a refresh. When a client connected, it called for the refresh and started working properly. Closes: https://dev.deluge-torrent.org/ticket/3497 Closes: https://github.com/deluge-torrent/deluge/pull/369
* [Lint] Update linter version and fix issuesCalum Lind2022-02-13
| | | | | | | | | | | Notable changes: * Prettier >=2.3 with more consistent js assignments * Black now formats docstrings * Added isort to list of autoformaters * Update flake8 config for v4 Ref: https://prettier.io/blog/2021/05/09/2.3.0.html
* [Core] Stopped using libtorrent deprecated functionsDjLegolas2022-02-13
| | | | | | | | | | | | | | | | | As part of the process of adding support to LT 2.0, we should stop using all deprecated function, as some (if not all) were removed. For this process, we should use the LT 1.2 upgrade (guide)[1]. The change includes: * stop using file entries directly * start using the torrent handle's set/unset flags * stop using url key in add_torrent_params (for magnet) * stop accessing resume_data from save_resume_data_alert * stop using deprecated session status keys in UI [1] https://libtorrent.org/upgrade_to_1.2-ref.html Closes: https://dev.deluge-torrent.org/ticket/3499 Closes: https://github.com/deluge-torrent/deluge/pull/342
* [Config] Fix callLater func missing argsDjLegolas2022-02-12
| | | | | | | | | | | | In a6840296, a refactor to the `config` class was introduced. The change included an internal wrapper for `reactor.callLater`, for lazy import, but didn't wrap it correctly and therefor, no args/kwargs were passed to the wrapped method. Furthermore, the exception was silently ignored. This caused changes to be ignored and not applied, including `preferencesmanager._on_config_value_change` callback. Closes: https://github.com/deluge-torrent/deluge/pull/372
* [Tests] Make file priority test more consistent.Chase Sterling2022-02-12
| | | | | | | | | | | Our file priority test was using time.sleep to wait until libtorrent had processed the command. This was sometimes not long enough and the test would fail. On libtorrent 2.0.3+ there is an alert when the process has finished, switch to waiting for that in this test to make the test more consistent. On older libtorrent, make the delay a bit longer, to try to make the test more consistent there as well. Closes: https://github.com/deluge-torrent/deluge/pull/373
* [Decorators] Add maybe_coroutine decoratorChase Sterling2022-02-06
| | | | | | | | | | | | - Clean up callback hell by making more code inline - Use async/await syntax as it has more modern niceties than inlineCallbacks - Also gets us closer if we want to transition to asyncio in the future - `await` is usable in places that `yield` is not. e.g. `return await thething` `func(await thething, 'otherparam')` - IDEs know async semantics of async/await syntax to help more than with `inlineCallbacks` - `maybe_coroutine` decorator has nice property (over `ensureDeferred`) that when used in a chain of other coroutines, they won't be wrapped in deferreds on each level, and so traceback will show each `await` call leading to the error. - All async functions wrapped in `maybe_coroutine` are 100% backwards compatible with a regular Deferred returning function. Whether called from a coroutine or not. - Use Deferred type hints as strings since older versions of twisted (<21.7) don't support generic Deferred type hinting.
* [Config] Add mask_funcs to help mask passwords in logsCalum Lind2022-02-06
| | | | | | | | | | | Added a new Config class parameter `log_mask_funcs` to enable config instances hide sensitive information that would normally appear in config debug logs. Added mask password function to hostlist to replace passwords with '*'s in logs. Closes: https://github.com/deluge-torrent/deluge/pull/363
* [Config] Refactor config classCalum Lind2022-02-05
| | | | | | | | | | | | | * Refactored duplication with setting config key and logging * Simplified lazy importing reactor for callLater. This lazy importing is required for testing and also prevents Gtk UI lockup if reactor imported in Config. * Fixed saving config to file when setting a key that doesn't exist yet. This was due to returning early in the set_item method. * Added a `default` arg to set_item to prevent saving to file when only setting a default value for a key in init. * Moved casting value to existing key type from set_item to dedicated function.
* [Tests] Transition tests to pure pytestChase Sterling2022-02-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert all the twisted.trial tests to pytest_twisted. Also move off of unittest.TestCase as well. Seems there were several tests which weren't actually testing what they should, and also some code that wasn't doing what the broken test said it should. Goals: Remove twisted.trial tests Move to pytest fixtures, rather than many classess and subclasses with setup and teardown functions Move away from self.assertX to assert style tests FIx broken tests Going forward I think these should be the goals when adding/modifying tests: * Don't use BaseTest or set_up tear_down methods any more. Fixtures should be used either in the test module/class, or make/improve the ones available in conftest.py * For sure don't use unittest or twisted.trial, they mess up the pytest stuff. * Prefer pytest_twisted.ensureDeferred with an async function over inlineCallbacks. - I think the async function syntax is nicer, and it helps catch silly mistakes, e.g. await None is invalid, but yield None isn't, so if some function returns an unexpected thing we try to await on, it will be caught earlier. (I struggled debugging a test for quite a while, then caught it immediately when switching to the new syntax) - Once the maybe_coroutine PR goes in, using the async syntax can also improve tracebacks when debugging tests. Things that should probably be cleaned up going forward: * Remove BaseTestCase * Remove the subclasses like DaemonBase in favor of new fixtures. * I think there are some other utility subclasses that could be removed too * Perhaps use parameterization in the ui_entry tests, rather that the weird combination of subclasses and the set_var fixture I mixed in. * Convert some of the callback stuff to pytest_twisted.ensureDeferred tests, just for nicer readability Details relating to pytest fixtures conftest.py in root dir: * https://github.com/pytest-dev/pytest/issues/5822#issuecomment-697331920 * https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files Closes: https://github.com/deluge-torrent/deluge/pull/354
* [Common] Add is_interface to validate network interfacestbkizle2022-01-30
| | | | | | | | | | | | | | | | | | | | | | Libtorrent now supports interface names instead of just IP address so add new common functions to validate user input. * Added is_interface that will verify if a libtorrent interface of name or IP address. * Added is_interface_name to verify that the name supplied is a valid network interface name in the operating system. On Windows sock.if_nameindex() is only supported on 3.8+ and does not return a uuid (required by libtorrent) so use ifaddr package. Using git commit version for ifaddr due to adapter name decode bug in v0.1.7. On other OSes attempt to use stdlib and fallback to ifaddr if installed otherwiser return True. * Added tests for is_interface & is_interface_name * Updated UIs with change from address to interface * Updated is_ipv6 and is_ipv4 to used inet_pton; now supported on Windows. Ref: https://github.com/pydron/ifaddr/pull/32 Closes: https://github.com/deluge-torrent/deluge/pull/338
* [Tests] fix/enable most ui tests on WindowsChase Sterling2022-01-26
| | | | Closes: https://github.com/deluge-torrent/deluge/pull/348
* [Tests] fix torrentview tests (new default column was added)Chase Sterling2022-01-26
|
* [Tests] Make sure to return exit code still when ending test daemonChase Sterling2022-01-26
| | | | Use a separate Client instance to call test daemon shutdown
* [Tests] Escape backslashes in filename in webserver testChase Sterling2022-01-26
|
* [Tests] Change example files in files tab test to sort the same on linux/windowsChase Sterling2022-01-26
|
* [Tests] Enable more tests that now work on WindowsChase Sterling2022-01-26
|
* [Tests] Shutdown test daemon cleanly using rpc. (needed for Windows)Chase Sterling2022-01-26
| | | | Escape backslashes in config path for test daemon startup.
* [Tests] Make failure message more clear when test daemon doesn't shut down ↵Chase Sterling2022-01-26
| | | | cleanly
* [Tests] Enable unicode path test on WindowsChase Sterling2022-01-26
|
* [Tests] Fix erroneous windows line endings in test state fileChase Sterling2022-01-26
|
* [Tests] Enable metafile test on WindowsChase Sterling2022-01-26
|
* [Tests] Fix maketorrent test on WindowsChase Sterling2022-01-26
|
* [Plugins] Fix missing description with metadata 2.1Calum Lind2022-01-12
| | | | | | | | | | | | Changes to the metadata specs in v2.1 meant that Description field might appear in the body of the message instead of as a header key. Replaced custom parser with email parser (as outlined in the document using compat32 policy) to simplify extracting the message header and body. Ref: https://dev.deluge-torrent.org/ticket/3476 Ref: https://packaging.python.org/en/latest/specifications/core-metadata/#description
* [Plugins] Fix and refactor get_plugin_info methodCalum Lind2022-01-12
| | | | | | | | | | | | | | | | | | A new metadata version 2.1 has optional Description that is causing an TypeError when looking up the key in plugin_info since clients are assuming values are always strings but the default is None. Fixed TypeError by ensuring that the info dict has a default empty string set for all keys. Separated the parsing of the pkg_info into static method to make it easier to test. Changed the missing plugin info to only set the Name and Version as 'not available' since all other fields are optional. Ref: https://dev.deluge-torrent.org/ticket/3476 Ref: https://packaging.python.org/en/latest/specifications/core-metadata/#description
* [GTK] Fix unable to prefetch magnet in thinclientCalum Lind2022-01-08
| | | | | | | | | | | | | | | | A UnicodeDecodeError is raised in transfer module when attempting to prefetch a magnet. This is result of passing a Python dict containing text bytes and raw bytes that cannot be decoded as utf-8 in rencode when recieving the message. This could be handled in rencode by returning raw bytes if decoding fails (perhaps with a strict mode?) however better to follow convention of encoding raw bytes in base64 in API calls. Fixed by retaining bencoding and encoding with base64 when sending result. Resolves: https://github.com/deluge-torrent/deluge/pull/334
* [TrackerIcon] Fixed parse error on UTF-8 sites with non-english charsDjLegolas2022-01-06
| | | | | | | | | | | | | When parsing the site's page in search for the FAVICON, the page gets opens. The default file encoding in dependent on the running OS, and might not be `UTF-8` on Windows. Therefor, some trackers might not get their icon downloaded at all because of an error: `UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2158: character maps to <undefined>`. This fix adds a detection of file encoding using the optional `chardet` dependency, and also a test. Closes: deluge-torrent/deluge#333 Closes: https://dev.deluge-torrent.org/ticket/3479
* Upgrade codebase with pyupgrade (>=py3.6)DjLegolas2021-12-29
| | | | | | | | Added pyupgrade utility with manual stage to pre-commit and run on all files. Ref: https://github.com/asottile/pyupgrade Closes: deluge-torrent/deluge#326
* [UI] Add SVG support for tracker iconsDjLegolas2021-12-29
| | | | | | | | | | | SVG files are supported by all browsers so need to support it as well, according to https://www.w3schools.com/html/html_favicon.asp Also, it appears as SEO.com site, which was dropped because of a cert issue, has only SVG icon. So enabled it again. Lastly, from python 3.2, `os.path.samefile` is supported on Windows. So Windows will now test TrackerIcons as well.
* Remove all Python 2 supportdeluge-2.1.0.dev0DjLegolas2021-12-28
| | | | | | | | | * Removed all __future__ imports from code * Removed all six dependencies * Removed all future_builtins imports * Removed all Python 2 related code Closes: deluge-torrent/deluge#325
* [Servers] Moved check_ssl_keys and generate_ssl_keys to crypto_utils.pyDjLegolas2021-12-20
| | | | | | | | | With this change, we drop a core dependency from the UI. This will help group together all related functionality in one place, i.e. all security related functions. Also updated testssl.sh version to 3.0.6 (SECURITY_TEST) Closes: deluge-torrent/deluge#288
* [Console] Fix using windows-curses on WindowsCalum Lind2021-08-01
| | | | | | The console tests are still failing on Windows due to an issue where the sys args are not being correctly replaced in the tests so the pytest args are being passed to console.
* [Tests] Fix skipping torrent test for libtorrent >= 1.2Calum Lind2021-08-01
| | | | Test is still failing with libtorrent 2 so also skip.
* [Tests] Fix incorrent twisted defer importCalum Lind2021-07-31
| | | | | With the release Twisted 21.7.0 there was an import error running the tests due to defer incorrectly imported via twisted.internet.tasks module.
* [CI/CD] Add github actions to replace TravisCalum Lind2021-07-25
| | | | | | | | | | | | | | | | Due to new limitations for open-source projects on Travis we are switching to GitHub actions. * Notes about system site-packages We had many problems with accessing system python packages on Travis for libtorrent and GTK and the problems are harder on Github since there is no more access. For now copying the python libtorrent binary into the deluge source is the workaround. There is a pip package that could be used in future. Fixed failing tests with libtorrent 1.2 which required a non-zero length file in torrent and workarounds for async alert delay.
* [AutoAdd|3295] Correctly fix auto-adding magnetsCalum Lind2021-07-24
| | | | | | | | Properly fix adding magnets, first attempted in previous commit 2e466101fc20a add_torrent_magnet does not return a deferred so wrap in maybeDeferred. Fixed broken test due to new deluge website icon
* [#3388|WebUI] Fix md5sums in torrent files breaking file listingCalum Lind2021-03-24
| | | | | | | | | | | | | | | | | | | Torrents containing md5sum optional hashes are not being decoded and so causes errors in the json_api when the TorrentInfo is returned: Object of type bytes is not JSON serializable Fixed by removing all optional hashes from the paths returned from TorrentInfo and only including the required path keys. The optional hashes are unused by Deluge so simplify by removing. Fixed Windows path issue in TorrentInfo by ensuring conversion to posix paths. Refs: http://wiki.bitcomet.com/inside_bitcomet http://wiki.depthstrike.com/index.php/P2P:Protocol:Specifications:Optional_Hashes https://wiki.theory.org/index.php/BitTorrentSpecification
* [WebUI] Add test for torrent files containing md5sumsHans Ole Hatzel2021-03-24
| | | | | | | | Some torrent files built with py3createtorrent fail to produce a file listing in the WebUI when uploading them. This made it impossible to add such files. Specifically this is caused by the additional metadata when using py3createtorrent with the `--md5` flag.
* [CI/CD] Add Travis windows buildCalum Lind2021-02-23
| | | | | | | | | * Added APPDATA to tox passenv so it is available to common module. * Fixed windows path issue in httpdownloader tests * Skipped torrentmanager test due to the following error from loading a Linux pickled state file with a different line ending. ModuleNotFoundError: No module named 'deluge.core.torrentmanager\r' * Removed appveyor build
* [#3440] Fix httpdownloader reencoding torrent file downloadsCalum Lind2021-02-20
| | | | | | | | | | | | | | Torrent downloads from rutracker responds with the header: Content-Type: application/x-bittorrent; charset=Windows-1251 The problem is that httpdownloader was using the charset to re-encode the downloaded file, corrupting the binary torrent file download. Fixed by only re-encoding text content types, since it is very rare that non-text content types would actually have a non-utf8 codeset and if there is a requirement we would need to determine it on a type by type basis.
* [#3325|Core] Fix unable to remove magnet with delete_copies enabledCalum Lind2021-02-05
| | | | | | | | | | | | | | | | Users were encountering the following error while attempting to delete magnet torrents and had the config 'Delete copy of torrent file' enabled. This was due to removing a magnet before the metadata was downloaded and the torrent.filename was still set to None so raises exceptions when string operations are performed with it. File "/usr/lib/python3/dist-packages/deluge/core/torrent.py", line 1317, in delete_torrentfile os.path.join(self.config['torrentfiles_location'], self.filename) ... TypeError: join() argument must be str or bytes, not 'NoneType' Fixed by both setting a default empty string for self.filename and only deleting the torrent file copy if filename is set.
* [Tests] Fix console tests sometimes failing due to hard coded portbendikro2021-01-29
| | | | | | | | | The tests in ConsoleUIWithDaemonBaseTestCase could fail to the hard coded port 58900 being busy. Fix by using the proper port found in self.listen_port Also convert unnecessary use of assertTrue where more appropriate assert functions should be used, such as assertEqual and assertIn