-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2520923
commit 5e87c44
Showing
4 changed files
with
70 additions
and
16 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,42 @@ | ||
from twisted.internet.defer import inlineCallbacks, succeed | ||
|
||
from Tribler.community.dht.provider import DHTCommunityProvider | ||
from Tribler.pyipv8.ipv8.util import blocking_call_on_reactor_thread | ||
from Tribler.Test.Core.base_test import TriblerCoreTest, MockObject | ||
|
||
|
||
class TestDHTProvider(TriblerCoreTest): | ||
|
||
@blocking_call_on_reactor_thread | ||
@inlineCallbacks | ||
def setUp(self, annotate=True): | ||
yield super(TestDHTProvider, self).setUp(annotate=annotate) | ||
|
||
def mocked_find_values(key): | ||
return succeed(['\x01\x01\x01\x01\x04\xd2']) | ||
|
||
def mocked_store(key, value): | ||
self.stored_value = value | ||
return succeed([]) | ||
|
||
self.cb_invoked = False | ||
self.stored_value = None | ||
self.dhtcommunity = MockObject() | ||
self.dhtcommunity.find_values = mocked_find_values | ||
self.dhtcommunity.store = mocked_store | ||
self.dhtcommunity.my_estimated_lan = '1.1.1.1' | ||
self.dht_provider = DHTCommunityProvider(self.dhtcommunity, 1234) | ||
|
||
def test_lookup(self): | ||
def check_result(result): | ||
self.cb_invoked = True | ||
self.assertEqual(result, [('1.1.1.1', 1234)]) | ||
self.dht_provider.lookup('a' * 20, check_result) | ||
self.assertTrue(self.cb_invoked) | ||
|
||
def test_announce(self): | ||
def check_result(result): | ||
self.cb_invoked = True | ||
self.dht_provider.announce('a' * 20, check_result) | ||
self.assertTrue(self.cb_invoked) | ||
self.assertEqual(self.stored_value, '\x01\x01\x01\x01\x04\xd2') |
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