2017-02-17 23:08:01 +01:00
|
|
|
from twisted.internet import defer
|
|
|
|
from twisted.trial import unittest
|
2017-08-04 05:13:59 +02:00
|
|
|
from lbrynet import conf
|
2017-06-26 03:04:04 +02:00
|
|
|
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
|
|
|
from lbrynet.file_manager.EncryptedFileManager import EncryptedFileManager
|
2017-09-28 19:21:26 +02:00
|
|
|
from lbrynet.tests.util import random_lbry_hash
|
2017-02-17 23:08:01 +01:00
|
|
|
|
|
|
|
class TestEncryptedFileManager(unittest.TestCase):
|
|
|
|
|
2017-08-04 05:13:59 +02:00
|
|
|
def setUp(self):
|
|
|
|
conf.initialize_settings()
|
|
|
|
|
2017-02-17 23:08:01 +01:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_database_operations(self):
|
|
|
|
# test database read/write functions in EncrypteFileManager
|
|
|
|
|
|
|
|
class MocSession(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
session = MocSession()
|
|
|
|
session.db_dir = '.'
|
2017-09-29 12:44:22 +02:00
|
|
|
stream_info_manager = None
|
2017-02-17 23:08:01 +01:00
|
|
|
sd_identifier = None
|
|
|
|
download_directory = '.'
|
2017-09-29 12:44:22 +02:00
|
|
|
manager = EncryptedFileManager(
|
|
|
|
session, stream_info_manager, sd_identifier, download_directory)
|
2017-02-17 23:08:01 +01:00
|
|
|
yield manager._open_db()
|
|
|
|
out = yield manager._get_all_lbry_files()
|
2017-09-29 12:44:22 +02:00
|
|
|
self.assertEqual(len(out), 0)
|
2017-02-17 23:08:01 +01:00
|
|
|
|
|
|
|
stream_hash = random_lbry_hash()
|
|
|
|
blob_data_rate = 0
|
|
|
|
out = yield manager._save_lbry_file(stream_hash, blob_data_rate)
|
|
|
|
rowid = yield manager._get_rowid_for_stream_hash(stream_hash)
|
|
|
|
self.assertEqual(out, rowid)
|
|
|
|
files = yield manager._get_all_lbry_files()
|
|
|
|
self.assertEqual(1, len(files))
|
|
|
|
yield manager._change_file_status(rowid, ManagedEncryptedFileDownloader.STATUS_RUNNING)
|
|
|
|
out = yield manager._get_lbry_file_status(rowid)
|
|
|
|
self.assertEqual(out, ManagedEncryptedFileDownloader.STATUS_RUNNING)
|