Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ichorid committed Dec 12, 2018
1 parent b7d9643 commit 3f4d64f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
7 changes: 5 additions & 2 deletions Tribler/Core/CacheDB/SqliteCacheDBHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@ def calculate_score_channel(keywords, channel_name, channel_description):
# and 20% on the matching in the channel description.
return 0.8 * scores[0] + 0.2 * scores[1]

def search_in_local_channels_db(self, query, first=0, last=None, count=False):
def search_in_local_channels_db(self, query, first=0, last=None, count=False, chan_size_limit=3):
"""
Searches for matching channels against a given query in the database.
"""
Expand All @@ -2376,7 +2376,10 @@ def search_in_local_channels_db(self, query, first=0, last=None, count=False):
else:
sql = "SELECT id, dispersy_cid, name, description, nr_torrents, nr_favorite, nr_spam, modified "

sql +="FROM Channels WHERE nr_torrents > 2 and ("
sql +="FROM Channels WHERE"
if chan_size_limit:
sql += " nr_torrents >= %i and " % chan_size_limit
sql += " ("
for _ in xrange(len(keywords)):
sql += " name LIKE ? OR description LIKE ? OR "
sql = sql[:-4] + " )"
Expand Down
18 changes: 0 additions & 18 deletions Tribler/Test/Core/CreditMining/test_credit_mining_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ def test_existing_channel_lookup(self):
self.assertEqual(source.community, community, 'ChannelSource failed to find existing ChannelCommunity')
source.stop()

@inlineCallbacks
def test_torrent_from_db(self):
# Torrent is a tuple: (channel_id, dispersy_id, peer_id, infohash, timestamp, name, files, trackers)
torrent = (0, self.cid, 42, '\00' * 20, 0, u'torrent', [], [])
channel_db_handler = self.session.open_dbhandler(NTFY_CHANNELCAST)
channel_db_handler.on_torrents_from_dispersy([torrent])

torrent_inserteds = []
torrent_insert_callback = lambda source, infohash, name: torrent_inserteds.append((source, infohash, name))
source = ChannelSource(self.session, self.cid, torrent_insert_callback)
source.start()

yield deferLater(reactor, 1, lambda: None)
self.assertIn((self.cid, hexlify(torrent[3]), torrent[5]), torrent_inserteds,
'ChannelSource failed to insert torrent')

source.stop()

def test_torrent_discovered(self):
torrent_inserteds = []
torrent_insert_callback = lambda source, infohash, name: torrent_inserteds.append((source, infohash, name))
Expand Down
4 changes: 2 additions & 2 deletions Tribler/Test/Core/test_sqlitecachedbhandler_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_get_channels_by_cid(self):
self.assertEqual(len(self.cdb.getChannelsByCID(["3"])), 0)

def test_get_all_channels(self):
self.assertEqual(len(self.cdb.getAllChannels()), 8)
self.assertEqual(len(self.cdb.getAllChannels()), 3)

def test_get_new_channels(self):
self.assertEqual(len(self.cdb.getNewChannels()), 1)
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_search_local_channels(self):
"""
Testing whether the right results are returned when searching in the local database for channels
"""
results = self.cdb.search_in_local_channels_db("fancy")
results = self.cdb.search_in_local_channels_db("fancy", chan_size_limit=None)
self.assertEqual(len(results), 2)
self.assertNotEqual(results[0][-1], 0.0) # Relevance score of result should not be zero

Expand Down
2 changes: 1 addition & 1 deletion Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_search_local_torrents(self):
"""
Test the search procedure in the local database when searching for torrents
"""
results = self.tdb.search_in_local_torrents_db('content', ['infohash', 'num_seeders'])
results = self.tdb.search_in_local_torrents_db('content', ['infohash', 'num_seeders'], family_filter=False, last = 5000)
self.assertEqual(len(results), 4849)
self.assertNotEqual(results[0][-1], 0.0) # Relevance score of result should not be zero
results = self.tdb.search_in_local_torrents_db('fdsafasfds', ['infohash'])
Expand Down

0 comments on commit 3f4d64f

Please sign in to comment.