本文整理汇总了Python中heartbeat.Heartbeat.challenge_type方法的典型用法代码示例。如果您正苦于以下问题:Python Heartbeat.challenge_type方法的具体用法?Python Heartbeat.challenge_type怎么用?Python Heartbeat.challenge_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类heartbeat.Heartbeat
的用法示例。
在下文中一共展示了Heartbeat.challenge_type方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def setUp(self):
self.challenge = Heartbeat.challenge_type().\
fromdict(
MockValues
.get_challenges_response['challenges'][0]['challenge'])
self.heartbeat = Heartbeat.fromdict(
MockValues.connect_response['heartbeat'])
self.tag = Heartbeat.tag_type().fromdict(
MockValues.get_chunks_response['chunks'][0]['tag'])
self.expiration = datetime.utcnow(
) + timedelta(int(MockValues.get_chunks_response['chunks'][0]['due']))
self.client = mock.MagicMock()
self.manager = ThreadManager()
self.test_hash = 'hash'
self.test_size = 100
self.test_seed = 'seed'
self.contract = DownstreamContract(self.client,
self.test_hash,
self.test_seed,
self.test_size,
self.challenge,
self.expiration,
self.tag,
self.manager,
os.path.join('data', 'chunks'))
self.contract.generate_data()
示例2: setUp
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def setUp(self):
self.challenge = Heartbeat.challenge_type()()
self.tag = Heartbeat.tag_type()()
self.expiration = datetime.utcnow()+timedelta(seconds=60)
self.contract = Contract('hash',
'seed',
12345,
self.challenge,
self.expiration,
self.tag)
示例3: test_challenge_working
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def test_challenge_working(self):
self.client.contract = self.test_contract
self.client.heartbeat = self.test_heartbeat
with mock.patch('downstream_farmer.client.requests.get') as patch:
inst = patch.return_value
inst.json.return_value = MockValues.get_challenge_response
self.client.get_challenge()
self.assertEqual(self.client.contract.challenge,
Heartbeat.challenge_type().fromdict(
MockValues.get_challenge_response['challenge']))
self.assertEqual(self.client.contract.expiration,
datetime.strptime(
MockValues.get_challenge_response['expiration'],
'%Y-%m-%dT%H:%M:%S'))
示例4: setUp
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def setUp(self):
self.server_url = 'https://test.url/'
self.api_path = '/api/downstream/v1'
self.size = 100
self.address = base58.b58encode_check(b'\x00' + os.urandom(20))
self.token = binascii.hexlify(os.urandom(16)).decode('ascii')
self.msg = ''
self.sig = ''
self.thread_manager = ShellApplication()
self.contract_thread = ManagedThread()
self.chunk_dir = os.path.join('data', 'chunks')
self.client = DownstreamClient(self.server_url,
self.token,
self.address,
self.size,
self.msg,
self.sig,
self.thread_manager,
self.chunk_dir)
self.client.session = mock.MagicMock()
self.test_contract = \
DownstreamContract(self.client,
MockValues.get_chunks_response[
'chunks'][0]['file_hash'],
MockValues.get_chunks_response[
'chunks'][0]['seed'],
MockValues.get_chunks_response[
'chunks'][0]['size'],
Heartbeat.challenge_type().fromdict(
MockValues
.get_chunks_response
['chunks'][0]['challenge']),
datetime.utcnow() + timedelta(
seconds=int(
MockValues
.get_chunks_response
['chunks'][0]['due'])),
Heartbeat.tag_type().fromdict(
MockValues
.get_chunks_response
['chunks'][0]['tag']),
self.thread_manager,
self.chunk_dir)
self.test_heartbeat = Heartbeat.fromdict(
MockValues.connect_response['heartbeat'])
示例5: setUp
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def setUp(self):
self.challenge = Heartbeat.challenge_type().\
fromdict(MockValues.get_challenge_response['challenge'])
self.heartbeat = Heartbeat.fromdict(
MockValues.connect_response['heartbeat'])
self.tag = Heartbeat.tag_type().fromdict(
MockValues.get_chunk_response['tag'])
self.expiration = datetime.utcnow(
) + timedelta(int(MockValues.get_chunk_response['due']))
self.client = mock.MagicMock()
self.api = API()
self.contract = DownstreamContract(self.client,
'hash',
'seed',
100,
self.challenge,
self.expiration,
self.tag,
self.api)
示例6: test_update_challenge_working
# 需要导入模块: from heartbeat import Heartbeat [as 别名]
# 或者: from heartbeat.Heartbeat import challenge_type [as 别名]
def test_update_challenge_working(self):
self.contract.answered = True
self.client.heartbeat = self.heartbeat
self.api = API()
self.contract.time_remaining = mock.MagicMock()
self.contract.time_remaining.return_value = 0
with mock.patch('downstream_farmer.contract.requests.get') as getpatch:
getpatch.return_value.json.return_value =\
MockValues.get_challenge_response
self.contract.update_challenge()
self.assertEqual(self.contract.challenge,
Heartbeat.challenge_type().fromdict(
MockValues
.get_challenge_response['challenge']),
self.api)
self.assertAlmostEqual((self.
contract.expiration - datetime.utcnow()).
total_seconds(),
int(MockValues.
get_challenge_response['due']),
delta=0.5)