forked from LBRYCommunity/lbry-sdk
add tests for BlobRequestHandler and run on travis
This commit is contained in:
parent
5368c91399
commit
f74f075b4e
6 changed files with 106 additions and 2 deletions
|
@ -38,8 +38,8 @@ rm get-pip.py
|
|||
|
||||
pip install -r requirements.txt
|
||||
|
||||
pip install nose coverage coveralls pylint
|
||||
nosetests --with-coverage --cover-package=lbrynet -v -I functional_tests.py tests/
|
||||
pip install mock pylint
|
||||
trial tests
|
||||
# TODO: submit coverage report to coveralls
|
||||
|
||||
# TODO: as code quality improves, make pylint be more strict
|
||||
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/lbrynet/__init__.py
Normal file
0
tests/lbrynet/__init__.py
Normal file
0
tests/lbrynet/core/__init__.py
Normal file
0
tests/lbrynet/core/__init__.py
Normal file
0
tests/lbrynet/core/server/__init__.py
Normal file
0
tests/lbrynet/core/server/__init__.py
Normal file
104
tests/lbrynet/core/server/test_BlobRequestHandler.py
Normal file
104
tests/lbrynet/core/server/test_BlobRequestHandler.py
Normal file
|
@ -0,0 +1,104 @@
|
|||
import mock
|
||||
from twisted.internet import defer
|
||||
from twisted.trial import unittest
|
||||
|
||||
from lbrynet.core.server import BlobRequestHandler
|
||||
|
||||
|
||||
class TestBlobRequestHandlerQueries(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.blob_manager = mock.Mock()
|
||||
self.payment_rate_manager = mock.Mock()
|
||||
self.handler = BlobRequestHandler.BlobRequestHandler(
|
||||
self.blob_manager, None, self.payment_rate_manager)
|
||||
|
||||
def test_empty_response_when_empty_query(self):
|
||||
self.assertEqual({}, self.successResultOf(self.handler.handle_queries({})))
|
||||
|
||||
def test_error_set_when_rate_is_missing(self):
|
||||
query = {'requested_blob': 'blob'}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {'incoming_blob': {'error': 'RATE_UNSET'}}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
def test_error_set_when_rate_too_low(self):
|
||||
self.payment_rate_manager.accept_rate_blob_data.return_value = False
|
||||
query = {
|
||||
'blob_data_payment_rate': 'way_too_low',
|
||||
'requested_blob': 'blob'
|
||||
}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {
|
||||
'blob_data_payment_rate': 'RATE_TOO_LOW',
|
||||
'incoming_blob': {'error': 'RATE_UNSET'}
|
||||
}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
def test_response_when_rate_too_low(self):
|
||||
self.payment_rate_manager.accept_rate_blob_data.return_value = False
|
||||
query = {
|
||||
'blob_data_payment_rate': 'way_too_low',
|
||||
}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {
|
||||
'blob_data_payment_rate': 'RATE_TOO_LOW',
|
||||
}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
def test_blob_unavailable_when_blob_not_validated(self):
|
||||
self.payment_rate_manager.accept_rate_blob_data.return_value = True
|
||||
blob = mock.Mock()
|
||||
blob.is_validated.return_value = False
|
||||
self.blob_manager.get_blob.return_value = defer.succeed(blob)
|
||||
query = {
|
||||
'blob_data_payment_rate': 'rate',
|
||||
'requested_blob': 'blob'
|
||||
}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {
|
||||
'blob_data_payment_rate': 'RATE_ACCEPTED',
|
||||
'incoming_blob': {'error': 'BLOB_UNAVAILABLE'}
|
||||
}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
def test_blob_unavailable_when_blob_cannot_be_opened(self):
|
||||
self.payment_rate_manager.accept_rate_blob_data.return_value = True
|
||||
blob = mock.Mock()
|
||||
blob.is_validated.return_value = True
|
||||
blob.open_for_reading.return_value = None
|
||||
self.blob_manager.get_blob.return_value = defer.succeed(blob)
|
||||
query = {
|
||||
'blob_data_payment_rate': 'rate',
|
||||
'requested_blob': 'blob'
|
||||
}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {
|
||||
'blob_data_payment_rate': 'RATE_ACCEPTED',
|
||||
'incoming_blob': {'error': 'BLOB_UNAVAILABLE'}
|
||||
}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
def test_blob_details_are_set_when_all_conditions_are_met(self):
|
||||
self.payment_rate_manager.accept_rate_blob_data.return_value = True
|
||||
blob = mock.Mock()
|
||||
blob.is_validated.return_value = True
|
||||
blob.open_for_reading.return_value = True
|
||||
blob.blob_hash = 'DEADBEEF'
|
||||
blob.length = 42
|
||||
self.blob_manager.get_blob.return_value = defer.succeed(blob)
|
||||
query = {
|
||||
'blob_data_payment_rate': 'rate',
|
||||
'requested_blob': 'blob'
|
||||
}
|
||||
deferred = self.handler.handle_queries(query)
|
||||
response = {
|
||||
'blob_data_payment_rate': 'RATE_ACCEPTED',
|
||||
'incoming_blob': {
|
||||
'blob_hash': 'DEADBEEF',
|
||||
'length': 42
|
||||
}
|
||||
}
|
||||
self.assertEqual(response, self.successResultOf(deferred))
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue