Best Python code snippet using pyresttest_python
test_network.py
Source:test_network.py
...35 block_hex = '0000000000000000001237f46acddf58578a37e213d2a6edc4884a2fcad05ba3'36 payload = network.gen_getheaders(start_block=bytes.fromhex(block_hex))37 payload_bytes = network.serialize_getheaders(payload)38 assert payload_bytes.hex() == '7f11010001a35bd0ca2f4a88c4eda6d213e2378a5758dfcd6af437120000000000000000000000000000000000000000000000000000000000000000000000000000000000'39def test_parse_headers():40 hex_msg = '0200000020df3b053dc46f162a9b00c7f0d5124e2676d47bbe7c5d0793a500000000000000ef445fef2ed495c275892206ca533e7411907971013ab83e3b47bd0d692d14d4dc7c835b67d8001ac157e670000000002030eb2540c41025690160a1014c577061596e32e426b712c7ca00000000000000768b89f07044e6130ead292a3f51951adbd2202df447d98789339937fd006bd44880835b67d8001ade09204600'41 stream = BytesIO(bytes.fromhex(hex_msg))42 payload = network.parse_headers(stream)43 assert len(payload['blocks']) == 244 for b in payload['blocks']:45 print(b)46def test_serialize_getdata():47 hex_msg = '020300000030eb2540c41025690160a1014c577061596e32e426b712c7ca00000000000000030000001049847939585b0652fba793661c361223446b6fc41089b8be00000000000000'48 payload = network.gen_getdata()49 block1 = bytes.fromhex('00000000000000cac712b726e4326e596170574c01a16001692510c44025eb30')50 payload['data'].append((network.FILTERED_BLOCK_DATA_TYPE, block1))51 block2 = bytes.fromhex('00000000000000beb88910c46f6b442312361c6693a7fb52065b583979844910')52 payload['data'].append((network.FILTERED_BLOCK_DATA_TYPE, block2))53 assert network.serialize_getdata(payload).hex() == hex_msg54test_gen_msg()55test_parse_msg()56test_serialize_msg()57test_serialize_getheaders()58test_parse_headers()59test_serialize_getdata()60def test_parse_merkleblock():61 hex_merkle_block = '00000020df3b053dc46f162a9b00c7f0d5124e2676d47bbe7c5d0793a500000000000000ef445fef2ed495c275892206ca533e7411907971013ab83e3b47bd0d692d14d4dc7c835b67d8001ac157e670bf0d00000aba412a0d1480e370173072c9562becffe87aa661c1e4a6dbc305d38ec5dc088a7cf92e6458aca7b32edae818f9c2c98c37e06bf72ae0ce80649a38655ee1e27d34d9421d940b16732f24b94023e9d572a7f9ab8023434a4feb532d2adfc8c2c2158785d1bd04eb99df2e86c54bc13e139862897217400def5d72c280222c4cbaee7261831e1550dbb8fa82853e9fe506fc5fda3f7b919d8fe74b6282f92763cef8e625f977af7c8619c32a369b832bc2d051ecd9c73c51e76370ceabd4f25097c256597fa898d404ed53425de608ac6bfe426f6e2bb457f1c554866eb69dcb8d6bf6f880e9a59b3cd053e6c7060eeacaacf4dac6697dac20e4bd3f38a2ea2543d1ab7953e3430790a9f81e1c67f5b58c825acf46bd02848384eebe9af917274cdfbb1a28a5d58a23a17977def0de10d644258d9c54f886d47d293a411cb6226103b55635'62 mb = network.parse_merkleblock(BytesIO(bytes.fromhex(hex_merkle_block)))63 assert mb['version'] == 0x2000000064 merkle_root_hex = 'ef445fef2ed495c275892206ca533e7411907971013ab83e3b47bd0d692d14d4'65 merkle_root = bytes.fromhex(merkle_root_hex)[::-1]66 assert mb['merkle_root'] == merkle_root67 prev_block_hash_hex = 'df3b053dc46f162a9b00c7f0d5124e2676d47bbe7c5d0793a500000000000000'68 prev_block_hash = bytes.fromhex(prev_block_hash_hex)[::-1]69 assert mb['prev_block_hash'] == prev_block_hash70 timestamp = util.little_endian_to_int(bytes.fromhex('dc7c835b'))71 assert mb['timestamp'] == timestamp72 bits = bytes.fromhex('67d8001a')...
test_http_helper.py
Source:test_http_helper.py
1# -*- coding: utf-8 -*-2from __future__ import absolute_import, division, print_function, unicode_literals3import pytest4from ssdpy.http_helper import parse_headers5def test_parse_headers():6 good_response = b"HTTP/1.1 200 OK\r\n" b"MX: 5\r\n"7 headers = parse_headers(good_response)8 assert headers.get("mx") == "5"9def test_parse_headers_invalid_header():10 good_response = b"HTTP/1.1 200 OK\r\n" b"MX: 5\r\n"11 headers = parse_headers(good_response)12 assert headers.get("should-not-exist") is None13def test_parse_headers_invalid_response():14 bad_response = b"not an http response"15 with pytest.raises(ValueError):16 parse_headers(bad_response)17def test_parse_headers_bad_response_header():18 bad_response = (19 b"HTTP/1.1 200 OK\r\n" b"Header: OK\r\n" b"Another-header-not-ok\r\n"...
test_parser.py
Source:test_parser.py
1import unittest2from webmentiontools.parser import parse_headers, parse_html3from .endpoints import WEBMENTION_ROCKS_TESTS4class ParserTestCase(unittest.TestCase):5 def test_parse_headers(self):6 for test in WEBMENTION_ROCKS_TESTS:7 if test["source"] == "header":8 endpoint = parse_headers(test["url"], test["headers"])9 assert endpoint == test["endpoint"]10 def test_parse_html(self):11 for test in WEBMENTION_ROCKS_TESTS:12 if test["source"] == "html":13 endpoint = parse_html(test["url"], test["html"])...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!