-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a combination of 12 commits. Squashed commits : - modify testcase to fit new preferences - Remove singleton in test - Change test to adapt TaskManager in source - Add test in dependencies and default load - Move rss xml creation to separate method - Refer channel and torrent creation to RestAPI test - Add more Levenshtein distance test - Add test on custom RSS parser - Refactor test on single type parameter in BoostingManager - Remove threading event usage in test - Reduce timeout in RSS test - Test cleaning pylint
- Loading branch information
1 parent
e258c66
commit f3b870a
Showing
10 changed files
with
1,151 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
This package contains tests for the credit mining-related code of Tribler. | ||
""" |
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,138 @@ | ||
""" | ||
Module of Credit mining mock classes | ||
Written by Ardhi Putra Pratama H | ||
""" | ||
from twisted.web.resource import Resource | ||
|
||
|
||
class MockLtTorrent(object): | ||
""" | ||
Class representing libtorrent handle for getting peer info | ||
""" | ||
def __init__(self, infohash="12345"): | ||
self.info_hash = infohash | ||
self.all_time_download = 0 | ||
self.all_time_upload = 0 | ||
|
||
def upload_limit(self): | ||
return 12 | ||
|
||
def max_uploads(self): | ||
return 13 | ||
|
||
def max_connections(self): | ||
return 14 | ||
|
||
def piece_priorities(self): | ||
return [0, 1, 1, 0, 1, 1, 1] | ||
|
||
def get_peer_info(self): | ||
""" | ||
class returning peer info for a particular handle | ||
""" | ||
peer = [None] * 6 | ||
peer[0] = MockLtPeer(1, "ip1") | ||
peer[0].setvalue(True, True, True) | ||
peer[1] = MockLtPeer(2, "ip2") | ||
peer[1].setvalue(False, False, True) | ||
peer[2] = MockLtPeer(3, "ip3") | ||
peer[2].setvalue(True, False, True) | ||
peer[3] = MockLtPeer(4, "ip4") | ||
peer[3].setvalue(False, True, False) | ||
peer[4] = MockLtPeer(5, "ip5") | ||
peer[4].setvalue(False, True, True) | ||
peer[5] = MockLtPeer(6, "ip6") | ||
peer[5].setvalue(False, False, False) | ||
return peer | ||
|
||
def is_valid(self): | ||
""" | ||
check whether the handle is valid or not | ||
""" | ||
return True | ||
|
||
def status(self): | ||
return self | ||
|
||
class MockLtPeer(object): | ||
""" | ||
Dummy peer object returned by libtorrent python binding | ||
""" | ||
def __init__(self, pid, ip): | ||
self.pid = pid | ||
self.client = 2 | ||
self.ip = [ip, "port"] | ||
self.flags = 1 | ||
self.local_connection = True | ||
self.payload_up_speed = 0 | ||
self.remote_interested = 1 | ||
self.remote_choked = 1 | ||
self.upload_queue_length = 0 | ||
self.used_send_buffer = 0 | ||
self.payload_down_speed = 0 | ||
self.interesting = True | ||
self.choked = True | ||
self.total_upload = 0 | ||
self.total_download = 0 | ||
self.progress = 0 | ||
self.pieces = 0 | ||
self.remote_dl_rate = 0 | ||
self.country = "ID" | ||
self.connection_type = 0 | ||
self.seed = 1 | ||
self.upload_only = 1 | ||
self.read_state = False | ||
self.write_state = False | ||
|
||
def setvalue(self, upload_only, uinterested, completed): | ||
self.upload_only = upload_only | ||
self.remote_interested = uinterested | ||
self.progress = 1 if completed else 0 | ||
|
||
|
||
class MockMeta(object): | ||
""" | ||
class for mocking the torrent metainfo | ||
""" | ||
|
||
def __init__(self, id_hash): | ||
self.infohash = id_hash | ||
|
||
def get_infohash(self): | ||
""" | ||
returning infohash of torrents | ||
""" | ||
return self.infohash | ||
|
||
|
||
class MockLtSession(object): | ||
""" | ||
Mock for session and LibTorrentMgr | ||
""" | ||
def __init__(self): | ||
pass | ||
|
||
def get_session(self): | ||
""" | ||
supposed to get libtorrent session | ||
""" | ||
return self | ||
|
||
def set_settings(self, _): | ||
""" | ||
set settings (don't do anything) | ||
""" | ||
pass | ||
|
||
def shutdown(self): | ||
""" | ||
obligatory shutdown function | ||
""" | ||
pass | ||
|
||
|
||
class ResourceFailClass(Resource): | ||
def render_GET(self, request): | ||
request.setResponseCode(503) | ||
return "<html><body>Error 503.</body></html>" |
Oops, something went wrong.