-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add torrent name validator on create torrent dialog
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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.
This file contains 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,25 @@ | ||
from PyQt5.QtGui import QValidator | ||
|
||
from tribler.gui.dialogs.createtorrentdialog import TorrentNameValidator | ||
|
||
|
||
def test_torrent_name_validator(): | ||
""" | ||
Tests if the torrent name validator marks the input as valid if there are no multiline characters. | ||
Upon fixup, the invalid characters are accepted correctly. | ||
""" | ||
def assert_text_is_valid(validator: QValidator, original_text: str, expected_to_be_valid: bool): | ||
state, text, pos = validator.validate(original_text, len(original_text)) | ||
assert state == QValidator.Acceptable if expected_to_be_valid else QValidator.Intermediate | ||
assert text == original_text | ||
assert pos == len(original_text) | ||
|
||
validator = TorrentNameValidator(None) | ||
|
||
invalid_name = """line 1 | ||
line2.torrent | ||
""" | ||
assert_text_is_valid(validator, invalid_name, expected_to_be_valid=False) | ||
|
||
fixed_name = validator.fixup(invalid_name) | ||
assert_text_is_valid(validator, fixed_name, expected_to_be_valid=True) |