def test_headers_items(): headers = [XHeader(name='A', value='a'), XHeader(name='B', value='b')] h = SpamcHeaders(headers=headers) header_tuples = [(header.field_name(), header) for header in headers] for test_result in h.items(): assert test_result in header_tuples
def test_headers_keys(): headers = [XHeader(name='A', value='a'), XHeader(name='B', value='b')] h = SpamcHeaders(headers=headers) header_fields = [header.field_name() for header in headers] for test_result in h.keys(): assert test_result in header_fields
def test_headers_bytes(): headers = [XHeader(name='A', value='a'), XHeader(name='B', value='b')] h = SpamcHeaders(headers=headers) result = bytes(h) header_bytes = [bytes(header) for header in headers] for header in header_bytes: assert header in result
def test_bytes(): x_header = XHeader('XHeader', 'head-value') assert bytes(x_header) == b'XHeader: head-value\r\n'
def test_field_name(): x_header = XHeader('head-name', 'head-value') assert x_header.field_name() == 'head-name'
def test_user_value(): x_header = XHeader('head-name', 'head-value') assert x_header.name == 'head-name' assert x_header.value == 'head-value'
def test_repr(): x_header = XHeader('head-name', 'head-value') assert repr( x_header) == 'XHeader(name=\'head-name\', value=\'head-value\')'
def test_headers_values(): headers = [XHeader(name='A', value='a'), XHeader(name='B', value='b')] h = SpamcHeaders(headers=headers) for test_result in h.values(): assert test_result in headers
def test_instantiates(self): x_header = XHeader('head-name', 'head-value') assert 'x_header' in locals()
def x_headers(): from aiospamc.headers import XHeader return [XHeader(name='A', value='a'), XHeader(name='B', value='b')]
import pytest from aiospamc.headers import Compress, ContentLength, XHeader from aiospamc.requests import Request def test_request_instantiates(): request = Request('TEST') assert 'request' in locals() @pytest.mark.parametrize( 'verb,body,headers', [('TEST', None, []), ('TEST', None, [XHeader('X-Tests-Head', 'Tests value')]), ('TEST', 'Test body\n', [ContentLength(length=10)]), ('TEST', 'Test body\n', [ContentLength(length=10), Compress()])]) def test_request_bytes(verb, body, headers): request = Request(verb=verb, body=body, headers=headers) assert bytes(request).startswith(verb.encode()) assert bytes(b'SPAMC/1.5\r\n') in bytes(request) assert all(bytes(header) in bytes(request) for header in headers) if body: if any(isinstance(header, Compress) for header in headers): assert bytes(request).endswith(zlib.compress(body.encode())) else: assert bytes(request).endswith(body.encode())