-
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.
Ignore old responses for the DownloadsPage
- Loading branch information
Showing
7 changed files
with
117 additions
and
11 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
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
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
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
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,50 @@ | ||
from unittest.mock import MagicMock, Mock, patch | ||
|
||
from PyQt5.QtWidgets import QWidget | ||
|
||
from tribler.gui.network.request import REQUEST_ID | ||
from tribler.gui.widgets.downloadspage import DownloadsPage | ||
|
||
|
||
def downloads_page() -> DownloadsPage: | ||
window = MagicMock() | ||
window.downloads_list.indexOfTopLevelItem = Mock(return_value=-1) | ||
|
||
page = DownloadsPage() | ||
page.window = Mock(return_value=window) | ||
page.received_downloads = Mock() | ||
return page | ||
|
||
|
||
@patch.object(QWidget, '__init__', Mock()) | ||
def test_accept_requests(): | ||
# Test that the page accepts requests with the greater request id | ||
page = downloads_page() | ||
|
||
page.on_received_downloads(result={REQUEST_ID: 1, 'downloads': MagicMock()}) | ||
assert page.received_downloads.emit.called | ||
|
||
page.received_downloads.emit.reset_mock() | ||
page.on_received_downloads(result={REQUEST_ID: 2, 'downloads': MagicMock()}) | ||
assert page.received_downloads.emit.called | ||
|
||
page.received_downloads.emit.reset_mock() | ||
page.on_received_downloads(result={REQUEST_ID: 10, 'downloads': MagicMock()}) | ||
assert page.received_downloads.emit.called | ||
|
||
|
||
@patch.object(QWidget, '__init__', Mock()) | ||
def test_ignore_request(): | ||
# Test that the page ignores requests with a lower or equal request id | ||
page = downloads_page() | ||
|
||
page.on_received_downloads(result={REQUEST_ID: 10, 'downloads': MagicMock()}) | ||
assert page.received_downloads.emit.called | ||
|
||
page.received_downloads.emit.reset_mock() | ||
page.on_received_downloads(result={REQUEST_ID: 10, 'downloads': MagicMock()}) | ||
assert not page.received_downloads.emit.called | ||
|
||
page.received_downloads.emit.reset_mock() | ||
page.on_received_downloads(result={REQUEST_ID: 9, 'downloads': MagicMock()}) | ||
assert not page.received_downloads.emit.called |
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
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