Esempio n. 1
0
def test_set_allowing_duplicates_left_of_hyphen():
    headers = Headers()
    headers.set(name="a-a", value="bar", adjust_case_to_allow_duplicates=True)
    headers.set(name="A-A",
                value="howdy",
                adjust_case_to_allow_duplicates=True)
    headers.set(name="A-a", value="yoyo", adjust_case_to_allow_duplicates=True)
    headers.set(name="a-A", value="boo", adjust_case_to_allow_duplicates=True)

    assert headers.to_dict() == {
        "a-a": [{
            'key': 'a-a',
            'value': 'bar',
        }],
        "a-A": [{
            'key': 'a-A',
            'value': 'howdy',
        }],
        "A-a": [{
            'key': 'A-a',
            'value': 'yoyo',
        }],
        "A-A": [{
            'key': 'A-A',
            'value': 'boo',
        }],
    }

    with pytest.raises(RuntimeError, match=r".*no more case variants.*"):
        headers.set(name="a-a",
                    value="yoyo",
                    adjust_case_to_allow_duplicates=True)
Esempio n. 2
0
def test_set_allowing_duplicates_with_given_data():
    headers = Headers({
        "a-a": [{
            'key': 'a-a',
            'value': 'bar',
        }],
        "a-A": [{
            'key': 'a-A',
            'value': 'howdy',
        }],
    })

    headers.set(name="A-a", value="yoyo", adjust_case_to_allow_duplicates=True)

    assert headers.to_dict() == {
        "a-a": [{
            'key': 'a-a',
            'value': 'bar',
        }],
        "a-A": [{
            'key': 'a-A',
            'value': 'howdy',
        }],
        "A-a": [{
            'key': 'A-a',
            'value': 'yoyo',
        }],
    }
Esempio n. 3
0
def test_set_allowing_duplicates():
    headers = Headers()
    headers.set(name="Set-Cookie",
                value="bar",
                adjust_case_to_allow_duplicates=True)
    headers.set(name="Set-Cookie",
                value="howdy",
                adjust_case_to_allow_duplicates=True)
    headers.set(name="Set-Cookie",
                value="yoyo",
                adjust_case_to_allow_duplicates=True)

    assert headers.to_dict() == {
        "set-cookie": [{
            'key': 'set-cookie',
            'value': 'bar',
        }],
        "set-cookiE": [{
            'key': 'set-cookiE',
            'value': 'howdy',
        }],
        "set-cookIe": [{
            'key': 'set-cookIe',
            'value': 'yoyo',
        }],
    }
Esempio n. 4
0
def test_to_dict_returns_copy_of_overlaid_data():
    orig_data = {
        'foo': [{
            'key': 'foo',
            'value': 'orig-foo-value',
        }]
    }
    headers = Headers(data=orig_data)

    new_data = headers.to_dict()
    assert new_data == orig_data

    new_data['foo'][0]['value'] = 'new-foo-value'
    assert orig_data['foo'][0]['value'] == 'orig-foo-value'