Пример #1
0
def test_msearch_payload():
    data = create_msearch_payload("239.255.255.250:1900", "ssdp:all", mx=1)
    data_headers = parse_headers(data)
    assert data_headers.get("host") == "239.255.255.250:1900"
    assert data_headers.get("st") == "ssdp:all"
    assert data_headers.get("man") == '"ssdp:discover"'
    assert data_headers.get("mx") == "1"
Пример #2
0
def test_notify_payload():
    data = create_notify_payload("239.255.255.250:1900", "testdevice", "ssdpy-test")
    data_headers = parse_headers(data)
    assert data_headers.get("host") == "239.255.255.250:1900"
    assert data_headers.get("nt") == "testdevice"
    assert data_headers.get("usn") == "ssdpy-test"
    assert data_headers.get("non-existant-header") is None
Пример #3
0
def test_notify_age():
    data = create_notify_payload("239.255.255.250:1900", "testdevice", "ssdpy-test", max_age=999)
    data_headers = parse_headers(data)
    assert data_headers.get("host") == "239.255.255.250:1900"
    assert data_headers.get("nt") == "testdevice"
    assert data_headers.get("usn") == "ssdpy-test"
    assert data_headers.get("non-existant-header") is None
    assert data_headers.get("cache-control") == "max-age=999"
Пример #4
0
def test_notify_extra_fields():
    data = create_notify_payload(
        "239.255.255.250:1900",
        "testdevice",
        "ssdpy-test",
        extra_fields={"test-header": "test-value", "test-header.domain.com": "test-value2"},
    )
    data_headers = parse_headers(data)
    assert data_headers.get("test-header") == "test-value"
    assert data_headers.get("test-header.domain.com") == "test-value2"
    assert data_headers.get("non-existant-header") is None
Пример #5
0
def test_parse_headers():
    good_response = b"HTTP/1.1 200 OK\r\n" b"MX: 5\r\n"
    headers = parse_headers(good_response)
    assert headers.get("mx") == "5"
Пример #6
0
def test_parse_headers_bad_response_header():
    bad_response = (b"HTTP/1.1 200 OK\r\n"
                    b"Header: OK\r\n"
                    b"Another-header-not-ok\r\n")
    with pytest.raises(ValueError):
        parse_headers(bad_response)
Пример #7
0
def test_parse_headers_invalid_response():
    bad_response = b"not an http response"
    with pytest.raises(ValueError):
        parse_headers(bad_response)
Пример #8
0
def test_parse_headers_invalid_header():
    good_response = b"HTTP/1.1 200 OK\r\n" b"MX: 5\r\n"
    headers = parse_headers(good_response)
    assert headers.get("should-not-exist") is None