diff --git a/INSTALL.md b/INSTALL.md index 8a6a9290c..b1e47b1c4 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -57,7 +57,7 @@ To install: python --version # Python 2 is not supported. Make sure you're on Python 3.7 - pip install --editable .[test] # [test] installs extras needed for running the tests + pip install -e . ``` To verify your installation, `which lbrynet` should return a path inside of the `lbry-venv` folder created by the `virtualenv` command. diff --git a/setup.py b/setup.py index c4bbb5323..f3077733a 100644 --- a/setup.py +++ b/setup.py @@ -44,9 +44,4 @@ setup( 'docopt', 'colorama==0.3.7', ], - extras_require={ - 'test': ( - 'faker==0.8.17', - ) - } ) diff --git a/tests/unit/lbrynet_daemon/test_Daemon.py b/tests/unit/lbrynet_daemon/test_Daemon.py index b0713a857..04a6777b3 100644 --- a/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/tests/unit/lbrynet_daemon/test_Daemon.py @@ -1,12 +1,9 @@ from unittest import mock import json -import random -from os import path from twisted.internet import defer from twisted.trial import unittest -from faker import Faker from lbrynet import conf from lbrynet.schema.decode import smart_decode from lbrynet.extras.daemon.storage import SQLiteStorage @@ -29,7 +26,6 @@ from tests.mocks import ExchangeRateManager as DummyExchangeRateManager from tests.mocks import BTCLBCFeed, USDBTCFeed from tests.test_utils import is_android - def get_test_daemon(data_rate=None, generous=True, with_fee=False): if data_rate is None: data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1] @@ -152,8 +148,6 @@ class TestFileListSorting(unittest.TestCase): def setUp(self): mock_conf_settings(self) test_utils.reset_time(self) - self.faker = Faker('en_US') - self.faker.seed(129) # contains 3 same points paid (5.9) self.test_daemon = get_test_daemon() self.test_daemon.file_manager.lbry_files = self._get_fake_lbry_files() @@ -268,44 +262,246 @@ class TestFileListSorting(unittest.TestCase): with self.assertRaisesRegex(Exception, expected_message): yield self.test_daemon.jsonrpc_file_list(sort=sort_options) - def _get_fake_lbry_files(self): - return [self._get_fake_lbry_file() for _ in range(10)] + @staticmethod + def _get_fake_lbry_files(): + faked_lbry_files = [] + for metadata in FAKED_LBRY_FILES: + lbry_file = mock.Mock(spec=ManagedEncryptedFileDownloader) + for attribute in metadata: + setattr(lbry_file, attribute, metadata[attribute]) + faked_lbry_files.append(lbry_file) + return faked_lbry_files - def _get_fake_lbry_file(self): - lbry_file = mock.Mock(spec=ManagedEncryptedFileDownloader) - file_path = self.faker.file_path() - stream_name = self.faker.file_name() - channel_claim_id = self.faker.sha1() - channel_name = self.faker.simple_profile()['username'] - faked_attributes = { - 'channel_claim_id': channel_claim_id, - 'channel_name': '@' + channel_name, - 'claim_id': self.faker.sha1(), - 'claim_name': '-'.join(self.faker.words(4)), - 'completed': self.faker.boolean(), - 'download_directory': path.dirname(file_path), - 'download_path': file_path, - 'file_name': path.basename(file_path), - 'key': self.faker.md5(raw_output=True), - 'metadata': { - 'author': channel_name, - 'nsfw': random.randint(0, 1) == 1, - }, - 'mime_type': self.faker.mime_type(), - 'nout': abs(self.faker.pyint()), - 'outpoint': self.faker.md5() + self.faker.md5(), - 'points_paid': self.faker.pyfloat(left_digits=1, right_digits=1, positive=True), - 'sd_hash': self.faker.md5() + self.faker.md5() + self.faker.md5(), - 'stopped': self.faker.boolean(), - 'stream_hash': self.faker.md5() + self.faker.md5() + self.faker.md5(), - 'stream_name': stream_name, - 'suggested_file_name': stream_name, - 'txid': self.faker.md5() + self.faker.md5(), - 'written_bytes': self.faker.pyint(), - } - - for key in faked_attributes: - setattr(lbry_file, key, faked_attributes[key]) - - return lbry_file +FAKED_LBRY_FILES = ( + { + 'channel_claim_id': '3aace03b007d108c668d201533b7b07ab2981d47', + 'channel_name': '@ashlee27', + 'claim_id': 'cb63e644b6629467c031d0097d52ab6e0f1a5bf8', + 'claim_name': 'very-skill-place-growth', + 'completed': True, + 'download_directory': '/usually', + 'download_path': '/usually/any.mov', + 'file_name': 'any.mov', + 'key': b'>a\x11}\xec\xc2j\x1c\xe9\xc5l]\xfc\x16s|', + 'metadata': {'author': 'ashlee27', 'nsfw': True}, + 'mime_type': 'multipart/signed', + 'nout': 7197, + 'outpoint': 'c5633a5932f9c8e3e5b9799c07251b236e3aec078b0546614f24a932b6b133f6', + 'points_paid': 8.2, + 'sd_hash': '3354ecf502870f6f6d59d21188755c1361c2cffaeb458764c179c136b26c4795083acfd93b3920218870b1a9c22535ef', + 'stopped': True, + 'stream_hash': 'c8f58a686726116c15a8de7f33b4f0d72504777c7dd0c48ba94d7bbea23d9c82b2f977081cd7c49d25d6a2841b232e1d', + 'stream_name': 'down.txt', + 'suggested_file_name': 'down.txt', + 'txid': '1c02986bfdb77b1c338e60b60c4c9febc59130af2e225f51665067c3d3419a35', + 'written_bytes': 6838, + }, + { + 'channel_claim_id': 'dade35ea84001858d7cf10f50be3b5fea3e57fb7', + 'channel_name': '@richard64', + 'claim_id': '1c01096727da90140d333197fa8aaf88893f6ea8', + 'claim_name': 'room-tonight-produce-good', + 'completed': False, + 'download_directory': '/ability', + 'download_path': '/ability/day.tiff', + 'file_name': 'day.tiff', + 'key': b'`\x86j\xba\x97\x0c\xe4L\xad\x06nC\x8b]\xd6&', + 'metadata': {'author': 'richard64', 'nsfw': False}, + 'mime_type': 'multipart/related', + 'nout': 9678, + 'outpoint': '0138083012ce4ff5a6e4c0ec2fc08e11a52ebd2306d70a20f36424011f7c1330', + 'points_paid': 2.5, + 'sd_hash': '9e98f5e4bd4393b45a41839fe72a4df1f94b029e2339f8b14b9eaa9fec2be5245b160a59cfcc80fa86c1f91da67d5581', + 'stopped': False, + 'stream_hash': '7403ff9319292bdb022d66d0b88401775c6bb355fc0a75fe01452950fb19642ba58d492d34e24d8bf58375e6c2fca16f', + 'stream_name': 'including.mp3', + 'suggested_file_name': 'including.mp3', + 'txid': '345bfc7b4a0c042b14474ac2cecf099236aec5a6730943630ffb176e7b421121', + 'written_bytes': 8438, + }, + { + 'channel_claim_id': '59766071ea2df38b4a751834a77246bf8ff8071d', + 'channel_name': '@bfrederick', + 'claim_id': '1c08967d515ac2a5fd3cb4e477fde18bddde22e2', + 'claim_name': 'at-first-skill-agency', + 'completed': True, + 'download_directory': '/agree', + 'download_path': '/agree/different.json', + 'file_name': 'different.json', + 'key': b'\xc06\xb9\x8e\x00S\xdbX\x1cC\xbd+\xfc\xea\xc96', + 'metadata': {'author': 'bfrederick', 'nsfw': True}, + 'mime_type': 'image/svg+xml', + 'nout': 2975, + 'outpoint': '62bb992e11c562e8064aec094e2b4eefb422e50b13ae49dc10f440a60f8e99bc', + 'points_paid': 9.1, + 'sd_hash': '3d809caf1266ec1ab78cc046a62f388434b6c59f85844500f59a1c75b4303b9ea27c532a231556e8b9776c544677bdf7', + 'stopped': True, + 'stream_hash': '9ecb8cf7dca7260f90666f05c88882017c786d31b572f3cba9447099ca9b49cdcb93f801db2249b7d32ff44ca6ffd69c', + 'stream_name': 'north.doc', + 'suggested_file_name': 'north.doc', + 'txid': '98e12bce3a5db96e3513f1ff45afca8b69d61324117d6e839075ac512dd86251', + 'written_bytes': 1929, + }, + { + 'channel_claim_id': '046c8a762cd158a6e5b112d7d9c9e4b778f27388', + 'channel_name': '@heidiherring', + 'claim_id': '3d7573264601af7b5402cd54a66c13f2f93f296f', + 'claim_name': 'drop-hot-military-drive', + 'completed': False, + 'download_directory': '/letter', + 'download_path': '/letter/than.ppt', + 'file_name': 'than.ppt', + 'key': b'\n\xa7\xb3\x05\xab\x8e\xcc\n\xdcn\xd9\x81\xf3m\xf1t', + 'metadata': {'author': 'heidiherring', 'nsfw': True}, + 'mime_type': 'text/javascript', + 'nout': 3452, + 'outpoint': '5e8b55ffe59774366804c384f632f728f769bad566c784c6a23f1081724d00ea', + 'points_paid': 5.9, + 'sd_hash': 'c945b0acaf1c97dd7f262cf73cc3813ab6552f695ab00a445ca07a2a4da43bf3bb020cc7e338b484405d0865ef836480', + 'stopped': False, + 'stream_hash': '692ea08506d13422c875ce9d49fb9fe90b828d259d46c53adffa68a045e3852d4763b90ef94ef3864a1164bcab7eefa0', + 'stream_name': 'few.css', + 'suggested_file_name': 'few.css', + 'txid': '9ef901facbf8bc133cfe67793fe4423c048753dab8370d987f6f552ed6483bbb', + 'written_bytes': 9498, + }, + { + 'channel_claim_id': 'adc87fa84d601aa1760d0f4585f02e60bc82c703', + 'channel_name': '@xsteele', + 'claim_id': '9022e1fd14646f6a4f6708566fbb6f6ac10ba3d5', + 'claim_name': 'mean-television-miss-yourself', + 'completed': True, + 'download_directory': '/its', + 'download_path': '/its/add.mp3', + 'file_name': 'add.mp3', + 'key': b'\xdc\xd1\xf1i!\x85\xc6\xc8\\\xe0\xd7\xc0\xceN